|
10 | 10 | import org.labkey.api.data.Container; |
11 | 11 | import org.labkey.api.data.DbSchema; |
12 | 12 | import org.labkey.api.data.DbSchemaType; |
| 13 | +import org.labkey.api.data.Results; |
13 | 14 | import org.labkey.api.data.SimpleFilter; |
14 | 15 | import org.labkey.api.data.Sort; |
15 | 16 | import org.labkey.api.data.TableSelector; |
|
43 | 44 | import java.io.File; |
44 | 45 | import java.io.IOException; |
45 | 46 | import java.io.PrintWriter; |
| 47 | +import java.sql.SQLException; |
46 | 48 | import java.util.ArrayList; |
47 | 49 | import java.util.Arrays; |
48 | 50 | import java.util.HashMap; |
@@ -148,21 +150,47 @@ public void init(PipelineJob job, SequenceAnalysisJobSupport support, List<Seque |
148 | 150 | Container targetContainer = getPipelineCtx().getJob().getContainer().isWorkbook() ? getPipelineCtx().getJob().getContainer().getParent() : getPipelineCtx().getJob().getContainer(); |
149 | 151 | final HashMap<String, List<String>> sourceFieldMap = new HashMap<>(); |
150 | 152 | final HashMap<String, List<String>> targetFieldMap = new HashMap<>(); |
151 | | - new TableSelector(QueryService.get().getUserSchema(getPipelineCtx().getJob().getUser(), targetContainer, mGAPSchema.NAME).getTable(mGAPSchema.TABLE_VARIANT_ANNOTATIONS), PageFlowUtil.set("toolName", "sourceField", "infoKey")).forEachResults(rs -> { |
152 | | - if (!sourceFieldMap.containsKey(rs.getString(FieldKey.fromString("toolName")))) |
153 | | - { |
154 | | - sourceFieldMap.put(rs.getString(FieldKey.fromString("toolName")), new ArrayList<>()); |
155 | | - targetFieldMap.put(rs.getString(FieldKey.fromString("toolName")), new ArrayList<>()); |
156 | | - } |
| 153 | + try (PrintWriter writer = PrintWriters.getPrintWriter(getFieldConfigFile())) |
| 154 | + { |
| 155 | + writer.println(StringUtils.join(Arrays.asList("DataSource", "SourceField", "ID", "Number", "Type", "Description"), "\t")); |
| 156 | + |
| 157 | + new TableSelector(QueryService.get().getUserSchema(getPipelineCtx().getJob().getUser(), targetContainer, mGAPSchema.NAME).getTable(mGAPSchema.TABLE_VARIANT_ANNOTATIONS), PageFlowUtil.set("toolName", "sourceField", "infoKey")).forEachResults(rs -> { |
| 158 | + if (!sourceFieldMap.containsKey(rs.getString(FieldKey.fromString("toolName")))) |
| 159 | + { |
| 160 | + sourceFieldMap.put(rs.getString(FieldKey.fromString("toolName")), new ArrayList<>()); |
| 161 | + targetFieldMap.put(rs.getString(FieldKey.fromString("toolName")), new ArrayList<>()); |
| 162 | + } |
157 | 163 |
|
158 | | - sourceFieldMap.get(rs.getString(FieldKey.fromString("toolName"))).add(rs.getString(FieldKey.fromString("sourceField"))); |
159 | | - targetFieldMap.get(rs.getString(FieldKey.fromString("toolName"))).add(rs.getString(FieldKey.fromString("infoKey"))); |
160 | | - }); |
| 164 | + sourceFieldMap.get(rs.getString(FieldKey.fromString("toolName"))).add(rs.getString(FieldKey.fromString("sourceField"))); |
| 165 | + targetFieldMap.get(rs.getString(FieldKey.fromString("toolName"))).add(rs.getString(FieldKey.fromString("infoKey"))); |
| 166 | + |
| 167 | + if ("Funcotator".equals(rs.getString(FieldKey.fromString("toolName")))) |
| 168 | + { |
| 169 | + writer.println(StringUtils.join(Arrays.asList( |
| 170 | + getFieldValue(rs, "dataSource"), |
| 171 | + getFieldValue(rs, "sourceField"), |
| 172 | + getFieldValue(rs, "infoKey"), |
| 173 | + getFieldValue(rs, "dataNumber"), |
| 174 | + getFieldValue(rs, "dataType"), |
| 175 | + getFieldValue(rs, "description") |
| 176 | + ), "\t")); |
| 177 | + } |
| 178 | + }); |
| 179 | + } |
| 180 | + catch (IOException e) |
| 181 | + { |
| 182 | + throw new PipelineJobException(e); |
| 183 | + } |
161 | 184 |
|
162 | 185 | getPipelineCtx().getSequenceSupport().cacheObject(SOURCE_FIELDS, sourceFieldMap); |
163 | 186 | getPipelineCtx().getSequenceSupport().cacheObject(TARGET_FIELDS, targetFieldMap); |
164 | 187 | } |
165 | 188 |
|
| 189 | + private String getFieldValue(Results rs, String fieldName) throws SQLException |
| 190 | + { |
| 191 | + return rs.getObject(FieldKey.fromString(fieldName)) == null ? "" : rs.getString(FieldKey.fromString(fieldName)); |
| 192 | + } |
| 193 | + |
166 | 194 | private static final String SOURCE_FIELDS = "sourceFields"; |
167 | 195 | private static final String TARGET_FIELDS = "targetFields"; |
168 | 196 |
|
@@ -452,7 +480,10 @@ public Output processVariants(File inputVCF, File outputDirectory, ReferenceGeno |
452 | 480 | extraArgs.add("-pmf"); |
453 | 481 | } |
454 | 482 |
|
455 | | - fr.runFuncotator(funcotatorSourceDir, liftedToGRCh37, funcotatorAnnotated, grch37Genome, extraArgs); |
| 483 | + File configFile = getFieldConfigFile(); |
| 484 | + output.addIntermediateFile(configFile); |
| 485 | + |
| 486 | + fr.runFuncotator(funcotatorSourceDir, liftedToGRCh37, funcotatorAnnotated, grch37Genome, configFile, extraArgs); |
456 | 487 | } |
457 | 488 | else |
458 | 489 | { |
@@ -528,6 +559,11 @@ public Output processVariants(File inputVCF, File outputDirectory, ReferenceGeno |
528 | 559 | return output; |
529 | 560 | } |
530 | 561 |
|
| 562 | + private File getFieldConfigFile() |
| 563 | + { |
| 564 | + return new File(getPipelineCtx().getSourceDirectory(), "funcotatorFields.txt"); |
| 565 | + } |
| 566 | + |
531 | 567 | private void addToolFieldNames(String toolName, String argName, List<String> options, File outDir, VariantProcessingStepOutputImpl output, @Nullable List<String> extraFields) throws PipelineJobException |
532 | 568 | { |
533 | 569 | List<String> fields = getCachedFields(TARGET_FIELDS, toolName); |
|
0 commit comments