public void setReadGroup(final SAMReadGroupRecord readGroup) { this.readGroup = readGroup; if (readGroup != null) { this.header.addReadGroup(readGroup); } }
public void setReadGroup(final SAMReadGroupRecord readGroup) { this.readGroup = readGroup; if (readGroup != null) { this.header.addReadGroup(readGroup); } }
public void setReadGroup(final SAMReadGroupRecord readGroup) { this.readGroup = readGroup; if (readGroup != null) { this.header.addReadGroup(readGroup); } }
private Map<String, SAMFileHeader> createHeaderMap( final SAMFileHeader inHeader, final SortOrder sortOrder, final boolean removeAlignmentInformation) { final Map<String, SAMFileHeader> headerMap = new HashMap<>(); for (final SAMReadGroupRecord readGroup : inHeader.getReadGroups()) { final SAMFileHeader header = createOutHeader(inHeader, sortOrder, removeAlignmentInformation); header.addReadGroup(readGroup); headerMap.put(readGroup.getId(), header); } return headerMap; }
private Map<String, SAMFileHeader> createHeaderMap( final SAMFileHeader inHeader, final SortOrder sortOrder, final boolean removeAlignmentInformation) { final Map<String, SAMFileHeader> headerMap = new HashMap<>(); for (final SAMReadGroupRecord readGroup : inHeader.getReadGroups()) { final SAMFileHeader header = createOutHeader(inHeader, sortOrder, removeAlignmentInformation); header.addReadGroup(readGroup); headerMap.put(readGroup.getId(), header); } return headerMap; }
public ArtificialBAMBuilder createAndSetHeader(final int nSamples) { createdReads = null; this.header = new SAMFileHeader(); header.setSortOrder(SAMFileHeader.SortOrder.coordinate); header.setSequenceDictionary(parser.getContigs()); samples.clear(); for ( int i = 0; i < nSamples; i++ ) { final GATKSAMReadGroupRecord rg = new GATKSAMReadGroupRecord("rg" + i); final String sample = "sample" + i; samples.add(sample); rg.setSample(sample); rg.setPlatform(NGSPlatform.ILLUMINA.getDefaultPlatform()); header.addReadGroup(rg); } return this; }
@Test() public void testPLFromReadWithRGButNoPL() { final SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader(seq.getSequenceDictionary()); final String rgID = "ID"; final SAMReadGroupRecord rg = new SAMReadGroupRecord(rgID); header.addReadGroup(rg); final GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "myRead", 0, 1, 10); read.setAttribute("RG", rgID); Assert.assertEquals(NGSPlatform.fromRead(read), NGSPlatform.UNKNOWN); }
@BeforeClass public void setUp() throws Exception { header = ArtificialSAMUtils.createArtificialSamHeader(1, 1, 1000); rg = new GATKSAMReadGroupRecord(RGID); rg.setSample(sample); header.addReadGroup(rg); parser = new GenomeLocParser(header.getSequenceDictionary()); }
/** * A unit test that creates an artificial read for testing some code that uses reads */ @Test(dataProvider = "TestMappings") public void testPLFromReadWithRG(final String plField, final NGSPlatform expected) { final SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader(seq.getSequenceDictionary()); final String rgID = "ID"; final SAMReadGroupRecord rg = new SAMReadGroupRecord(rgID); if ( plField != null ) rg.setPlatform(plField); header.addReadGroup(rg); final GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "myRead", 0, 1, 10); read.setAttribute("RG", rgID); Assert.assertEquals(NGSPlatform.fromRead(read), expected); }
private SAMFileHeader loadSamHeader() throws ErrorMsg { if (run == null) { throw new RuntimeException("Cannot load SAMFileHeader - SRA run is uninitialized"); } String runName = run.getName(); SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(SAMFileHeader.SortOrder.coordinate); ReadGroupIterator itRg = run.getReadGroups(); while (itRg.nextReadGroup()) { String rgName = itRg.getName(); if (rgName.isEmpty()) rgName = runName; SAMReadGroupRecord rg = new SAMReadGroupRecord(rgName); rg.setSample(runName); header.addReadGroup(rg); } ReferenceIterator itRef = run.getReferences(); while (itRef.nextReference()) { header.addSequence(new SAMSequenceRecord(itRef.getCanonicalName(), (int) itRef.getLength())); } return header; }
private SAMFileHeader loadSamHeader() throws ErrorMsg { if (run == null) { throw new RuntimeException("Cannot load SAMFileHeader - SRA run is uninitialized"); } String runName = run.getName(); SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(SAMFileHeader.SortOrder.coordinate); ReadGroupIterator itRg = run.getReadGroups(); while (itRg.nextReadGroup()) { String rgName = itRg.getName(); if (rgName.isEmpty()) rgName = runName; SAMReadGroupRecord rg = new SAMReadGroupRecord(rgName); rg.setSample(runName); header.addReadGroup(rg); } ReferenceIterator itRef = run.getReferences(); while (itRef.nextReference()) { header.addSequence(new SAMSequenceRecord(itRef.getCanonicalName(), (int) itRef.getLength())); } return header; }
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; }
void setup(final int numReads, final String readName, final int ID, final String readGroupId, final SAMReadGroupRecord readGroupRecord, final String sample, final String library, final SAMFileHeader header, final SAMRecordSetBuilder setBuilder) throws IOException { final String separator = ":"; readGroupRecord.setSample(sample); readGroupRecord.setPlatform(platform); readGroupRecord.setLibrary(library); readGroupRecord.setPlatformUnit(readGroupId); header.addReadGroup(readGroupRecord); setBuilder.setReadGroup(readGroupRecord); setBuilder.setUseNmFlag(true); setBuilder.setHeader(header); final int max = 15000; final int min = 1; final Random rg = new Random(5); for (int i = 0; i < numReads; i++) { final int start = rg.nextInt(max) + min; final String newReadName = readName + separator + ID + separator + i; setBuilder.addPair(newReadName, 0, start + ID, start + ID + 99); } }
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 SAMFileWriterFactory createWriterFactoryWithOptions(SAMFileHeader header) { final SAMFileWriterFactory factory = new SAMFileWriterFactory(); factory.setCreateIndex(true); factory.setCreateMd5File(true); // index only created if coordinate sorted header.setSortOrder(SAMFileHeader.SortOrder.coordinate); header.addSequence(new SAMSequenceRecord("chr1", 123)); header.addReadGroup(new SAMReadGroupRecord("1")); return factory; }
/** Creates a simple header with the values provided on the command line. */ public SAMFileHeader createSamFileHeader() { final SAMReadGroupRecord rgroup = new SAMReadGroupRecord(this.READ_GROUP_NAME); rgroup.setSample(this.SAMPLE_NAME); if (this.LIBRARY_NAME != null) rgroup.setLibrary(this.LIBRARY_NAME); if (this.PLATFORM != null) rgroup.setPlatform(this.PLATFORM); if (this.PLATFORM_UNIT != null) rgroup.setPlatformUnit(this.PLATFORM_UNIT); if (this.SEQUENCING_CENTER != null) rgroup.setSequencingCenter(SEQUENCING_CENTER); if (this.PREDICTED_INSERT_SIZE != null) rgroup.setPredictedMedianInsertSize(PREDICTED_INSERT_SIZE); if (this.DESCRIPTION != null) rgroup.setDescription(this.DESCRIPTION); if (this.RUN_DATE != null) rgroup.setRunDate(this.RUN_DATE); if (this.PLATFORM_MODEL != null) rgroup.setPlatformModel(this.PLATFORM_MODEL); if (this.PROGRAM_GROUP != null) rgroup.setProgramGroup(this.PROGRAM_GROUP); final SAMFileHeader header = new SAMFileHeader(); header.addReadGroup(rgroup); for (final String comment : COMMENT) { header.addComment(comment); } header.setSortOrder(this.SORT_ORDER); return header ; }
/** Creates a simple header with the values provided on the command line. */ public SAMFileHeader createSamFileHeader() { final SAMReadGroupRecord rgroup = new SAMReadGroupRecord(this.READ_GROUP_NAME); rgroup.setSample(this.SAMPLE_NAME); if (this.LIBRARY_NAME != null) rgroup.setLibrary(this.LIBRARY_NAME); if (this.PLATFORM != null) rgroup.setPlatform(this.PLATFORM); if (this.PLATFORM_UNIT != null) rgroup.setPlatformUnit(this.PLATFORM_UNIT); if (this.SEQUENCING_CENTER != null) rgroup.setSequencingCenter(SEQUENCING_CENTER); if (this.PREDICTED_INSERT_SIZE != null) rgroup.setPredictedMedianInsertSize(PREDICTED_INSERT_SIZE); if (this.DESCRIPTION != null) rgroup.setDescription(this.DESCRIPTION); if (this.RUN_DATE != null) rgroup.setRunDate(this.RUN_DATE); if (this.PLATFORM_MODEL != null) rgroup.setPlatformModel(this.PLATFORM_MODEL); if (this.PROGRAM_GROUP != null) rgroup.setProgramGroup(this.PROGRAM_GROUP); final SAMFileHeader header = new SAMFileHeader(); header.addReadGroup(rgroup); for (final String comment : COMMENT) { header.addComment(comment); } header.setSortOrder(this.SORT_ORDER); return header ; }
private static SAMFileHeader mergeHeaders(List<RecordSource> sources) { SAMFileHeader header = new SAMFileHeader(); for (RecordSource source : sources) { SAMFileHeader h = source.reader.getFileHeader(); for (SAMSequenceRecord seq : h.getSequenceDictionary().getSequences()) { if (header.getSequenceDictionary().getSequence(seq.getSequenceName()) == null) header.addSequence(seq); } for (SAMProgramRecord pro : h.getProgramRecords()) { if (header.getProgramRecord(pro.getProgramGroupId()) == null) header.addProgramRecord(pro); } for (String comment : h.getComments()) header.addComment(comment); for (SAMReadGroupRecord rg : h.getReadGroups()) { if (header.getReadGroup(rg.getReadGroupId()) == null) header.addReadGroup(rg); } } return header; }
protected static SAMRecordSetBuilder createTestSAMBuilder(final File reference, final String readGroupId, final String sample, final String platform, final String library) { final SAMFileHeader header = new SAMFileHeader(); // check that dictionary file is readable and then set header dictionary try { header.setSequenceDictionary(SAMSequenceDictionaryExtractor.extractDictionary(reference.toPath())); header.setSortOrder(SAMFileHeader.SortOrder.unsorted); } catch (final SAMException e) { e.printStackTrace(); } // set readGroupRecord final SAMReadGroupRecord readGroupRecord = new SAMReadGroupRecord(readGroupId); readGroupRecord.setSample(sample); readGroupRecord.setPlatform(platform); readGroupRecord.setLibrary(library); readGroupRecord.setPlatformUnit(readGroupId); header.addReadGroup(readGroupRecord); final SAMRecordSetBuilder setBuilder = new SAMRecordSetBuilder(true, SAMFileHeader.SortOrder.coordinate, true, 100); setBuilder.setReadGroup(readGroupRecord); setBuilder.setUseNmFlag(true); setBuilder.setHeader(header); return(setBuilder); }
private void testSingleRecord(byte[] bases, byte[] scores, byte[] ref) throws IOException { SAMFileHeader header = new SAMFileHeader(); header.addReadGroup(new SAMReadGroupRecord("1")); header.addSequence(new SAMSequenceRecord("chr1", ref.length)); SAMRecord s = new SAMRecord(header); s.setReadBases(bases); s.setBaseQualities(scores); s.setFlags(0); s.setAlignmentStart(1); s.setReferenceName("chr1"); s.setReadName("1"); if (bases == SAMRecord.NULL_SEQUENCE) { s.setCigarString("10M"); } else { s.setCigarString(s.getReadLength() + "M"); } testSingleRecord(s, ref); } }