diff --git a/src/main/java/com/github/discvrseq/walkers/ClinvarAnnotator.java b/src/main/java/com/github/discvrseq/walkers/ClinvarAnnotator.java index 65f5c7c8..09486a2c 100644 --- a/src/main/java/com/github/discvrseq/walkers/ClinvarAnnotator.java +++ b/src/main/java/com/github/discvrseq/walkers/ClinvarAnnotator.java @@ -23,7 +23,7 @@ /** * This tool compares an input VCF to the provided ClinVar VCF and adds annotations to * any variant overlapping with a variant from ClinVar (matching both site and allele). Note, this requires the VCF to use ClinVar's 2.0 VCF format. - * The ClinVar VCFs can be foind here: https://www.ncbi.nlm.nih.gov/variation/docs/ClinVar_vcf_files/ + * The ClinVar VCFs can be found here: https://www.ncbi.nlm.nih.gov/variation/docs/ClinVar_vcf_files/ *

* *

Usage example

@@ -60,7 +60,7 @@ public class ClinvarAnnotator extends VariantWalker { /** * INFO header fields in the new VCF for ClinVar annotations. */ - private List HEADER_LINES = Arrays.asList( + private final List HEADER_LINES = Arrays.asList( new VCFInfoHeaderLine("CLN_ALLELE", VCFHeaderLineCount.R, VCFHeaderLineType.Character, "Alternate alleles from Clinvar"), new VCFInfoHeaderLine("CLN_ALLELEID", VCFHeaderLineCount.R, VCFHeaderLineType.Integer, "the ClinVar Allele ID"), new VCFInfoHeaderLine("CLN_DN", VCFHeaderLineCount.R, VCFHeaderLineType.String, "ClinVar's preferred disease name for the concept specified by disease identifiers in CLNDISDB"), @@ -120,7 +120,7 @@ public void apply(VariantContext variant, ReadsContext readsContext, ReferenceCo if (cvAllele.equals(alt)){ //gather annotations, add to map by allele foundHit = true; - annotationMap.put(alt, transferAnnotations(vc, alt, vcb)); + annotationMap.put(alt, transferAnnotations(vc, alt)); } } } @@ -148,7 +148,7 @@ public void apply(VariantContext variant, ReadsContext readsContext, ReferenceCo if (nonNull > 0){ if (!sb.isEmpty()){ hasAnnotation = true; - vcb.attribute(line.getID(), sb.stream().collect(Collectors.joining(","))); + vcb.attribute(line.getID(), String.join(",", sb)); } } } @@ -187,11 +187,10 @@ public void apply(VariantContext variant, ReadsContext readsContext, ReferenceCo *

* * @param source ClinVar VCF - * @param alt alternate allele from ClinVar - * @param vcb new VCF to annotate + * @param alt alternate allele from ClinVar* * @return a map which maps ClinVar alleles with their corresponding ClinVar annotations */ - private Map transferAnnotations (VariantContext source, Allele alt, VariantContextBuilder vcb){ + private Map transferAnnotations(VariantContext source, Allele alt){ Map annotations = new HashMap<>(); annotations.put("CLN_ALLELE", alt.getDisplayString()); @@ -229,7 +228,6 @@ private Map transferAnnotations (VariantContext source, Allele a * * @param source ClinVar VCF * @param ID ClinVar VCF Annotation ID - * @return */ private String annotateValue(VariantContext source, String ID){ if (source.getAttribute(ID) == null){ diff --git a/src/main/java/com/github/discvrseq/walkers/MultiSourceAnnotator.java b/src/main/java/com/github/discvrseq/walkers/MultiSourceAnnotator.java index 3fe037be..c6d6df96 100644 --- a/src/main/java/com/github/discvrseq/walkers/MultiSourceAnnotator.java +++ b/src/main/java/com/github/discvrseq/walkers/MultiSourceAnnotator.java @@ -18,9 +18,11 @@ import org.broadinstitute.hellbender.exceptions.GATKException; import org.broadinstitute.hellbender.utils.Utils; +import javax.annotation.Nullable; import java.io.File; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * This is a fairly specialized tool, designed to take the VCFs annotated with ClinvarAnnotator (from DISCVR-seq Toolkit) and Cassandra, @@ -66,6 +68,11 @@ public class MultiSourceAnnotator extends VariantWalker { @Argument(doc="SnpSift Allowed INFO Fields", fullName = "snpsift-fields", shortName = "ssf", optional = true) public List snpSiftFields = new ArrayList<>(SNPSIFT_INFO); + @Argument(doc="Renamed SnpSift INFO Fields. If provided, this must be of equal length as snpsift-fields. Each source snpsift-field will be transferred to an annotation of this name", fullName = "renamed-snpsift-fields", shortName = "rssf", optional = true) + public List renamedSnpSiftFields = new ArrayList<>(); + + final Map snpSiftFieldMapping = new HashMap<>(); + @Argument(doc="Funcotator Annotated VCF", fullName = "funcotator", shortName = "f", optional = true) public FeatureInput funcotatorVariants = null; @@ -466,6 +473,14 @@ public void onTraversalStart() { allAnnotationKeys.add(id); } + if (renamedSnpSiftFields != null && !renamedSnpSiftFields.isEmpty()) { + if (renamedSnpSiftFields.size() != snpSiftFields.size()) { + throw new GATKException("--renamed-snpsift-fields must be the same length as --snpsift-fields"); + } + + IntStream.range(0, renamedSnpSiftFields.size()).forEach(j -> snpSiftFieldMapping.put(snpSiftFields.get(j), renamedSnpSiftFields.get(j))); + } + List allKeys = new ArrayList<>(snpSiftHeader.getInfoHeaderLines().stream().map(VCFInfoHeaderLine::getID).toList()); allKeys.removeAll(snpSiftFields); if (!allKeys.isEmpty()) { @@ -533,7 +548,7 @@ public void apply(VariantContext variant, ReadsContext readsContext, ReferenceCo } snpSift++; - transferInfoData(vcb, vc, snpSiftFields); + transferInfoData(vcb, vc, snpSiftFields, snpSiftFieldMapping); } } @@ -593,9 +608,18 @@ private boolean matches(VariantContext source, VariantContext annotation){ } private void transferInfoData(VariantContextBuilder vcb, VariantContext source, List ids){ + transferInfoData(vcb, source, ids, null); + } + + private void transferInfoData(VariantContextBuilder vcb, VariantContext source, List ids, @Nullable Map oldKeyToNewKey){ for (String id : ids){ if (source.hasAttribute(id) && source.getAttribute(id) != null){ - vcb.attribute(id, source.getAttribute(id)); + if (oldKeyToNewKey != null) { + vcb.attribute(oldKeyToNewKey.getOrDefault(id, id), source.getAttribute(id)); + } + else { + vcb.attribute(id, source.getAttribute(id)); + } } } }