Search in sources :

Example 1 with NonReferenceReadPair

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

the class SupportNodeIterator method addSupport.

private boolean addSupport(List<KmerSupportNode> supportNodes, DirectedEvidence de, KmerEvidence e) {
    boolean hasNonReference = false;
    if (e != null) {
        for (int i = 0; i < e.length(); i++) {
            KmerSupportNode support = e.node(i);
            if (support != null) {
                // make sure that we are actually able to resort into kmer order
                if (support.firstStart() < de.getBreakendSummary().start - maxSupportStartPositionOffset) {
                    SAMRecord read = null;
                    if (de instanceof SingleReadEvidence) {
                        read = ((SingleReadEvidence) de).getSAMRecord();
                    } else if (de instanceof NonReferenceReadPair) {
                        read = ((NonReferenceReadPair) de).getLocalledMappedRead();
                    }
                    String readString = "";
                    if (read != null) {
                        readString = read.getReadName();
                        if (!read.getReadUnmappedFlag()) {
                            readString += String.format(" (%s:%d %s)", read.getReferenceName(), read.getStart(), read.getCigarString());
                        }
                    }
                    String msg = String.format("Error: kmer in evidence %s of read %s out of bounds." + " Kmer support starts at %d which is more than %d before the breakpoint start position at %s", de.getEvidenceID(), readString, support.firstStart(), maxSupportStartPositionOffset, de.getBreakendSummary());
                    log.error(msg);
                // Try to continue
                // throw new RuntimeException(msg);
                } else if (support.weight() <= 0) {
                    String msg = String.format("Invalid support weight of %d for evidence %s", support.weight(), de.getEvidenceID());
                    log.error(msg);
                    throw new RuntimeException(msg);
                } else {
                    supportNodes.add(support);
                    hasNonReference |= !support.isReference();
                }
            }
        }
    }
    return hasNonReference;
}
Also used : NonReferenceReadPair(au.edu.wehi.idsv.NonReferenceReadPair) SAMRecord(htsjdk.samtools.SAMRecord) SingleReadEvidence(au.edu.wehi.idsv.SingleReadEvidence)

Example 2 with NonReferenceReadPair

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

the class CallVariantsTest method test_sr_rp_assembly.

@Test
public void test_sr_rp_assembly() throws IOException {
    List<DirectedEvidence> in = new ArrayList<DirectedEvidence>();
    in.add(SCE(FWD, withSequence("AACCGGTTCTA", Read(0, 15, "5M6S"))));
    in.add(SCE(FWD, withSequence("AACCGGTTCTA", Read(0, 15, "6M5S"))));
    in.add(NRRP(withSequence("AACCGGTTCTA", DP(0, 1, "11M", true, 1, 100, "11M", false))));
    in.add(NRRP(withSequence("AACCGGTTCTA", DP(0, 2, "11M", true, 1, 100, "11M", false))));
    List<SAMRecord> insam = in.stream().flatMap(de -> {
        if (de instanceof SoftClipEvidence)
            return ImmutableList.<SAMRecord>of(((SoftClipEvidence) de).getSAMRecord()).stream();
        if (de instanceof NonReferenceReadPair)
            return ImmutableList.<SAMRecord>of(((NonReferenceReadPair) de).getNonReferenceRead(), ((NonReferenceReadPair) de).getLocalledMappedRead()).stream();
        throw new RuntimeException("NYI");
    }).collect(Collectors.toList());
    insam.addAll(Lists.newArrayList(RP(0, 1, 100, 10)));
    createInput(insam);
    File propfile = testFolder.newFile("custom.properties");
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(propfile))) {
        writer.write("assembly.k=5\n");
        writer.write("softclip.minLength=1\n");
        writer.write("minAnchorShannonEntropy=0\n");
        writer.write("softclip.minAnchorIdentity=0\n");
        writer.write("softclip.minAverageQual=0\n");
        writer.write("realignment.aligner=\n");
    }
    File assembly = new File(testFolder.getRoot(), "assembly.bam");
    String[] args = new String[] { "INPUT=" + input.toString(), "ASSEMBLY=" + assembly.toString(), "REFERENCE_SEQUENCE=" + reference.toString(), "OUTPUT=" + output.toString(), "TMP_DIR=" + super.testFolder.getRoot().toString(), "WORKING_DIR=" + super.testFolder.getRoot().toString(), "CONFIGURATION_FILE=" + propfile.toString(), "INPUT_MIN_FRAGMENT_SIZE=10", "INPUT_MAX_FRAGMENT_SIZE=100" };
    assertEquals(0, new CallVariants().instanceMain(args));
    List<SAMRecord> breakendAssemblies = getRecords(assembly);
    assertEquals(1, breakendAssemblies.size());
    assembly.delete();
}
Also used : IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) NonReferenceReadPair(au.edu.wehi.idsv.NonReferenceReadPair) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) DirectedEvidence(au.edu.wehi.idsv.DirectedEvidence) File(java.io.File) SAMRecord(htsjdk.samtools.SAMRecord) ArrayList(java.util.ArrayList) SortOrder(htsjdk.samtools.SAMFileHeader.SortOrder) List(java.util.List) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) SoftClipEvidence(au.edu.wehi.idsv.SoftClipEvidence) Assert.assertEquals(org.junit.Assert.assertEquals) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) NonReferenceReadPair(au.edu.wehi.idsv.NonReferenceReadPair) SoftClipEvidence(au.edu.wehi.idsv.SoftClipEvidence) DirectedEvidence(au.edu.wehi.idsv.DirectedEvidence) SAMRecord(htsjdk.samtools.SAMRecord) File(java.io.File) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) Test(org.junit.Test)

Example 3 with NonReferenceReadPair

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

the class CallVariantsTest method should_handle_unpaired_libraries.

@Test
public void should_handle_unpaired_libraries() throws IOException {
    List<DirectedEvidence> in = new ArrayList<DirectedEvidence>();
    in.add(SCE(FWD, withSequence("AACCGGTTCTA", Read(0, 15, "5M6S"))));
    List<SAMRecord> insam = in.stream().flatMap(de -> {
        if (de instanceof SoftClipEvidence)
            return ImmutableList.<SAMRecord>of(((SoftClipEvidence) de).getSAMRecord()).stream();
        if (de instanceof NonReferenceReadPair)
            return ImmutableList.<SAMRecord>of(((NonReferenceReadPair) de).getNonReferenceRead(), ((NonReferenceReadPair) de).getLocalledMappedRead()).stream();
        throw new RuntimeException("NYI");
    }).collect(Collectors.toList());
    createInput(insam);
    File assembly = new File(testFolder.getRoot(), "assembly.bam");
    createBAM(assembly, SortOrder.coordinate);
    String[] args = new String[] { "INPUT=" + input.toString(), "ASSEMBLY=" + assembly.toString(), "REFERENCE_SEQUENCE=" + reference.toString(), "OUTPUT=" + output.toString(), "TMP_DIR=" + super.testFolder.getRoot().toString(), "WORKING_DIR=" + super.testFolder.getRoot().toString() };
    assertEquals(0, new CallVariants().instanceMain(args));
    assertTrue(output.exists());
    assembly.delete();
}
Also used : IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) NonReferenceReadPair(au.edu.wehi.idsv.NonReferenceReadPair) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) DirectedEvidence(au.edu.wehi.idsv.DirectedEvidence) File(java.io.File) SAMRecord(htsjdk.samtools.SAMRecord) ArrayList(java.util.ArrayList) SortOrder(htsjdk.samtools.SAMFileHeader.SortOrder) List(java.util.List) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) SoftClipEvidence(au.edu.wehi.idsv.SoftClipEvidence) Assert.assertEquals(org.junit.Assert.assertEquals) ArrayList(java.util.ArrayList) NonReferenceReadPair(au.edu.wehi.idsv.NonReferenceReadPair) SoftClipEvidence(au.edu.wehi.idsv.SoftClipEvidence) DirectedEvidence(au.edu.wehi.idsv.DirectedEvidence) SAMRecord(htsjdk.samtools.SAMRecord) File(java.io.File) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) Test(org.junit.Test)

Example 4 with NonReferenceReadPair

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

the class NonReferenceContigAssemblerTest method should_assembly_UM_into_anchor.

@Test
public void should_assembly_UM_into_anchor() {
    ProcessingContext pc = getContext();
    pc.getAssemblyParameters().k = 4;
    pc.getAssemblyParameters().includePairAnchors = true;
    pc.getAssemblyParameters().pairAnchorMismatchIgnoreEndBases = 0;
    SAMRecord[] rp = OEA(0, 100, "10M", true);
    rp[0].setReadBases(B(S(RANDOM).substring(0, 10)));
    rp[1].setReadBases(B(S(RANDOM).substring(2, 12)));
    rp[1].setReadNegativeStrandFlag(true);
    NonReferenceReadPair nrrp = NRRP(SES(1, 100), rp);
    List<SAMRecord> output = go(pc, false, nrrp);
    assertEquals(S(RANDOM).substring(0, 12), S(output.get(0).getReadBases()));
    assertEquals(0, (int) output.get(0).getReferenceIndex());
    assertEquals(100, output.get(0).getAlignmentStart());
    assertEquals("10M2S", output.get(0).getCigarString());
}
Also used : NonReferenceReadPair(au.edu.wehi.idsv.NonReferenceReadPair) ProcessingContext(au.edu.wehi.idsv.ProcessingContext) SAMRecord(htsjdk.samtools.SAMRecord) Test(org.junit.Test)

Example 5 with NonReferenceReadPair

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

the class PathNodeIteratorTest method should_assembly_UM_into_anchor.

@Test
public void should_assembly_UM_into_anchor() {
    SAMRecord[] rp = OEA(0, 100, "10M", true);
    rp[0].setReadBases(B(S(RANDOM).substring(0, 10)));
    rp[1].setReadBases(B(S(RANDOM).substring(5, 15)));
    NonReferenceReadPair nrrp = NRRP(SES(1, 100), rp);
    List<KmerPathNode> result = asCheckedKPN(4, 100, true, nrrp);
    assertCompleteGraph(result, 4);
}
Also used : NonReferenceReadPair(au.edu.wehi.idsv.NonReferenceReadPair) SAMRecord(htsjdk.samtools.SAMRecord) Test(org.junit.Test)

Aggregations

NonReferenceReadPair (au.edu.wehi.idsv.NonReferenceReadPair)5 SAMRecord (htsjdk.samtools.SAMRecord)5 Test (org.junit.Test)4 DirectedEvidence (au.edu.wehi.idsv.DirectedEvidence)2 IntermediateFilesTest (au.edu.wehi.idsv.IntermediateFilesTest)2 SoftClipEvidence (au.edu.wehi.idsv.SoftClipEvidence)2 ImmutableList (com.google.common.collect.ImmutableList)2 Lists (com.google.common.collect.Lists)2 SortOrder (htsjdk.samtools.SAMFileHeader.SortOrder)2 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 ProcessingContext (au.edu.wehi.idsv.ProcessingContext)1 SingleReadEvidence (au.edu.wehi.idsv.SingleReadEvidence)1