|
5 | 5 | import org.json.JSONObject; |
6 | 6 | import org.labkey.api.data.Container; |
7 | 7 | import org.labkey.api.data.SimpleFilter; |
| 8 | +import org.labkey.api.data.TableInfo; |
8 | 9 | import org.labkey.api.data.TableSelector; |
9 | 10 | import org.labkey.api.jbrowse.JBrowseService; |
10 | 11 | import org.labkey.api.pipeline.PipelineJob; |
11 | 12 | import org.labkey.api.pipeline.PipelineJobException; |
| 13 | +import org.labkey.api.query.BatchValidationException; |
12 | 14 | import org.labkey.api.query.FieldKey; |
| 15 | +import org.labkey.api.query.InvalidKeyException; |
13 | 16 | import org.labkey.api.query.QueryService; |
| 17 | +import org.labkey.api.query.QueryUpdateServiceException; |
14 | 18 | import org.labkey.api.security.User; |
15 | 19 | import org.labkey.api.sequenceanalysis.SequenceOutputFile; |
16 | 20 | import org.labkey.api.sequenceanalysis.pipeline.AbstractVariantProcessingStepProvider; |
|
28 | 32 |
|
29 | 33 | import javax.annotation.Nullable; |
30 | 34 | import java.io.File; |
| 35 | +import java.sql.SQLException; |
31 | 36 | import java.util.Arrays; |
| 37 | +import java.util.Collections; |
32 | 38 | import java.util.List; |
| 39 | +import java.util.Map; |
33 | 40 |
|
34 | 41 | public class IndexVariantsForMgapStep extends AbstractCommandPipelineStep<SelectVariantsWrapper> implements VariantProcessingStep |
35 | 42 | { |
@@ -97,4 +104,41 @@ public Output processVariants(File inputVCF, File outputDirectory, ReferenceGeno |
97 | 104 |
|
98 | 105 | return output; |
99 | 106 | } |
| 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 | + } |
100 | 144 | } |
0 commit comments