-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change GTs to single character, drop hom ref, add sample metrics to sample metadata tsv
- Loading branch information
1 parent
44a78a5
commit 84f8551
Showing
11 changed files
with
349 additions
and
213 deletions.
There are no files selected for viewing
38 changes: 30 additions & 8 deletions
38
src/main/java/org/broadinstitute/hellbender/tools/variantdb/CommonCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
...in/java/org/broadinstitute/hellbender/tools/variantdb/arrays/ArrayMetadataTsvCreator.java
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
src/main/java/org/broadinstitute/hellbender/tools/variantdb/arrays/ArraySampleFieldEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package org.broadinstitute.hellbender.tools.variantdb.arrays; | ||
|
||
import htsjdk.variant.variantcontext.VariantContext; | ||
import org.broadinstitute.hellbender.tools.variantdb.CommonCode; | ||
import org.broadinstitute.hellbender.tools.variantdb.arrays.tables.ProbeInfo; | ||
|
||
import java.util.*; | ||
|
||
|
||
|
||
public enum ArraySampleFieldEnum { | ||
sample_id, | ||
sample_name, | ||
|
||
|
||
// This where the validation step (required vs not) lives -- fail if there is missing data for a required field | ||
// and just leave it empty if not required | ||
|
||
NUM_ASSAYS { | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NUM_NON_FILTERED_ASSAYS{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NUM_FILTERED_ASSAYS{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NUM_ZEROED_OUT_ASSAYS{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NUM_SNPS{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NUM_INDELS{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NUM_CALLS{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NUM_AUTOCALL_CALLS{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NUM_NO_CALLS{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NUM_IN_DB_SNP{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NOVEL_SNPS{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
|
||
PCT_DBSNP{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
CALL_RATE{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
AUTOCALL_CALL_RATE{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}, | ||
NUM_SINGLETONS{ | ||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
return metricsMap.get(this.name()); | ||
} | ||
}; | ||
|
||
public String getColumnValue(final Map<String, String> metricsMap) { | ||
throw new IllegalArgumentException("Not implemented"); | ||
} | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
...main/java/org/broadinstitute/hellbender/tools/variantdb/arrays/ArraySampleTsvCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.broadinstitute.hellbender.tools.variantdb.arrays; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.broadinstitute.hellbender.exceptions.UserException; | ||
import org.broadinstitute.hellbender.tools.variantdb.IngestConstants; | ||
import org.broadinstitute.hellbender.utils.tsv.SimpleXSVWriter; | ||
|
||
import java.io.*; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
public class ArraySampleTsvCreator { | ||
|
||
private static final Logger logger = LogManager.getLogger(ArraySampleTsvCreator.class); | ||
|
||
private SimpleXSVWriter sampleMetadataWriter = null; | ||
private Map<String, String> metricsMap; | ||
|
||
|
||
public ArraySampleTsvCreator(String metricsFilepath) { | ||
if (metricsFilepath != null && !metricsFilepath.isEmpty()) { | ||
BufferedReader reader = null; | ||
try { | ||
String columns = null; | ||
String values = null; | ||
reader = new BufferedReader(new FileReader(metricsFilepath)); | ||
String line = reader.readLine(); | ||
while (line != null) { | ||
if (!line.startsWith("#") && !line.trim().isEmpty()) { | ||
if (columns == null) { | ||
columns = line; | ||
} else if (values == null) { | ||
values = line; | ||
} else { | ||
// there are more lines than expected - output a warning | ||
logger.warn("more lines than expected in metrics file: " + line); | ||
} | ||
} | ||
line = reader.readLine(); | ||
} | ||
|
||
List<String> colList = Arrays.asList(columns.split("\t")); | ||
List<String> valList = Arrays.asList(values.split("\t")); | ||
metricsMap = IntStream.range(0, colList.size()).boxed().collect(Collectors.toMap(colList::get, valList::get)); | ||
|
||
} catch (IOException e) { | ||
throw new RuntimeException("could not read metrics file", e); | ||
} | ||
} | ||
} | ||
|
||
public static List<String> getHeaders() { | ||
return Arrays.stream(ArraySampleFieldEnum.values()).map(String::valueOf).collect(Collectors.toList()); | ||
} | ||
|
||
public void createRow(String sampleName, String sampleId, String tableNumberPrefix, File outputDirectory) { | ||
// if the metadata tsvs don't exist yet -- create them | ||
try { | ||
// Create a metadata file to go into the metadata dir for _this_ sample | ||
// TODO--this should just be one file per sample set? | ||
final File sampleMetadataFileName = new File (outputDirectory, IngestConstants.sampleMetadataFilePrefix + tableNumberPrefix + sampleName + IngestConstants.FILETYPE); | ||
// write header to it | ||
List<String> sampleListHeader = ArraySampleTsvCreator.getHeaders(); | ||
sampleMetadataWriter = new SimpleXSVWriter(sampleMetadataFileName.toPath(), IngestConstants.SEPARATOR); | ||
sampleMetadataWriter.setHeaderLine(sampleListHeader); | ||
|
||
final List<String> TSVLineToCreateSampleMetadata = createSampleListRow( | ||
sampleName, | ||
sampleId); | ||
sampleMetadataWriter.getNewLineBuilder().setRow(TSVLineToCreateSampleMetadata).write(); | ||
|
||
} catch (final IOException e) { | ||
throw new UserException("Could not create sample outputs", e); | ||
} | ||
|
||
} | ||
|
||
private List<String> createSampleListRow(String sampleName, String sampleId) { | ||
List<String> row = new ArrayList<>(); | ||
row.add(sampleName); | ||
row.add(sampleId); | ||
|
||
for (final ArraySampleFieldEnum fieldEnum : ArraySampleFieldEnum.values()) { | ||
if (fieldEnum != ArraySampleFieldEnum.sample_id && fieldEnum != ArraySampleFieldEnum.sample_name) { | ||
if (metricsMap == null) { | ||
row.add("null"); | ||
} else { | ||
row.add(fieldEnum.getColumnValue(metricsMap)); | ||
} | ||
} | ||
} | ||
return row; | ||
} | ||
|
||
public void closeTool() { | ||
if (sampleMetadataWriter != null) { | ||
try { | ||
sampleMetadataWriter.close(); | ||
} catch (final Exception e) { | ||
throw new IllegalArgumentException("Couldn't close array sample writer", e); | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.