diff --git a/java/src/org/broadinstitute/sting/utils/SampleUtils.java b/java/src/org/broadinstitute/sting/utils/SampleUtils.java new file mode 100755 index 000000000..8f68f209b --- /dev/null +++ b/java/src/org/broadinstitute/sting/utils/SampleUtils.java @@ -0,0 +1,54 @@ +package org.broadinstitute.sting.utils; + +import net.sf.samtools.SAMReadGroupRecord; +import net.sf.samtools.SAMFileHeader; + +import java.util.*; + +import org.broadinstitute.sting.utils.genotype.Genotype; +import org.broadinstitute.sting.utils.genotype.SampleBacked; + + +/** + * SampleUtils is a static class (no instantiation allowed!) with some utility methods for getting samples + * quality scores. + * + * @author ebanks + */ +public class SampleUtils { + /** + * Private constructor. No instantiating this class! + */ + private SampleUtils() {} + + /** + * Pull out the samples from a SAMFileHeader; + * note that we use a TreeSet so that they are sorted + * + * @param header the sam file header + * @return list of strings representing the sample names + */ + public static Set getSAMFileSamples(SAMFileHeader header) { + // get all of the unique sample names + Set samples = new TreeSet(); + List readGroups = header.getReadGroups(); + for ( SAMReadGroupRecord readGroup : readGroups ) + samples.add(readGroup.getSample()); + return samples; + } + + /** + * get the samples names from genotype objects if they are backed by samples + * + * @param genotypes the genotype list + * @return list of strings representing the sample names + */ + public static List getGenotypeSamples(List genotypes) { + List samples = new ArrayList(); + for ( Genotype genotype : genotypes ) { + if ( genotype instanceof SampleBacked ) + samples.add(((SampleBacked)genotype).getSampleName()); + } + return samples; + } +} \ No newline at end of file