/** * Creates an artificial sam header based on the sequence dictionary dict * * @return a new sam header */ public static SAMFileHeader createArtificialSamHeader(final SAMSequenceDictionary dict) { SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(htsjdk.samtools.SAMFileHeader.SortOrder.coordinate); header.setSequenceDictionary(dict); return header; }
@Test(expectedExceptions=IllegalArgumentException.class) public void testResolveNameUnresolvable() { final SAMFileHeader samHeader = new SAMFileHeader(); SAMRecord.resolveNameFromIndex(99, samHeader); }
@Test public void testResolveNameNoAlignment() { final SAMFileHeader samHeader = new SAMFileHeader(); Assert.assertEquals(SAMRecord.resolveNameFromIndex( SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX, samHeader), SAMRecord.NO_ALIGNMENT_REFERENCE_NAME); }
@Test(expectedExceptions = SAMException.class) public void testRequireCoordinateSortOrder() { SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(SAMFileHeader.SortOrder.queryname); new BAMIndexer(new ByteArrayOutputStream(), header); }
@Test public void testGetSequenceIfSequenceDictionaryIsEmpty() { final SAMFileHeader header = new SAMFileHeader(); header.setSequenceDictionary(null); Assert.assertNull(header.getSequence("chr1")); }
@Test public void testEmptyArrayAttributeHasNoCommaWhenWrittenToSAM(){ final SAMFileHeader header = new SAMFileHeader(); final SAMRecord record = new SAMRecord(header); record.setAttribute("xa", new int[0]); Assert.assertTrue(record.getSAMString().endsWith("xa:B:i\n")); } }
private SAMFileHeader createOutHeader( final SAMFileHeader inHeader, final SAMFileHeader.SortOrder sortOrder, final boolean removeAlignmentInformation) { final SAMFileHeader outHeader = new SAMFileHeader(); outHeader.setSortOrder(sortOrder); if (!removeAlignmentInformation) { outHeader.setSequenceDictionary(inHeader.getSequenceDictionary()); outHeader.setProgramRecords(inHeader.getProgramRecords()); } return outHeader; }
private SAMRecord generateRecord(String name) { SAMRecord record = new SAMRecord(new SAMFileHeader()); record.setReadName(name); record.setBaseQualities(highQualities); record.setReadBases(refBases); return record; }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_setAttribute_unsigned_int_tooLarge() { SAMFileHeader header = new SAMFileHeader(); SAMRecord record = new SAMRecord(header); Assert.assertNull(record.getUnsignedIntegerAttribute("UI")); record.setAttribute("UI", (long) BinaryCodec.MAX_UINT + 1L); }
@Test(dataProvider = "brokenUmiProvider", expectedExceptions = PicardException.class) public void testBrokenUmi(final String brokenUmi) { SAMFileHeader header = new SAMFileHeader(); SAMRecord rec = new SAMRecord(header); rec.setAttribute("RX", brokenUmi); // This should throw an exception due to a broken UMI in rec UmiUtil.getTopStrandNormalizedUmi(rec, "RX", true); } }
public static SAMFileHeader duplicateSAMFileHeader(SAMFileHeader toCopy) { SAMFileHeader copy = new SAMFileHeader(); copy.setSortOrder(toCopy.getSortOrder()); copy.setGroupOrder(toCopy.getGroupOrder()); copy.setProgramRecords(toCopy.getProgramRecords()); copy.setReadGroups(toCopy.getReadGroups()); copy.setSequenceDictionary(toCopy.getSequenceDictionary()); for (Map.Entry<String, String> e : toCopy.getAttributes()) copy.setAttribute(e.getKey(), e.getValue()); return copy; }
@Test public void test_setAttribute_empty_array() { final SAMFileHeader header = new SAMFileHeader(); final SAMRecord record = new SAMRecord(header); Assert.assertNull(record.getStringAttribute(ARRAY_TAG)); record.setAttribute(ARRAY_TAG, new int[0]); Assert.assertNotNull(record.getSignedIntArrayAttribute(ARRAY_TAG)); Assert.assertEquals(record.getSignedIntArrayAttribute(ARRAY_TAG), new int[0]); Assert.assertEquals(record.getAttribute(ARRAY_TAG), new char[0]); record.setAttribute(ARRAY_TAG, null); Assert.assertNull(record.getStringAttribute(ARRAY_TAG)); }
@Test public void testMakeCRAMWriterWithOptions() throws Exception { final File outputFile = prepareOutputFile(CramIO.CRAM_FILE_EXTENSION); final SAMFileHeader header = new SAMFileHeader(); final SAMFileWriterFactory factory = createWriterFactoryWithOptions(header); final File referenceFile = new File(TEST_DATA_DIR, "hg19mini.fasta"); int nRecs; try (final SAMFileWriter samWriter = factory.makeCRAMWriter(header, false, outputFile, referenceFile)) { nRecs = fillSmallBam(samWriter); } verifyWriterOutput(outputFile, new ReferenceSource(referenceFile), nRecs, true); }
@BeforeTest public void setUp(){ String referenceString = ">chrM\nACCTACGTTCAATATTCTTCACCTACGTTCAATATTCTTCACCTACGTTCAATATTCTTCACCTACGTTCAATATTCTTCACCTACGTTCAATATTCTTC"; ref = new ReferenceSequence("chrM", 0, referenceString.getBytes()); sequence = new SAMSequenceRecord("chrM", 100); record = new SAMRecord(new SAMFileHeader()); record.setReadName("test"); record.setBaseQualities(qualities); record.setReadBases(refBases); secondRecord = generateRecord("test1"); thirdRecord = generateRecord("test2"); }
@BeforeClass public void init() { SAMSequenceDictionary sequenceDictionary = new SAMSequenceDictionary(); sequenceDictionary.addSequence(new SAMSequenceRecord("1",500)); sequenceDictionary.addSequence(new SAMSequenceRecord("2",500)); samFileHeader = new SAMFileHeader(); samFileHeader.setSequenceDictionary(sequenceDictionary); }
private SAMFileHeader createSAMHeader(SAMFileHeader.SortOrder sortOrder) { final SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(sortOrder); header.addSequence(new SAMSequenceRecord("chr1", 123)); SAMReadGroupRecord readGroupRecord = new SAMReadGroupRecord("1"); header.addReadGroup(readGroupRecord); return header; }
private IntervalList buildIntervalList(final int start, final int end) { final SAMFileHeader header = new SAMFileHeader(); header.addSequence(new SAMSequenceRecord("CONTIG", 100000000)); final IntervalList intervals = new IntervalList(header); if (0 < start) intervals.add(new Interval("CONTIG", start, end)); return intervals; }
private SAMFileHeader getSAMFileHeader() { final VCFFileReader reader = getReader(CEU_TRIOS_SNPS_VCF); final SAMSequenceDictionary dict = reader.getFileHeader().getSequenceDictionary(); reader.close(); final SAMFileHeader header = new SAMFileHeader(); header.setSequenceDictionary(dict); return header; }
private SAMFileHeader createSAMHeader(SAMFileHeader.SortOrder sortOrder) { final SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(sortOrder); header.addSequence(new SAMSequenceRecord("chr1", 123)); header.addSequence(new SAMSequenceRecord("chr2", 123)); SAMReadGroupRecord readGroupRecord = new SAMReadGroupRecord("1"); header.addReadGroup(readGroupRecord); return header; }
private void createSmallBam(final Path outputPath) { final SAMFileWriterFactory factory = new SAMFileWriterFactory(); factory.setCreateIndex(true); factory.setCreateMd5File(true); final SAMFileHeader header = new SAMFileHeader(); // index only created if coordinate sorted header.setSortOrder(SAMFileHeader.SortOrder.coordinate); header.addSequence(new SAMSequenceRecord("chr1", 123)); try (final SAMFileWriter writer = factory.makeBAMWriter(header, false, outputPath)) { fillSmallBam(writer); } }