@Override public void setSample(String s) { super.setSample(s); mSample = s; retrievedSample = true; }
private void overwriteSample(final List<SAMReadGroupRecord> readGroups, final String sampleAlias) { readGroups.forEach(rg -> rg.setSample(sampleAlias)); }
private void overwriteSample(final List<SAMReadGroupRecord> readGroups, final String sampleAlias) { readGroups.forEach(rg -> rg.setSample(sampleAlias)); }
/** * setup a default read group for a SAMFileHeader * * @param header the header to set * @param readGroupID the read group ID tag * @param sampleName the sample name * @return the adjusted SAMFileHeader */ public static SAMFileHeader createDefaultReadGroup(SAMFileHeader header, String readGroupID, String sampleName) { SAMReadGroupRecord rec = new SAMReadGroupRecord(readGroupID); rec.setSample(sampleName); List<SAMReadGroupRecord> readGroups = new ArrayList<SAMReadGroupRecord>(); readGroups.add(rec); header.setReadGroups(readGroups); return header; }
/** * setup read groups for the specified read groups and sample names * * @param header the header to set * @param readGroupIDs the read group ID tags * @param sampleNames the sample names * @return the adjusted SAMFileHeader */ public static SAMFileHeader createEnumeratedReadGroups(SAMFileHeader header, List<String> readGroupIDs, List<String> sampleNames) { if (readGroupIDs.size() != sampleNames.size()) { throw new ReviewedGATKException("read group count and sample name count must be the same"); } List<SAMReadGroupRecord> readGroups = new ArrayList<SAMReadGroupRecord>(); int x = 0; for (; x < readGroupIDs.size(); x++) { SAMReadGroupRecord rec = new SAMReadGroupRecord(readGroupIDs.get(x)); rec.setSample(sampleNames.get(x)); readGroups.add(rec); } header.setReadGroups(readGroups); return header; }
private SAMReadGroupRecord createRG(String name) { SAMReadGroupRecord rg = new SAMReadGroupRecord(name); rg.setPlatform(rgPlatform.getDefaultPlatform()); rg.setSample(name); return rg; }
private FingerprintIdDetails createUnknownFP(final Path samFile, final SAMRecord rec) { final PicardException e = new PicardException("Found read with no readgroup: " + rec.getReadName() + " in file: " + samFile); if (validationStringency != ValidationStringency.STRICT) { final SAMReadGroupRecord readGroupRecord = new SAMReadGroupRecord("<UNKNOWN>:::" + samFile.toUri().toString()); readGroupRecord.setLibrary("<UNKNOWN>"); readGroupRecord.setSample("<UNKNOWN>"); readGroupRecord.setPlatformUnit("<UNKNOWN>.0.ZZZ"); if (validationStringency == ValidationStringency.LENIENT) { log.warn(e); log.warn("further messages from this file will be suppressed"); } return new FingerprintIdDetails(readGroupRecord, samFile.toUri().toString()); } else { log.error(e); throw e; } }
private FingerprintIdDetails createUnknownFP(final Path samFile, final SAMRecord rec) { final PicardException e = new PicardException("Found read with no readgroup: " + rec.getReadName() + " in file: " + samFile); if (validationStringency != ValidationStringency.STRICT) { final SAMReadGroupRecord readGroupRecord = new SAMReadGroupRecord("<UNKNOWN>:::" + samFile.toUri().toString()); readGroupRecord.setLibrary("<UNKNOWN>"); readGroupRecord.setSample("<UNKNOWN>"); readGroupRecord.setPlatformUnit("<UNKNOWN>.0.ZZZ"); if (validationStringency == ValidationStringency.LENIENT) { log.warn(e); log.warn("further messages from this file will be suppressed"); } return new FingerprintIdDetails(readGroupRecord, samFile.toUri().toString()); } else { log.error(e); throw e; } }
protected ReadDestination(final SAMFileHeader header, final String readGroupID) { // prepare the bam header if ( header == null ) throw new IllegalArgumentException("header cannot be null"); bamHeader = new SAMFileHeader(); bamHeader.setSequenceDictionary(header.getSequenceDictionary()); bamHeader.setSortOrder(SAMFileHeader.SortOrder.coordinate); bamHeader.setProgramRecords(header.getProgramRecords()); // include the original read groups plus an artificial one for haplotypes final List<SAMReadGroupRecord> readGroups = new ArrayList<>(header.getReadGroups()); SAMReadGroupRecord rg = new SAMReadGroupRecord(readGroupID); rg.setSample("HC"); rg.setSequencingCenter("BI"); readGroups.add(rg); bamHeader.setReadGroups(readGroups); }
@Test public void testGetSAMString() { SAMReadGroupRecord r = new SAMReadGroupRecord("rg1"); r.setSample("mysample"); r.setPlatform("ILLUMINA"); r.setDescription("my description"); Assert.assertEquals("@RG\tID:rg1\tSM:mysample\tPL:ILLUMINA\tDS:my description", r.getSAMString()); }
/** * Build a SamFileWriter that will write its contents to the output file. * * @param output The file to which to write * @param sampleAlias The sample alias set in the read group header * @param libraryName The name of the library to which this read group belongs * @param headerParameters Header parameters that will be added to the RG header for this SamFile * @return A SAMFileWriter */ private SAMFileWriterWrapper buildSamFileWriter(final File output, final String sampleAlias, final String libraryName, final Map<String, String> headerParameters, final boolean presorted) { IOUtil.assertFileIsWritable(output); final SAMReadGroupRecord rg = new SAMReadGroupRecord(READ_GROUP_ID); rg.setSample(sampleAlias); if (libraryName != null) rg.setLibrary(libraryName); for (final Map.Entry<String, String> tagNameToValue : headerParameters.entrySet()) { if (tagNameToValue.getValue() != null) { rg.setAttribute(tagNameToValue.getKey(), tagNameToValue.getValue()); } } final SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(SAMFileHeader.SortOrder.queryname); header.addReadGroup(rg); return new SAMFileWriterWrapper(new SAMFileWriterFactory().makeSAMOrBAMWriter(header, presorted, output)); }
/** * Build a SamFileWriter that will write its contents to the output file. * * @param output The file to which to write * @param sampleAlias The sample alias set in the read group header * @param libraryName The name of the library to which this read group belongs * @param headerParameters Header parameters that will be added to the RG header for this SamFile * @return A SAMFileWriter */ private SAMFileWriterWrapper buildSamFileWriter(final File output, final String sampleAlias, final String libraryName, final Map<String, String> headerParameters, final boolean presorted) { IOUtil.assertFileIsWritable(output); final SAMReadGroupRecord rg = new SAMReadGroupRecord(READ_GROUP_ID); rg.setSample(sampleAlias); if (libraryName != null) rg.setLibrary(libraryName); for (final Map.Entry<String, String> tagNameToValue : headerParameters.entrySet()) { if (tagNameToValue.getValue() != null) { rg.setAttribute(tagNameToValue.getKey(), tagNameToValue.getValue()); } } final SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(SAMFileHeader.SortOrder.queryname); header.addReadGroup(rg); return new SAMFileWriterWrapper(new SAMFileWriterFactory().makeSAMOrBAMWriter(header, presorted, output)); }
@DataProvider public Object[][] readGroupsForEquals() { final SAMReadGroupRecord empty = new SAMReadGroupRecord("empty"); final SAMReadGroupRecord withSample = new SAMReadGroupRecord("rg1"); withSample.setSample("sample1"); return new Object[][] { // same object {empty, empty, true}, {withSample, withSample, true}, // null or different class {empty, null, false}, {empty, empty.getId(), false}, // different information set {empty, withSample, false}, {withSample, empty, false}, }; }
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; }
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); } }
public void setupTest1(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 = ":"; final int contig1 = 0; final int contig2 = 1; 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 = 800; final int min = 1; final Random rg = new Random(5); //add records that align to chrM and O but not N for (int i = 0; i < NUM_READS; i++) { final int start = rg.nextInt(max) + min; final String newReadName = READ_NAME + separator + ID + separator + i; if (i != NUM_READS - 1) { setBuilder.addPair(newReadName, contig1, start + ID, start + ID + LENGTH); } else { setBuilder.addPair(newReadName, contig2, start + ID, start + ID + LENGTH); } } }
/** 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 ; }
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); }