private static Map<String, File> createOutputMap(final List<SAMReadGroupRecord> readGroups, final File outputDir, final String extension) { final Map<String, File> outputMap = new HashMap<>(); for (final SAMReadGroupRecord readGroup : readGroups) { final String id = readGroup.getId(); final String fileName = id + extension; final Path outputPath = Paths.get(outputDir.toString(), fileName); outputMap.put(id, outputPath.toFile()); } return outputMap; }
/** 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 boolean compareReadGroup(final SAMReadGroupRecord samReadGroupRecord1, final SAMReadGroupRecord samReadGroupRecord2) { boolean ret = compareValues(samReadGroupRecord1.getReadGroupId(), samReadGroupRecord2.getReadGroupId(), "Read Group ID"); ret = compareValues(samReadGroupRecord1.getSample(), samReadGroupRecord2.getSample(), "Sample for read group " + samReadGroupRecord1.getReadGroupId()) && ret; ret = compareValues(samReadGroupRecord1.getLibrary(), samReadGroupRecord2.getLibrary(), "Library for read group " + samReadGroupRecord1.getReadGroupId()) && ret; final String[] attributes = {"DS", "PU", "PI", "CN", "DT", "PL"}; for (final String attribute : attributes) { ret = compareValues(samReadGroupRecord1.getAttribute(attribute), samReadGroupRecord2.getAttribute(attribute), attribute + " for read group " + samReadGroupRecord1.getReadGroupId()) && ret; } return ret; }
public FingerprintIdDetails(final SAMReadGroupRecord rg, final String file) { this(rg.getPlatformUnit(), file); this.sample = rg.getSample(); this.library = rg.getLibrary(); }
private SAMReadGroupRecord createRG(String name) { SAMReadGroupRecord rg = new SAMReadGroupRecord(name); rg.setPlatform(rgPlatform.getDefaultPlatform()); rg.setSample(name); return rg; }
public SAMReadGroupRecord(final String id, final SAMReadGroupRecord srcProgramRecord) { mReadGroupId = id; for (final Map.Entry<String, String> entry : srcProgramRecord.getAttributes()) { setAttribute(entry.getKey(), entry.getValue()); } }
final SAMReadGroupRecord rg = new SAMReadGroupRecord(RGID); rg.setLibrary(RGLB); rg.setPlatform(RGPL); rg.setSample(RGSM); rg.setPlatformUnit(RGPU); if (RGCN != null) rg.setSequencingCenter(RGCN); if (RGDS != null) rg.setDescription(RGDS); if (RGDT != null) rg.setRunDate(RGDT); if (RGPI != null) rg.setPredictedMedianInsertSize(RGPI); if (RGPG != null) rg.setProgramGroup(RGPG); if (RGPM != null) rg.setPlatformModel(RGPM); if (RGKS != null) rg.setKeySequence(RGKS); if (RGFO != null) rg.setFlowOrder(RGFO); log.info(String.format("Created read-group ID=%s PL=%s LB=%s SM=%s%n", rg.getId(), rg.getPlatform(), rg.getLibrary(), rg.getSample()));
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; } }
public static String getTypeID( SAMReadGroupRecord r, DoCOutputType.Partition type ) { if ( type == DoCOutputType.Partition.sample ) { return r.getSample(); } else if ( type == DoCOutputType.Partition.readgroup ) { return String.format("%s_rg_%s",r.getSample(),r.getReadGroupId()); } else if ( type == DoCOutputType.Partition.library ) { return r.getLibrary(); } else if ( type == DoCOutputType.Partition.center ) { return r.getSequencingCenter(); } else if ( type == DoCOutputType.Partition.platform ) { return r.getPlatform(); } else if ( type == DoCOutputType.Partition.sample_by_center ) { return String.format("%s_cn_%s",r.getSample(),r.getSequencingCenter()); } else if ( type == DoCOutputType.Partition.sample_by_platform) { return String.format("%s_pl_%s",r.getSample(),r.getPlatform()); } else if ( type == DoCOutputType.Partition.sample_by_platform_by_center ) { return String.format("%s_pl_%s_cn_%s",r.getSample(),r.getPlatform(),r.getSequencingCenter()); } else { throw new ReviewedGATKException("Invalid type ID sent to getTypeID. This is a BUG!"); } }
private void validateReadGroup(final SAMRecord record, final SAMFileHeader header) { final SAMReadGroupRecord rg = record.getReadGroup(); if (rg == null) { addError(new SAMValidationError(Type.RECORD_MISSING_READ_GROUP, "A record is missing a read group", record.getReadName())); } else if (header.getReadGroup(rg.getId()) == null) { addError(new SAMValidationError(Type.READ_GROUP_NOT_FOUND, "A record has a read group not found in the header: ", record.getReadName() + ", " + rg.getReadGroupId())); } }
final String rgID = rg.getId(); table.addRowID(rgID, true); PerReadGroupInfo info = readGroupInfo.get(rgID); final int readLength = info.readLength.getMedian(0); setTableValue(table, rgID, "sample", rg.getSample()); setTableValue(table, rgID, "library", rg.getLibrary()); setTableValue(table, rgID, "platform", rg.getPlatform()); setTableValue(table, rgID, "center", rg.getSequencingCenter()); try { setTableValue(table, rgID, "date", rg.getRunDate() != null ? dateFormatter.format(rg.getRunDate()) : "NA"); } catch ( NullPointerException e ) {
@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()); }
@Test public void testReadGroupIdGetters() throws Exception { final SAMReadGroupRecord rg = new SAMReadGroupRecord("rg1"); Assert.assertEquals(rg.getId(), "rg1"); Assert.assertEquals(rg.getReadGroupId(), "rg1"); }
@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}, }; }
/** * Determines the list of read groups that meet the user's criteria for inclusion (based on id, platform, or sample) * @param header the merged header for all input files * @param samplesToKeep the list of specific samples specified by the user * @return a Set of read group IDs that meet the user's criteria, empty if all RGs should be included */ private Set<String> determineReadGroupsOfInterest(final SAMFileHeader header, final Set<String> samplesToKeep) { //If no filter options that use read group information have been supplied, exit early if (platform == null && readGroup == null && samplesToKeep.isEmpty()) return Collections.emptySet(); if ( platform != null ) platform = platform.toUpperCase(); final Set<String> result = new HashSet<>(); for (final SAMReadGroupRecord rg : header.getReadGroups()) { // To be eligible for output, a read group must: // NOT have an id that is blacklisted on the command line (note that String.equals(null) is false) // AND NOT have a platform that contains the blacklisted platform from the command line // AND have a sample that is whitelisted on the command line if (!rg.getReadGroupId().equals(readGroup) && (platform == null || !rg.getPlatform().toUpperCase().contains(platform)) && (samplesToKeep.isEmpty() || samplesToKeep.contains(rg.getSample()))) result.add(rg.getReadGroupId()); } if (result.isEmpty()) throw new UserException.BadArgumentValue("-sn/-sf/-platform/-readGroup", "No read groups remain after pruning based on the supplied parameters"); return result; }
@Test(expectedExceptions = {PicardException.class}) public void testAssertAllReadGroupsMappedFailure() { final SAMReadGroupRecord rg1 = new SAMReadGroupRecord("rg1"); final SAMReadGroupRecord rg2 = new SAMReadGroupRecord("rg2"); final SAMReadGroupRecord rg3 = new SAMReadGroupRecord("rg3"); final Map<String, File> outputMap = new HashMap<String, File>(); outputMap.put("rg1", new File("/foo/bar/rg1.bam")); outputMap.put("rg2", new File("/foo/bar/rg2.bam")); RevertSam.ValidationUtil.assertAllReadGroupsMapped(outputMap, Arrays.asList(rg1, rg2, rg3)); }
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); }
public void addReadGroup(final SAMReadGroupRecord readGroup) { if (mReadGroupMap.containsKey(readGroup.getReadGroupId())) { throw new IllegalArgumentException("Read group with group id " + readGroup.getReadGroupId() + " already exists in SAMFileHeader!"); } mReadGroups.add(readGroup); mReadGroupMap.put(readGroup.getReadGroupId(), readGroup); }
/** * 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; }
@Override AbstractSAMHeaderRecord newGroup(String id) { SAMReadGroupRecord group = new SAMReadGroupRecord(id); group.setAttribute(SAMTag.SM.name(), id); return group; }