Skip to content

Commit 5f01338

Browse files
committed
Add code to automatically update luceneIndex of release record
1 parent 3dfbbe3 commit 5f01338

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

mGAP/src/org/labkey/mgap/pipeline/IndexVariantsForMgapStep.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
import org.json.JSONObject;
66
import org.labkey.api.data.Container;
77
import org.labkey.api.data.SimpleFilter;
8+
import org.labkey.api.data.TableInfo;
89
import org.labkey.api.data.TableSelector;
910
import org.labkey.api.jbrowse.JBrowseService;
1011
import org.labkey.api.pipeline.PipelineJob;
1112
import org.labkey.api.pipeline.PipelineJobException;
13+
import org.labkey.api.query.BatchValidationException;
1214
import org.labkey.api.query.FieldKey;
15+
import org.labkey.api.query.InvalidKeyException;
1316
import org.labkey.api.query.QueryService;
17+
import org.labkey.api.query.QueryUpdateServiceException;
1418
import org.labkey.api.security.User;
1519
import org.labkey.api.sequenceanalysis.SequenceOutputFile;
1620
import org.labkey.api.sequenceanalysis.pipeline.AbstractVariantProcessingStepProvider;
@@ -28,8 +32,11 @@
2832

2933
import javax.annotation.Nullable;
3034
import java.io.File;
35+
import java.sql.SQLException;
3136
import java.util.Arrays;
37+
import java.util.Collections;
3238
import java.util.List;
39+
import java.util.Map;
3340

3441
public class IndexVariantsForMgapStep extends AbstractCommandPipelineStep<SelectVariantsWrapper> implements VariantProcessingStep
3542
{
@@ -97,4 +104,41 @@ public Output processVariants(File inputVCF, File outputDirectory, ReferenceGeno
97104

98105
return output;
99106
}
107+
108+
@Override
109+
public void complete(PipelineJob job, List<SequenceOutputFile> inputs, List<SequenceOutputFile> outputsCreated, SequenceAnalysisJobSupport support) throws PipelineJobException
110+
{
111+
String releaseVersion = getProvider().getParameterByName("releaseVersion").extractValue(getPipelineCtx().getJob(), getProvider(), getStepIdx(), String.class);
112+
113+
List<SequenceOutputFile> of = outputsCreated.stream().filter(x -> CATEGORY.equals(x.getCategory())).toList();
114+
if (of.size() != 1)
115+
{
116+
throw new PipelineJobException("Expected a single output, found: " + of.size());
117+
}
118+
119+
Container target = job.getContainer().isWorkbook() ? job.getContainer().getParent() : job.getContainer();
120+
TableInfo ti = QueryService.get().getUserSchema(job.getUser(), target, mGAPSchema.NAME).getTable(mGAPSchema.TABLE_VARIANT_CATALOG_RELEASES);
121+
TableSelector ts = new TableSelector(ti, PageFlowUtil.set("rowId", "container"), new SimpleFilter(FieldKey.fromString("version"), releaseVersion), null);
122+
if (ts.exists())
123+
{
124+
job.getLogger().info("Updating release record");
125+
Map<String, Object> row = ts.getValueMap();
126+
row.put("luceneIndex", of.get(0).getRowid());
127+
128+
try
129+
{
130+
BatchValidationException bve = new BatchValidationException();
131+
Map<String, Object> oldKeys = Map.of("rowId", row.get("rowId"));
132+
ti.getUpdateService().updateRows(job.getUser(), target, Collections.singletonList(row), Collections.singletonList(oldKeys), bve, null, null);
133+
}
134+
catch (BatchValidationException | InvalidKeyException | QueryUpdateServiceException | SQLException e)
135+
{
136+
throw new PipelineJobException(e);
137+
}
138+
}
139+
else
140+
{
141+
job.getLogger().info("No release record found, will not update");
142+
}
143+
}
100144
}

0 commit comments

Comments
 (0)