Search in sources :

Example 1 with IdsvVariantContext

use of au.edu.wehi.idsv.IdsvVariantContext in project gridss by PapenfussLab.

the class ComputeCoverage method initIntervalCoverageAccumulator.

private IntervalCoverageAccumulator initIntervalCoverageAccumulator() {
    SAMSequenceDictionary dictionary = getReference().getSequenceDictionary();
    if (VCF == null) {
        return new IntervalCoverageAccumulator(COVERAGE_METHOD, dictionary, BIN_SIZE, null);
    } else {
        try (VCFFileReader vcfReader = new VCFFileReader(VCF, false)) {
            try (CloseableIterator<VariantContext> it = vcfReader.iterator()) {
                GenomicProcessingContext pc = new GenomicProcessingContext(new FileSystemContext(TMP_DIR.get(0), MAX_RECORDS_IN_RAM), REFERENCE_SEQUENCE, getReference());
                Iterator<IdsvVariantContext> idsvIt = Iterators.transform(it, variant -> IdsvVariantContext.create(pc, null, variant));
                Iterator<VariantContextDirectedEvidence> bpit = Iterators.filter(idsvIt, VariantContextDirectedEvidence.class);
                return new IntervalCoverageAccumulator(COVERAGE_METHOD, dictionary, BIN_SIZE, bpit);
            }
        }
    }
}
Also used : IntervalCoverageAccumulator(au.edu.wehi.idsv.IntervalCoverageAccumulator) VariantContextDirectedEvidence(au.edu.wehi.idsv.VariantContextDirectedEvidence) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VariantContext(htsjdk.variant.variantcontext.VariantContext) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) FileSystemContext(au.edu.wehi.idsv.FileSystemContext) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) GenomicProcessingContext(au.edu.wehi.idsv.GenomicProcessingContext)

Example 2 with IdsvVariantContext

use of au.edu.wehi.idsv.IdsvVariantContext in project gridss by PapenfussLab.

the class TruthAnnotator method annotate.

public VariantContextDirectedEvidence annotate(VariantContextDirectedEvidence variant) {
    BreakendSummary variantBreakend = variant.getBreakendSummary();
    BreakpointSummary variantBreakpoint = null;
    if (variantBreakend instanceof BreakpointSummary) {
        variantBreakpoint = (BreakpointSummary) variantBreakend;
        variantBreakend = variantBreakpoint.localBreakend();
    }
    HashSet<String> breakpointHits = Sets.newHashSet();
    HashSet<String> breakendHits = Sets.newHashSet();
    for (IdsvVariantContext truthVariant : truth) {
        if ((truthVariant.hasAttribute(VcfSvConstants.SV_TYPE_KEY) && truthVariant.getAttributeAsString(VcfSvConstants.SV_TYPE_KEY, "").equals("INS")) || (truthVariant.hasAttribute(VcfSvConstants.SV_TYPE_KEY) && truthVariant.getAttributeAsString(VcfSvConstants.SV_TYPE_KEY, "").equals("DEL"))) {
            int svLen = truthVariant.getAttributeAsInt(VcfSvConstants.SV_LENGTH_KEY, 0);
            int untemplatedSequence = 0;
            if (variant instanceof VariantContextDirectedEvidence) {
                untemplatedSequence = ((VariantContextDirectedEvidence) variant).getBreakendSequence().length;
            }
            // two breakpoints: forward & backward
            BreakendSummary truthBreakendStart = new BreakendSummary(truthVariant.getReferenceIndex(), BreakendDirection.Forward, truthVariant.getStart());
            int endOffset = Math.max(0, -truthVariant.getAttributeAsInt(VcfSvConstants.SV_LENGTH_KEY, 0));
            endOffset = truthVariant.getStart() + endOffset + 1;
            BreakendSummary truthBreakendEnd = new BreakendSummary(truthVariant.getReferenceIndex(), BreakendDirection.Backward, endOffset);
            BreakpointSummary truthBreakpoint = new BreakpointSummary(truthBreakendStart, truthBreakendEnd);
            if (matches(truthBreakpoint, variantBreakpoint, svLen, untemplatedSequence)) {
                breakpointHits.add(truthVariant.getID());
            } else if (matches(truthBreakpoint, variantBreakend, svLen, untemplatedSequence)) {
                breakendHits.add(truthVariant.getID());
            }
        } else {
            throw new RuntimeException(String.format("Matching of truth variant at %s:%d not yet implemented.", truthVariant.getContig(), truthVariant.getStart()));
        }
    }
    if (!breakpointHits.isEmpty() || !breakendHits.isEmpty()) {
        IdsvVariantContextBuilder builder = new IdsvVariantContextBuilder(processContext, variant);
        builder.attribute("TRUTH_MATCHES", Lists.newArrayList(breakpointHits));
        builder.attribute("TRUTH_MISREALIGN", Lists.newArrayList(breakendHits));
        return (VariantContextDirectedEvidence) builder.make();
    }
    return variant;
}
Also used : IdsvVariantContextBuilder(au.edu.wehi.idsv.IdsvVariantContextBuilder) VariantContextDirectedEvidence(au.edu.wehi.idsv.VariantContextDirectedEvidence) BreakendSummary(au.edu.wehi.idsv.BreakendSummary) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) BreakpointSummary(au.edu.wehi.idsv.BreakpointSummary)

Example 3 with IdsvVariantContext

use of au.edu.wehi.idsv.IdsvVariantContext in project gridss by PapenfussLab.

the class TruthAnnotator method loadTruthVcf.

private static List<IdsvVariantContext> loadTruthVcf(GenomicProcessingContext processContext, File truthVcf) {
    List<IdsvVariantContext> truth = Lists.newArrayList();
    VCFFileReader vcfReader = null;
    CloseableIterator<VariantContext> it = null;
    try {
        vcfReader = new VCFFileReader(truthVcf, false);
        it = vcfReader.iterator();
        while (it.hasNext()) {
            truth.add(IdsvVariantContext.create(processContext, null, it.next()));
        }
    } finally {
        CloserUtil.close(it);
        CloserUtil.close(vcfReader);
    }
    return truth;
}
Also used : VCFFileReader(htsjdk.variant.vcf.VCFFileReader) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) VariantContext(htsjdk.variant.variantcontext.VariantContext) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext)

Example 4 with IdsvVariantContext

use of au.edu.wehi.idsv.IdsvVariantContext in project gridss by PapenfussLab.

the class VcfTransformCommandLineProgram method saveVcf.

protected void saveVcf(File file, Iterator<IdsvVariantContext> calls) throws IOException {
    File tmp = gridss.Defaults.OUTPUT_TO_TEMP_FILE ? FileSystemContext.getWorkingFileFor(file) : file;
    final ProgressLogger writeProgress = new ProgressLogger(log);
    try (VariantContextWriter vcfWriter = getContext().getVariantContextWriter(tmp, true)) {
        while (calls.hasNext()) {
            IdsvVariantContext record = calls.next();
            vcfWriter.add(record);
            writeProgress.record(record.getContig(), record.getStart());
        }
    }
    if (tmp != file) {
        FileHelper.move(tmp, file, true);
    }
}
Also used : IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) ProgressLogger(htsjdk.samtools.util.ProgressLogger) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) File(java.io.File)

Example 5 with IdsvVariantContext

use of au.edu.wehi.idsv.IdsvVariantContext in project gridss by PapenfussLab.

the class VcfTransformCommandLineProgram method getAllCalls.

public Iterator<IdsvVariantContext> getAllCalls(File file, CloseableIterator<VariantContextDirectedBreakpoint> breakpointCalls) {
    VCFFileReader vcfReader = new VCFFileReader(file, false);
    CloseableIterator<VariantContext> it = vcfReader.iterator();
    Iterator<IdsvVariantContext> idsvIt = Iterators.transform(it, variant -> IdsvVariantContext.create(getContext(), null, variant));
    Iterator<IdsvVariantContext> nonbpIt = Iterators.filter(idsvIt, variant -> !(variant instanceof VariantContextDirectedBreakpoint));
    // sort back to nominal VCF position
    Iterator<VariantContextDirectedBreakpoint> bpit = new VariantContextWindowedSortingIterator<>(getContext(), SAMEvidenceSource.maximumWindowSize(getContext(), getSamEvidenceSources(), getAssemblySource()), breakpointCalls);
    Iterator<IdsvVariantContext> mergedIt = Iterators.mergeSorted(ImmutableList.of(bpit, nonbpIt), IdsvVariantContext.ByLocationStart);
    return new AutoClosingIterator<>(mergedIt, vcfReader, it);
}
Also used : VCFFileReader(htsjdk.variant.vcf.VCFFileReader) AutoClosingIterator(au.edu.wehi.idsv.util.AutoClosingIterator) VariantContext(htsjdk.variant.variantcontext.VariantContext) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint) VariantContextWindowedSortingIterator(au.edu.wehi.idsv.VariantContextWindowedSortingIterator)

Aggregations

IdsvVariantContext (au.edu.wehi.idsv.IdsvVariantContext)8 VariantContext (htsjdk.variant.variantcontext.VariantContext)5 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)4 VariantContextDirectedBreakpoint (au.edu.wehi.idsv.VariantContextDirectedBreakpoint)3 AutoClosingIterator (au.edu.wehi.idsv.util.AutoClosingIterator)3 BreakpointSummary (au.edu.wehi.idsv.BreakpointSummary)2 VariantContextDirectedEvidence (au.edu.wehi.idsv.VariantContextDirectedEvidence)2 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)2 File (java.io.File)2 AssemblyEvidenceSource (au.edu.wehi.idsv.AssemblyEvidenceSource)1 BreakendSummary (au.edu.wehi.idsv.BreakendSummary)1 DirectedEvidence (au.edu.wehi.idsv.DirectedEvidence)1 DirectedEvidenceOrder (au.edu.wehi.idsv.DirectedEvidenceOrder)1 DiscordantReadPair (au.edu.wehi.idsv.DiscordantReadPair)1 FileSystemContext (au.edu.wehi.idsv.FileSystemContext)1 GenomicProcessingContext (au.edu.wehi.idsv.GenomicProcessingContext)1 IdsvVariantContextBuilder (au.edu.wehi.idsv.IdsvVariantContextBuilder)1 IntermediateFilesTest (au.edu.wehi.idsv.IntermediateFilesTest)1 IntervalCoverageAccumulator (au.edu.wehi.idsv.IntervalCoverageAccumulator)1 NonReferenceReadPair (au.edu.wehi.idsv.NonReferenceReadPair)1