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);
}
}
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);
}
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);
}
Aggregations