use of htsjdk.samtools.SAMSequenceDictionary in project gatk by broadinstitute.
the class GenomicsDBImport method initializeIntervals.
/**
* Loads our intervals using the best available sequence
* dictionary (as returned by {@link #getBestAvailableSequenceDictionary})
* to parse/verify them. Does nothing if no intervals were specified.
*/
private void initializeIntervals() {
if (intervalArgumentCollection.intervalsSpecified()) {
final SAMSequenceDictionary intervalDictionary = getBestAvailableSequenceDictionary();
if (intervalDictionary == null) {
throw new UserException("We require at least one input source that " + "has a sequence dictionary (reference or reads) when intervals are specified");
}
intervals = new ArrayList<>();
final List<SimpleInterval> simpleIntervalList = intervalArgumentCollection.getIntervals(intervalDictionary);
if (simpleIntervalList.size() > 1) {
throw new UserException("More than one interval specified. The tool takes only one");
}
for (final SimpleInterval simpleInterval : simpleIntervalList) {
intervals.add(new ChromosomeInterval(simpleInterval.getContig(), simpleInterval.getStart(), simpleInterval.getEnd()));
}
} else {
throw new UserException("No intervals specified");
}
}
use of htsjdk.samtools.SAMSequenceDictionary in project gatk by broadinstitute.
the class CreateSomaticPanelOfNormals method doWork.
public Object doWork() {
final List<File> inputVcfs = new ArrayList<>(vcfs);
final Collection<CloseableIterator<VariantContext>> iterators = new ArrayList<>(inputVcfs.size());
final Collection<VCFHeader> headers = new HashSet<>(inputVcfs.size());
final VCFHeader headerOfFirstVcf = new VCFFileReader(inputVcfs.get(0), false).getFileHeader();
final SAMSequenceDictionary sequenceDictionary = headerOfFirstVcf.getSequenceDictionary();
final VariantContextComparator comparator = headerOfFirstVcf.getVCFRecordComparator();
for (final File vcf : inputVcfs) {
final VCFFileReader reader = new VCFFileReader(vcf, false);
iterators.add(reader.iterator());
final VCFHeader header = reader.getFileHeader();
Utils.validateArg(comparator.isCompatible(header.getContigLines()), () -> vcf.getAbsolutePath() + " has incompatible contigs.");
headers.add(header);
}
final VariantContextWriter writer = GATKVariantContextUtils.createVCFWriter(outputVcf, sequenceDictionary, false, Options.INDEX_ON_THE_FLY);
writer.writeHeader(new VCFHeader(VCFUtils.smartMergeHeaders(headers, false)));
final MergingIterator<VariantContext> mergingIterator = new MergingIterator<>(comparator, iterators);
SimpleInterval currentPosition = new SimpleInterval("FAKE", 1, 1);
final List<VariantContext> variantsAtThisPosition = new ArrayList<>(20);
while (mergingIterator.hasNext()) {
final VariantContext vc = mergingIterator.next();
if (!currentPosition.overlaps(vc)) {
processVariantsAtSamePosition(variantsAtThisPosition, writer);
variantsAtThisPosition.clear();
currentPosition = new SimpleInterval(vc.getContig(), vc.getStart(), vc.getStart());
}
variantsAtThisPosition.add(vc);
}
mergingIterator.close();
writer.close();
return "SUCCESS";
}
use of htsjdk.samtools.SAMSequenceDictionary in project gatk by broadinstitute.
the class Mutect2 method onTraversalStart.
@Override
public void onTraversalStart() {
m2Engine = new Mutect2Engine(MTAC, getHeaderForReads(), referenceArguments.getReferenceFileName());
final SAMSequenceDictionary sequenceDictionary = getHeaderForReads().getSequenceDictionary();
vcfWriter = createVCFWriter(outputVCF);
m2Engine.writeHeader(vcfWriter, sequenceDictionary, getDefaultToolVCFHeaderLines());
}
use of htsjdk.samtools.SAMSequenceDictionary in project gatk by broadinstitute.
the class FeatureDataSourceUnitTest method testGetSequenceDictionary.
@Test
public void testGetSequenceDictionary() {
try (FeatureDataSource<VariantContext> featureSource = new FeatureDataSource<>(QUERY_TEST_VCF, "CustomName")) {
final SAMSequenceDictionary dict = featureSource.getSequenceDictionary();
Assert.assertEquals(dict.size(), 4);
Assert.assertEquals(dict.getSequences().stream().map(s -> s.getSequenceName()).collect(Collectors.toList()), Arrays.asList("1", "2", "3", "4"));
}
}
use of htsjdk.samtools.SAMSequenceDictionary in project gatk by broadinstitute.
the class GATKToolUnitTest method testBestSequenceDictionary_fromReads.
@Test
public void testBestSequenceDictionary_fromReads() throws Exception {
final GATKTool tool = new TestGATKToolWithReads();
final CommandLineParser clp = new CommandLineArgumentParser(tool);
final File bamFile = new File(publicTestDir + "org/broadinstitute/hellbender/engine/reads_data_source_test1.bam");
final String[] args = { "-I", bamFile.getCanonicalPath() };
clp.parseArguments(System.out, args);
tool.onStartup();
//read the dict back in and compare to bam dict
final SAMSequenceDictionary toolDict = tool.getBestAvailableSequenceDictionary();
try (final SamReader open = SamReaderFactory.makeDefault().open(bamFile)) {
final SAMSequenceDictionary bamDict = open.getFileHeader().getSequenceDictionary();
toolDict.assertSameDictionary(bamDict);
bamDict.assertSameDictionary(toolDict);
Assert.assertEquals(toolDict, bamDict);
}
}
Aggregations