Search in sources :

Example 6 with IdsvVariantContext

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

the class VcfTransformCommandLineProgram method getBreakpoints.

public CloseableIterator<VariantContextDirectedBreakpoint> getBreakpoints(File file) {
    VCFFileReader vcfReader = new VCFFileReader(file, false);
    CloseableIterator<VariantContext> it = vcfReader.iterator();
    Iterator<IdsvVariantContext> idsvIt = Iterators.transform(it, variant -> IdsvVariantContext.create(getContext(), null, variant));
    Iterator<VariantContextDirectedBreakpoint> bpit = Iterators.filter(idsvIt, VariantContextDirectedBreakpoint.class);
    // resort by evidence start
    bpit = new DirectEvidenceWindowedSortingIterator<>(getContext(), SAMEvidenceSource.maximumWindowSize(getContext(), getSamEvidenceSources(), getAssemblySource()), bpit);
    return new AutoClosingIterator<VariantContextDirectedBreakpoint>(bpit, it, vcfReader);
}
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)

Example 7 with IdsvVariantContext

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

the class SimulatedChromosome method assemble.

protected void assemble(File fasta, File vcf, List<Fragment> fragList, boolean includeReference) throws IOException {
    StringBuilder sb = new StringBuilder();
    if (includeReference) {
        sb.append(">");
        sb.append(getChr());
        sb.append("\n");
        sb.append(new String(seq, StandardCharsets.US_ASCII));
        sb.append("\n");
    }
    sb.append(">chromothripsis." + getChr() + "\n");
    List<IdsvVariantContext> calls = Lists.newArrayList();
    Fragment last = null;
    for (int i = 0; i < fragList.size(); i++) {
        Fragment f = fragList.get(i);
        sb.append(f.getSequence());
        if (last != null) {
            BreakpointSummary bp = new BreakpointSummary(last.getEndBreakend(), f.getStartBreakend());
            String event = String.format("truth_%d_", i);
            calls.add(create(bp, event).make());
            calls.add(create(bp.remoteBreakpoint(), event).make());
        }
        last = f;
    }
    Collections.sort(calls, IdsvVariantContext.ByLocationStart);
    Files.write(sb.toString(), fasta, StandardCharsets.US_ASCII);
    VariantContextWriter writer = context.getVariantContextWriter(vcf, true);
    for (VariantContext vc : calls) {
        writer.add(vc);
    }
    writer.close();
}
Also used : IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) VariantContext(htsjdk.variant.variantcontext.VariantContext) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) BreakpointSummary(au.edu.wehi.idsv.BreakpointSummary) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter)

Example 8 with IdsvVariantContext

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

the class AllocateEvidenceTest method should_uniquely_assign.

@Test
public void should_uniquely_assign() throws IOException, InterruptedException, ExecutionException {
    final int fragSize = 4;
    final int testSize = 64;
    final List<SAMRecord> in = new ArrayList<SAMRecord>();
    final ProcessingContext pc = getCommandlineContext();
    pc.getVariantCallingParameters().writeFiltered = true;
    pc.getVariantCallingParameters().minScore = 0;
    StubSAMEvidenceSource ses = new StubSAMEvidenceSource(pc, input, 0, 0, fragSize);
    for (int i = 1; i < testSize; i++) {
        for (int j = 1; j < testSize; j++) {
            SAMRecord[] dp = withReadName(String.format("read-%d-%d", i, j), DP(0, i, "1M", true, 1, j, "1M", false));
            ses.evidence.add(NonReferenceReadPair.create(dp[0], dp[1], ses));
            ses.evidence.add(NonReferenceReadPair.create(dp[1], dp[0], ses));
            in.add(dp[0]);
            in.add(dp[1]);
        }
    }
    StubAssemblyEvidenceSource aes = new StubAssemblyEvidenceSource(pc);
    aes.fragSize = fragSize;
    Collections.sort(ses.evidence, DirectedEvidenceOrder.ByNatural);
    createInput(in);
    VariantCaller vc = new VariantCaller(pc, ImmutableList.<SAMEvidenceSource>of(ses), aes);
    ExecutorService threadpool = Executors.newSingleThreadExecutor();
    vc.callBreakends(output, threadpool);
    threadpool.shutdown();
    AllocateEvidence cmd = new AllocateEvidence();
    cmd.INPUT_VCF = output;
    cmd.setContext(pc);
    cmd.setAssemblySource(aes);
    cmd.setSamEvidenceSources(ImmutableList.of(ses));
    cmd.OUTPUT_VCF = new File(testFolder.getRoot(), "annotated.vcf");
    cmd.ASSEMBLY = new File(testFolder.getRoot(), "assembly.bam");
    // to shut up the command-line parsing
    createBAM(cmd.ASSEMBLY, SortOrder.coordinate, Collections.emptyList());
    cmd.doWork(null);
    // List<IdsvVariantContext> annotated = getVcf(new File(testFolder.getRoot(), "out.vcf"), null);
    List<IdsvVariantContext> rawcalls = getVcf(output, null);
    List<IdsvVariantContext> calls = getVcf(cmd.OUTPUT_VCF, null);
    assertSymmetrical(rawcalls.stream().map(x -> (VariantContextDirectedBreakpoint) x).collect(Collectors.toList()));
    assertSymmetrical(calls.stream().map(x -> (VariantContextDirectedBreakpoint) x).collect(Collectors.toList()));
    // with no filtering, annotation should not change call set
    double expectedEvidence = 0;
    for (DirectedEvidence e : ses.evidence) {
        DiscordantReadPair bp = (DiscordantReadPair) e;
        expectedEvidence += bp.getBreakpointQual();
    }
    double annotatedEvidence = 0;
    for (IdsvVariantContext e : calls) {
        annotatedEvidence += e.getPhredScaledQual();
    }
    double rawEvidence = rawcalls.stream().mapToDouble(e -> e.getPhredScaledQual()).sum();
    // unique assignment must result in the evidence total being, at most, the same
    assertTrue(annotatedEvidence <= rawEvidence);
    // each piece of evidence should be assigned to a single breakpoint so totals should match
    int rpCalls = calls.stream().mapToInt(v -> ((VariantContextDirectedBreakpoint) v).getBreakpointEvidenceCount()).sum();
    assertEquals(ses.evidence.size(), rpCalls);
    // floating point truncation on VCF is severe!
    assertEquals(expectedEvidence, annotatedEvidence, 20);
}
Also used : AssemblyEvidenceSource(au.edu.wehi.idsv.AssemblyEvidenceSource) DirectedEvidenceOrder(au.edu.wehi.idsv.DirectedEvidenceOrder) Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) SAMEvidenceSource(au.edu.wehi.idsv.SAMEvidenceSource) ArrayList(java.util.ArrayList) SortOrder(htsjdk.samtools.SAMFileHeader.SortOrder) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint) Lists(com.google.common.collect.Lists) AutoClosingIterator(au.edu.wehi.idsv.util.AutoClosingIterator) ImmutableList(com.google.common.collect.ImmutableList) ProcessingContext(au.edu.wehi.idsv.ProcessingContext) ExecutorService(java.util.concurrent.ExecutorService) VariantCaller(au.edu.wehi.idsv.VariantCaller) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) NonReferenceReadPair(au.edu.wehi.idsv.NonReferenceReadPair) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) DirectedEvidence(au.edu.wehi.idsv.DirectedEvidence) File(java.io.File) Executors(java.util.concurrent.Executors) SAMRecord(htsjdk.samtools.SAMRecord) ExecutionException(java.util.concurrent.ExecutionException) DiscordantReadPair(au.edu.wehi.idsv.DiscordantReadPair) List(java.util.List) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ProcessingContext(au.edu.wehi.idsv.ProcessingContext) ArrayList(java.util.ArrayList) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint) DirectedEvidence(au.edu.wehi.idsv.DirectedEvidence) SAMRecord(htsjdk.samtools.SAMRecord) ExecutorService(java.util.concurrent.ExecutorService) VariantCaller(au.edu.wehi.idsv.VariantCaller) DiscordantReadPair(au.edu.wehi.idsv.DiscordantReadPair) File(java.io.File) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) Test(org.junit.Test)

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