Search in sources :

Example 1 with ChimericAlignment

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

the class SplitReadEvidenceTest method involvesPrimaryReadAlignment_should_allow_primary_remote.

@Test
public void involvesPrimaryReadAlignment_should_allow_primary_remote() {
    List<SingleReadEvidence> list;
    SAMRecord r = Read(0, 1, "10M10S");
    r.setSupplementaryAlignmentFlag(true);
    r.setAttribute("SA", new ChimericAlignment(Read(0, 10, "10S10M")).toString());
    list = SingleReadEvidence.createEvidence(SES(), 0, r);
    assertTrue(list.stream().allMatch(e -> e.involvesPrimaryReadAlignment()));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) InMemoryReferenceSequenceFile(au.edu.wehi.idsv.picard.InMemoryReferenceSequenceFile) Assert.assertNotNull(org.junit.Assert.assertNotNull) Header(htsjdk.samtools.metrics.Header) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) SynchronousReferenceLookupAdapter(au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter) SAMRecordUtil(au.edu.wehi.idsv.sam.SAMRecordUtil) Category(org.junit.experimental.categories.Category) SAMFileHeader(htsjdk.samtools.SAMFileHeader) File(java.io.File) SAMRecord(htsjdk.samtools.SAMRecord) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) Assert.assertFalse(org.junit.Assert.assertFalse) BiConsumer(java.util.function.BiConsumer) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) SAMRecord(htsjdk.samtools.SAMRecord) Test(org.junit.Test)

Example 2 with ChimericAlignment

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

the class SplitReadEvidenceTest method isReference_should_be_true_if_either_alignment_could_be_moved_to_the_other_breakend.

@Test
public void isReference_should_be_true_if_either_alignment_could_be_moved_to_the_other_breakend() {
    SAMRecord r1 = withSequence("TTTAACAA", Read(0, 10, "3M5S"))[0];
    SAMRecord r2 = withSequence("TTTAACAA", Read(0, 20, "3S2M3S"))[0];
    r1.setAttribute("SA", new ChimericAlignment(r2).toString());
    r2.setAttribute("SA", new ChimericAlignment(r1).toString());
    SplitReadEvidence e1 = SplitReadEvidence.create(SES(), r1).get(0);
    SplitReadEvidence e2 = SplitReadEvidence.create(SES(), r2).get(0);
    Assert.assertTrue(e2.isReference());
    Assert.assertTrue(e1.isReference());
}
Also used : ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) SAMRecord(htsjdk.samtools.SAMRecord) Test(org.junit.Test)

Example 3 with ChimericAlignment

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

the class StubFastqAligner method align.

public StubFastqAligner align(SAMRecord r, BreakendDirection direction, int referenceIndex, int pos, boolean isNegativeStrand, String cigar) {
    List<FastqRecord> srs = SplitReadIdentificationHelper.getSplitReadRealignments(r, false, eidgen);
    FastqRecord fqr = srs.get(0);
    if (srs.size() == 2) {
        if (direction == BreakendDirection.Forward ^ r.getReadNegativeStrandFlag()) {
            fqr = srs.get(1);
        }
    }
    map.put(fqr.getReadName(), new ChimericAlignment(r.getHeader().getSequenceDictionary().getSequence(referenceIndex).getSequenceName(), pos, isNegativeStrand, TextCigarCodec.decode(cigar), 40, 0));
    nameLookup.put(fqr.getReadName(), r);
    return this;
}
Also used : ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) FastqRecord(htsjdk.samtools.fastq.FastqRecord)

Example 4 with ChimericAlignment

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

the class StubFastqAligner method align.

@Override
public void align(File fastq, File output, File reference, int threads) throws IOException {
    SAMFileHeader header = context.getBasicSamHeader();
    try (FastqReader reader = new FastqReader(fastq)) {
        try (SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, true, output)) {
            for (FastqRecord fqr : reader) {
                SAMRecord source = nameLookup.get(fqr.getReadName());
                SAMRecord r = new SAMRecord(header);
                r.setReadName(fqr.getReadName());
                r.setReadBases(fqr.getReadString().getBytes());
                r.setBaseQualities(SAMUtils.fastqToPhred(fqr.getBaseQualityString()));
                if (source == null) {
                    r.setReadUnmappedFlag(true);
                } else {
                    ChimericAlignment aln = map.get(fqr.getReadName());
                    r.setReferenceName(aln.rname);
                    r.setAlignmentStart(aln.pos);
                    r.setCigar(aln.cigar);
                    r.setMappingQuality(aln.mapq);
                    r.setAttribute("NM", aln.nm);
                    if (aln.isNegativeStrand) {
                        SequenceUtil.reverseComplement(r.getReadBases());
                        ArrayUtils.reverse(r.getBaseQualities());
                    }
                }
                writer.addAlignment(r);
            }
        }
    }
}
Also used : ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) FastqReader(htsjdk.samtools.fastq.FastqReader) SAMFileWriter(htsjdk.samtools.SAMFileWriter) SAMRecord(htsjdk.samtools.SAMRecord) FastqRecord(htsjdk.samtools.fastq.FastqRecord) SAMFileWriterFactory(htsjdk.samtools.SAMFileWriterFactory) SAMFileHeader(htsjdk.samtools.SAMFileHeader)

Example 5 with ChimericAlignment

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

the class ExtractSVReadsTest method hasReadAlignmentConsistentWithReference_should_consider_SA_alignments.

/*
	@Test
	public void should_not_extract_unclipped_alignment_overlapping_blacklist() {
		createInput();
		IntervalBed blacklist = new IntervalBed(getSequenceDictionary(), new PaddedLinearGenomicCoordinate(getSequenceDictionary()));
		blacklist.addInterval(0, 2, 2);
				
		ExtractSVReads extract = new ExtractSVReads();
		extract.INPUT = input;
		extract.OUTPUT = output;
		extract.setBlacklist(blacklist);
		extract.setup(getHeader(), extract.INPUT);
		extract.acceptFragment(ImmutableList.of(Read(0, 1, "1M1S")), null); // Soft clip breakpoint position overlaps
		extract.acceptFragment(ImmutableList.of(Read(0, 2, "1M1S")), null); // overlaps
		extract.acceptFragment(ImmutableList.of(Read(0, 3, "1M1S")), null);
		extract.acceptFragment(ImmutableList.of(Read(0, 4, "1M1S")), null);
		extract.acceptFragment(ImmutableList.of(Read(0, 3, "1S1M")), null); // overlaps
		extract.finish();
		List<SAMRecord> out = getRecords(output);
		assertEquals(2, out.size());
	}
	@Test
	public void should_not_extract_any_read_from_fragment_overlapping_read_pair_breakend() {
		createInput();
		IntervalBed blacklist = new IntervalBed(getSequenceDictionary(), new PaddedLinearGenomicCoordinate(getSequenceDictionary()));
		blacklist.addInterval(0, 2, 2);
				
		ExtractSVReads extract = new ExtractSVReads();
		extract.INPUT = input;
		extract.OUTPUT = output;
		extract.FIXED_READ_PAIR_CONCORDANCE_MAX_FRAGMENT_SIZE = 2;
		extract.FIXED_READ_PAIR_CONCORDANCE_MIN_FRAGMENT_SIZE = 2;
		extract.READ_PAIR_CONCORDANCE_METHOD = ReadPairConcordanceMethod.FIXED;
		extract.setBlacklist(blacklist);
		extract.setup(getHeader(), extract.INPUT);
		extract.acceptFragment(Lists.newArrayList(DP(0, 1, "1M", true, 1, 1, "1M", false)), null); // breakend overlaps
		extract.acceptFragment(Lists.newArrayList(DP(0, 1, "1M", false, 1, 1, "1M", false)), null); // other direction = no overlap 
		extract.acceptFragment(Lists.newArrayList(DP(0, 2, "1M", true, 1, 1, "1M", false)), null); // read overlaps
		extract.acceptFragment(Lists.newArrayList(DP(0, 2, "1M", false, 1, 1, "1M", false)), null); // read overlaps 
		extract.acceptFragment(Lists.newArrayList(DP(0, 3, "1M", true, 1, 1, "1M", false)), null); // other direction = no overlap 
		extract.acceptFragment(Lists.newArrayList(DP(0, 3, "1M", false, 1, 1, "1M", false)), null); // breakend overlaps
		extract.finish();
		List<SAMRecord> out = getRecords(output);
		assertEquals(2 * 2, out.size());
	}
	@Test
	public void should_not_extract_any_split_reads_overlapping_blacklist() {
		fail();
	}
	*/
@Test
public void hasReadAlignmentConsistentWithReference_should_consider_SA_alignments() {
    SAMRecord r = Read(0, 1, "5M5S");
    r.setAttribute("SA", new ChimericAlignment(Read(0, 1, "10M")).toString());
    Assert.assertTrue(ExtractSVReads.hasReadAlignmentConsistentWithReference(ImmutableList.of(r))[0]);
}
Also used : ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) SAMRecord(htsjdk.samtools.SAMRecord) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) Test(org.junit.Test)

Aggregations

ChimericAlignment (au.edu.wehi.idsv.sam.ChimericAlignment)20 SAMRecord (htsjdk.samtools.SAMRecord)16 Test (org.junit.Test)11 List (java.util.List)5 IntermediateFilesTest (au.edu.wehi.idsv.IntermediateFilesTest)4 SynchronousReferenceLookupAdapter (au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter)4 ImmutableList (com.google.common.collect.ImmutableList)4 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)4 File (java.io.File)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Assert (org.junit.Assert)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertFalse (org.junit.Assert.assertFalse)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Category (org.junit.experimental.categories.Category)4 FixedSizeReadPairConcordanceCalculator (au.edu.wehi.idsv.FixedSizeReadPairConcordanceCalculator)3 SAMRecordUtil (au.edu.wehi.idsv.sam.SAMRecordUtil)3 Lists (com.google.common.collect.Lists)3 SAMFileHeader (htsjdk.samtools.SAMFileHeader)3