Java Code Examples for htsjdk.samtools.SAMReadGroupRecord#getLibrary()

The following examples show how to use htsjdk.samtools.SAMReadGroupRecord#getLibrary() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoverageUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Method takes a ReadGroup record and a partition type and returns the appropriate summary string for displaying in output tables.
 * Since each partition type has its own pattern for separating out readgroups this method is intended to handle all of the
 * processing for regroups so that outputs can be properly partitioned in all cases.
 *
 * @param rg readGroupRecord to be processed.
 * @param type partition type to generate read group string for.
 */
public static String getTypeID(final SAMReadGroupRecord rg, final DoCOutputType.Partition type ) {
    switch (type) {
        case sample:
            return rg.getSample();
        case readgroup:
            return rg.getSample()+"_rg_"+rg.getReadGroupId();
        case library:
            return rg.getLibrary();
        case center:
            return rg.getSequencingCenter();
        case platform:
            return rg.getPlatform();
        case sample_by_center:
            return rg.getSample()+"_cn_"+rg.getSequencingCenter();
        case sample_by_platform:
            return rg.getSample()+"_pl_"+rg.getPlatform();
        case sample_by_platform_by_center:
            return rg.getSample()+"_pl_"+rg.getPlatform()+"_cn_"+rg.getSequencingCenter();
        default:
            throw new GATKException(String.format("Invalid aggregation type %s", type));
    }
}
 
Example 2
Source File: LibraryIdGenerator.java    From picard with MIT License 5 votes vote down vote up
/**
 * Gets the library name from the header for the record. If the RG tag is not present on
 * the record, or the library isn't denoted on the read group, a constant string is
 * returned.
 */
public static String getLibraryName(final SAMFileHeader header, final SAMRecord rec) {
    final String readGroupId = (String) rec.getAttribute(ReservedTagConstants.READ_GROUP_ID);

    if (readGroupId != null) {
        final SAMReadGroupRecord rg = header.getReadGroup(readGroupId);
        if (rg != null) {
            final String libraryName = rg.getLibrary();
            if (null != libraryName) return libraryName;
        }
    }

    return UNKNOWN_LIBRARY;
}
 
Example 3
Source File: LibraryIdGenerator.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Gets the library name from the header for the read group id. If the read group id is null
 * or the library isn't denoted on the read group, a constant string is
 * returned.
 */
public static String getLibraryName(final SAMFileHeader header, String readGroupId) {
  if (readGroupId != null) {
        final SAMReadGroupRecord rg = header.getReadGroup(readGroupId);
        if (rg != null) {
            final String libraryName = rg.getLibrary();
            if (null != libraryName) return libraryName;
        }
    }

    return UNKNOWN_LIBRARY;
}
 
Example 4
Source File: MarkDuplicatesSparkUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the library associated with the provided read's read group.
 * Or the specified default if no library is found
 *
 * @param read read whose library to retrieve
 * @param header SAM header containing read groups
 * @return the library for the provided read's read group as a String,
 *         or the default value if the read has no read group.
 */
public static String getLibraryForRead(final GATKRead read, final SAMFileHeader header, String defaultLibrary) {
    final SAMReadGroupRecord readGroup = ReadUtils.getSAMReadGroupRecord(read, header);
    if (readGroup != null) {
        String library = readGroup.getLibrary();
        return library==null? defaultLibrary : library;
    } else {
        if (read.getReadGroup() == null) {
            throw new UserException.ReadMissingReadGroup(read);
        } else {
            throw new UserException.HeaderMissingReadGroup(read);
        }
    }
}
 
Example 5
Source File: FingerprintIdDetails.java    From picard with MIT License 4 votes vote down vote up
public FingerprintIdDetails(final SAMReadGroupRecord rg, final String file) {
    this(rg.getPlatformUnit(), file);
    this.sample = rg.getSample();
    this.library = rg.getLibrary();
}
 
Example 6
Source File: MultiLevelCollector.java    From picard with MIT License 4 votes vote down vote up
@Override
protected String getKey(SAMReadGroupRecord rg) {
    return rg.getLibrary();
}
 
Example 7
Source File: MultiLevelCollector.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected String getKey(SAMReadGroupRecord rg) {
    return rg.getLibrary();
}
 
Example 8
Source File: MultiLevelReducibleCollector.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected String getKey(SAMReadGroupRecord rg) {
    return rg.getLibrary();
}
 
Example 9
Source File: CoverageUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Takes an AlignmentContext object and extracts all the reads that pass the provided filters, and then returns a
 * count breakdown for each base (plus D and N bases) present at the site.
 *
 * NOTE: this currently doesn't support counts by fragments as was the case in gatk3
 */
private static Map<SAMReadGroupRecord,int[]> getBaseCountsByReadGroup(final AlignmentContext context, final byte minBaseQ, final byte maxBaseQ, final CountPileupType countType, final SAMFileHeader header) {
    Map<SAMReadGroupRecord, int[]> countsByRG = new HashMap<>();

    Map<String, int[]> countsByRGName = new HashMap<>();
    Map<String, SAMReadGroupRecord> RGByName = new HashMap<>();

    List<PileupElement> countPileup = new ArrayList<>(context.getBasePileup().size());

    switch (countType) {

        case COUNT_READS:
            for (PileupElement read : context.getBasePileup()) {
                if (elementWithinQualRange(read, minBaseQ, maxBaseQ)) {
                    countPileup.add(read);
                }
            }
            break;

        // TODO see reconcile FragmentUtils.create() and its various idiosyncrasies to re-enable this feature see https://github.com/broadinstitute/gatk/issues/6491
        case COUNT_FRAGMENTS: // ignore base identities and put in FIRST base that passes filters:
            throw new UnsupportedOperationException("Fragment based counting is currently unsupported");

        case COUNT_FRAGMENTS_REQUIRE_SAME_BASE:
            throw new UnsupportedOperationException("Fragment based counting is currently unsupported");

        default:
            throw new UserException("Must use valid CountPileupType");
    }

    for (PileupElement e : countPileup) {
        SAMReadGroupRecord readGroup = ReadUtils.getSAMReadGroupRecord(e.getRead(), header);
        Utils.nonNull(readGroup, String.format("Read %s was missing read group information", e.getRead()));

        // uniqueReadGroupID is unique across the library, read group ID, and the sample
        String uniqueReadGroupId = readGroup.getSample() + "_" + readGroup.getReadGroupId() + "_" + readGroup.getLibrary() + "_" + readGroup.getPlatformUnit();
        int[] counts = countsByRGName.get(uniqueReadGroupId);
        if (counts == null) {
            counts = new int[6];
            countsByRGName.put(uniqueReadGroupId, counts);
            RGByName.put(uniqueReadGroupId, readGroup);
        }

        updateCounts(counts, e);
    }

    for (String readGroupId : RGByName.keySet()) {
        countsByRG.put(RGByName.get(readGroupId), countsByRGName.get(readGroupId));
    }

    return countsByRG;
}