Search in sources :

Example 1 with BwaMemIndex

use of org.broadinstitute.hellbender.utils.bwa.BwaMemIndex in project gatk by broadinstitute.

the class BwaMemIndexImageCreatorIntegrationTest method testImageFileGeneration.

@Test
public void testImageFileGeneration() throws Exception {
    final File tempImage = BaseTest.createTempFile("tempBwaMemIndexImage", ".img");
    final List<String> args = new ArrayList<>(Arrays.asList("--input", testReferenceFasta.getAbsolutePath(), "--output", tempImage.getAbsolutePath()));
    runCommandLine(args);
    // piggy-backing on the existing integration test
    try (final BwaMemIndex index = new BwaMemIndex(tempImage.getAbsolutePath())) {
        BwaMemTestUtils.assertCorrectSingleReadAlignment(index);
        BwaMemTestUtils.assertCorrectChimericContigAlignment(index);
    }
}
Also used : ArrayList(java.util.ArrayList) BwaMemIndex(org.broadinstitute.hellbender.utils.bwa.BwaMemIndex) File(java.io.File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 2 with BwaMemIndex

use of org.broadinstitute.hellbender.utils.bwa.BwaMemIndex in project gatk by broadinstitute.

the class ContigAligner method alignContigs.

/**
     * Takes a collection of assembled contigs and aligns them to the reference with bwa-mem. Non-canonical
     * (secondary) alignments are filtered out, preserving the primary and supplementary alignments.
     * Within the output list, alignments are sorted first by contig (based on the order in which
     * the contigs were passed in, and then by their start position on the contig).
     * @param assemblyId An identifier for the assembly or set of contigs
     * @param contigsCollection The set of all canonical (primary or supplementary) alignments for the contigs.*/
AlignedAssembly alignContigs(final int assemblyId, final ContigsCollection contigsCollection) {
    final List<AlignedContig> alignedContigs = new ArrayList<>(contigsCollection.getContents().size());
    final BwaMemIndex index = BwaMemIndexSingleton.getInstance(indexImageFile);
    try (final BwaMemAligner aligner = new BwaMemAligner(index)) {
        final List<String> refNames = index.getReferenceContigNames();
        final List<Tuple2<ContigsCollection.ContigID, ContigsCollection.ContigSequence>> contents = contigsCollection.getContents();
        final List<byte[]> seqs = contents.stream().map(contigInfo -> contigInfo._2.toString().getBytes()).collect(Collectors.toList());
        final List<List<BwaMemAlignment>> allAlignments = aligner.alignSeqs(seqs);
        for (int contigIdx = 0; contigIdx < seqs.size(); ++contigIdx) {
            final int contigLen = seqs.get(contigIdx).length;
            // filter out secondary alignments, convert to AlignmentInterval objects and sort by alignment start pos
            final List<AlignedAssembly.AlignmentInterval> alignmentIntervals = allAlignments.get(contigIdx).stream().filter(a -> (a.getSamFlag() & SAMFlag.NOT_PRIMARY_ALIGNMENT.intValue()) == 0).filter(a -> (a.getSamFlag() & SAMFlag.READ_UNMAPPED.intValue()) == 0).map(a -> new AlignedAssembly.AlignmentInterval(a, refNames, contigLen)).sorted(Comparator.comparing(a -> a.startInAssembledContig)).collect(Collectors.toList());
            final String contigName = AlignedAssemblyOrExcuse.formatContigName(assemblyId, Integer.valueOf(contents.get(contigIdx)._1.toString().split(" ")[0].replace("contig", "").replace("-", "").replace(">", "")));
            alignedContigs.add(new AlignedContig(contigName, seqs.get(contigIdx), alignmentIntervals));
        }
    }
    return new AlignedAssembly(assemblyId, alignedContigs);
}
Also used : BwaMemAligner(org.broadinstitute.hellbender.utils.bwa.BwaMemAligner) BwaMemIndexSingleton(org.broadinstitute.hellbender.utils.bwa.BwaMemIndexSingleton) java.util(java.util) SAMFlag(htsjdk.samtools.SAMFlag) BwaMemIndex(org.broadinstitute.hellbender.utils.bwa.BwaMemIndex) Tuple2(scala.Tuple2) BwaMemAlignment(org.broadinstitute.hellbender.utils.bwa.BwaMemAlignment) Collectors(java.util.stream.Collectors) Tuple2(scala.Tuple2) BwaMemIndex(org.broadinstitute.hellbender.utils.bwa.BwaMemIndex) BwaMemAligner(org.broadinstitute.hellbender.utils.bwa.BwaMemAligner)

Example 3 with BwaMemIndex

use of org.broadinstitute.hellbender.utils.bwa.BwaMemIndex in project gatk by broadinstitute.

the class BwaMemIntegrationTest method loadIndex.

@BeforeSuite
public void loadIndex() {
    final String imageFile = createTempFile(b37_reference_20_21, ".img").toString();
    BwaMemIndex.createIndexImage(b37_reference_20_21, imageFile);
    index = new BwaMemIndex(imageFile);
}
Also used : BwaMemIndex(org.broadinstitute.hellbender.utils.bwa.BwaMemIndex) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

BwaMemIndex (org.broadinstitute.hellbender.utils.bwa.BwaMemIndex)3 SAMFlag (htsjdk.samtools.SAMFlag)1 File (java.io.File)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collectors (java.util.stream.Collectors)1 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)1 BwaMemAligner (org.broadinstitute.hellbender.utils.bwa.BwaMemAligner)1 BwaMemAlignment (org.broadinstitute.hellbender.utils.bwa.BwaMemAlignment)1 BwaMemIndexSingleton (org.broadinstitute.hellbender.utils.bwa.BwaMemIndexSingleton)1 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)1 BeforeSuite (org.testng.annotations.BeforeSuite)1 Test (org.testng.annotations.Test)1 Tuple2 (scala.Tuple2)1