Further cleanup of Sample
-- Cleaned up interface functions in GAE -- Added Walker.getSampleDB() function which is an easier option for tools to get the samples db
This commit is contained in:
parent
e76f381628
commit
2a0cd556d3
|
|
@ -1034,123 +1034,16 @@ public class GenomeAnalysisEngine {
|
|||
return readsDataSource == null ? null : readsDataSource.getCumulativeReadMetrics();
|
||||
}
|
||||
|
||||
public SampleDataSource getSampleMetadata() {
|
||||
// -------------------------------------------------------------------------------------
|
||||
//
|
||||
// code for working with Samples database
|
||||
//
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
public SampleDataSource getSampleDB() {
|
||||
return this.sampleDataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sample by its ID
|
||||
* If an alias is passed in, return the main sample object
|
||||
* @param id sample id
|
||||
* @return sample Object with this ID
|
||||
*/
|
||||
public Sample getSampleById(String id) {
|
||||
return sampleDataSource.getSampleById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sample for a given read group
|
||||
* Must first look up ID for read group
|
||||
* @param readGroup of sample
|
||||
* @return sample object with ID from the read group
|
||||
*/
|
||||
public Sample getSampleByReadGroup(SAMReadGroupRecord readGroup) {
|
||||
return sampleDataSource.getSampleByReadGroup(readGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sample for a given read
|
||||
* Must first look up read group, and then sample ID for that read group
|
||||
* @param read of sample
|
||||
* @return sample object of this read
|
||||
*/
|
||||
public Sample getSampleByRead(SAMRecord read) {
|
||||
return getSampleByReadGroup(read.getReadGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of sample objects
|
||||
* @return size of samples map
|
||||
*/
|
||||
public int sampleCount() {
|
||||
return sampleDataSource.sampleCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all samples with a given family ID
|
||||
* Note that this isn't terribly efficient (linear) - it may be worth adding a new family ID data structure for this
|
||||
* @param familyId family ID
|
||||
* @return Samples with the given family ID
|
||||
*/
|
||||
public Set<Sample> getFamily(String familyId) {
|
||||
return sampleDataSource.getFamily(familyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all children of a given sample
|
||||
* See note on the efficiency of getFamily() - since this depends on getFamily() it's also not efficient
|
||||
* @param sample parent sample
|
||||
* @return children of the given sample
|
||||
*/
|
||||
public Set<Sample> getChildren(Sample sample) {
|
||||
return sampleDataSource.getChildren(sample);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the samples
|
||||
* @return
|
||||
*/
|
||||
public Collection<Sample> getSamples() {
|
||||
return sampleDataSource.getSamples();
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a list of sample names and returns their corresponding sample objects
|
||||
*
|
||||
* @param sampleNameList List of sample names
|
||||
* @return Corresponding set of samples
|
||||
*/
|
||||
public Set<Sample> getSamples(Collection<String> sampleNameList) {
|
||||
return sampleDataSource.getSamples(sampleNameList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a set of samples that have any value (which could be null) for a given property
|
||||
* @param key Property key
|
||||
* @return Set of samples with the property
|
||||
*/
|
||||
public Set<Sample> getSamplesWithProperty(String key) {
|
||||
return sampleDataSource.getSamplesWithProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of samples that have a property with a certain value
|
||||
* Value must be a string for now - could add a similar method for matching any objects in the future
|
||||
*
|
||||
* @param key Property key
|
||||
* @param value String property value
|
||||
* @return Set of samples that match key and value
|
||||
*/
|
||||
public Set<Sample> getSamplesWithProperty(String key, String value) {
|
||||
return sampleDataSource.getSamplesWithProperty(key, value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of sample objects for the sample names in a variant context
|
||||
*
|
||||
* @param context Any variant context
|
||||
* @return a set of the sample objects
|
||||
*/
|
||||
public Set<Sample> getSamplesByVariantContext(VariantContext context) {
|
||||
Set<Sample> samples = new HashSet<Sample>();
|
||||
for (String sampleName : context.getSampleNames()) {
|
||||
samples.add(sampleDataSource.getOrCreateSample(sampleName));
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all samples that were referenced in the SAM file
|
||||
*/
|
||||
|
|
@ -1158,18 +1051,6 @@ public class GenomeAnalysisEngine {
|
|||
return sampleDataSource.getSAMFileSamples();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a subcontext restricted to samples with a given property key/value
|
||||
* Gets the sample names from key/value and relies on VariantContext.subContextFromGenotypes for the filtering
|
||||
* @param context VariantContext to filter
|
||||
* @param key property key
|
||||
* @param value property value (must be string)
|
||||
* @return subcontext
|
||||
*/
|
||||
public VariantContext subContextFromSampleProperty(VariantContext context, String key, String value) {
|
||||
return sampleDataSource.subContextFromSampleProperty(context, key, value);
|
||||
}
|
||||
|
||||
public Map<String,String> getApproximateCommandLineArguments(Object... argumentProviders) {
|
||||
return CommandLineUtils.getApproximateCommandLineArguments(parsingEngine,argumentProviders);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
package org.broadinstitute.sting.gatk.contexts;
|
||||
|
||||
import net.sf.samtools.SAMReadGroupRecord;
|
||||
import org.broadinstitute.sting.gatk.samples.Sample;
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
|
||||
import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||
|
|
@ -76,14 +75,6 @@ public class AlignmentContextUtils {
|
|||
return splitContextBySampleName(context, null);
|
||||
}
|
||||
|
||||
public static Map<Sample, AlignmentContext> splitContextBySample(AlignmentContext context) {
|
||||
Map<Sample, AlignmentContext> m = new HashMap<Sample, AlignmentContext>();
|
||||
for ( Map.Entry<String, AlignmentContext> entry : splitContextBySampleName(context, null).entrySet() ) {
|
||||
m.put(new Sample(entry.getKey()), entry.getValue());
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the given AlignmentContext into a StratifiedAlignmentContext per sample, but referencd by sample name instead
|
||||
* of sample object.
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class LinearMicroScheduler extends MicroScheduler {
|
|||
traversalEngine.startTimersIfNecessary();
|
||||
if(shard.getShardType() == Shard.ShardType.LOCUS) {
|
||||
LocusWalker lWalker = (LocusWalker)walker;
|
||||
WindowMaker windowMaker = new WindowMaker(shard, engine.getGenomeLocParser(), getReadIterator(shard), shard.getGenomeLocs(), engine.getSampleMetadata());
|
||||
WindowMaker windowMaker = new WindowMaker(shard, engine.getGenomeLocParser(), getReadIterator(shard), shard.getGenomeLocs(), engine.getSampleDB());
|
||||
for(WindowMaker.WindowMakerIterator iterator: windowMaker) {
|
||||
ShardDataProvider dataProvider = new LocusShardDataProvider(shard,iterator.getSourceInfo(),engine.getGenomeLocParser(),iterator.getLocus(),iterator,reference,rods);
|
||||
Object result = traversalEngine.traverse(walker, dataProvider, accumulator.getReduceInit());
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class ShardTraverser implements Callable {
|
|||
|
||||
Object accumulator = walker.reduceInit();
|
||||
LocusWalker lWalker = (LocusWalker)walker;
|
||||
WindowMaker windowMaker = new WindowMaker(shard,microScheduler.getEngine().getGenomeLocParser(),microScheduler.getReadIterator(shard),shard.getGenomeLocs(), microScheduler.engine.getSampleMetadata()); // todo: microScheduler.engine is protected - is it okay to user it here?
|
||||
WindowMaker windowMaker = new WindowMaker(shard,microScheduler.getEngine().getGenomeLocParser(),microScheduler.getReadIterator(shard),shard.getGenomeLocs(), microScheduler.engine.getSampleDB()); // todo: microScheduler.engine is protected - is it okay to user it here?
|
||||
ShardDataProvider dataProvider = null;
|
||||
|
||||
for(WindowMaker.WindowMakerIterator iterator: windowMaker) {
|
||||
|
|
|
|||
|
|
@ -542,7 +542,7 @@ public class LocusIteratorByState extends LocusIterator {
|
|||
Map<String,ReadSelector> readSelectors = new HashMap<String,ReadSelector>();
|
||||
for(Sample sample: samples) {
|
||||
readStatesBySample.put(sample,new PerSampleReadStateManager());
|
||||
readSelectors.put(sample.getId(),downsamplingMethod.type == DownsampleType.BY_SAMPLE ? new NRandomReadSelector(null,targetCoverage) : new AllReadsSelector());
|
||||
readSelectors.put(sample.getID(),downsamplingMethod.type == DownsampleType.BY_SAMPLE ? new NRandomReadSelector(null,targetCoverage) : new AllReadsSelector());
|
||||
}
|
||||
|
||||
samplePartitioner = new SamplePartitioner(readSelectors);
|
||||
|
|
@ -640,7 +640,7 @@ public class LocusIteratorByState extends LocusIterator {
|
|||
samplePartitioner.complete();
|
||||
|
||||
for(Sample sample: samples) {
|
||||
ReadSelector aggregator = samplePartitioner.getSelectedReads(sample.getId());
|
||||
ReadSelector aggregator = samplePartitioner.getSelectedReads(sample.getID());
|
||||
|
||||
Collection<SAMRecord> newReads = new ArrayList<SAMRecord>(aggregator.getSelectedReads());
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package org.broadinstitute.sting.gatk.samples;
|
|||
|
||||
import org.broadinstitute.sting.utils.exceptions.StingException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -13,23 +14,16 @@ import java.util.Map;
|
|||
* Time: 3:31:38 PM
|
||||
*/
|
||||
public class Sample implements java.io.Serializable {
|
||||
private final static String MOTHER = "mother";
|
||||
private final static String FATHER = "father";
|
||||
private final static String GENDER = "gender";
|
||||
private final static String POPULATION = "population";
|
||||
private final static String FAMILY = "familyId";
|
||||
private final static String AFFECTION = "affection";
|
||||
private final static String QUANT_TRAIT = "quantTrait";
|
||||
|
||||
private final String id;
|
||||
|
||||
private boolean hasSampleFileEntry = false; // true if this sample has an entry in a sample file
|
||||
final private String familyID, paternalID, maternalID;
|
||||
final private Sample.Gender gender;
|
||||
final private double quantitativePhenotype;
|
||||
final private Sample.Affection affection;
|
||||
final private String population;
|
||||
final private String ID;
|
||||
final private SampleDataSource dataSource;
|
||||
|
||||
private boolean hasSAMFileEntry = false; // true if this sample has an entry in the SAM file
|
||||
|
||||
private HashMap<String, Object> properties = new HashMap<String, Object>();
|
||||
|
||||
private HashMap<String, Sample> relationships = new HashMap<String, Sample>();
|
||||
private Map<String, Object> properties = new HashMap<String, Object>();
|
||||
|
||||
public enum Gender {
|
||||
MALE,
|
||||
|
|
@ -47,26 +41,28 @@ public class Sample implements java.io.Serializable {
|
|||
/** A quantitative trait: value of the trait is stored elsewhere */
|
||||
QUANTITATIVE
|
||||
}
|
||||
|
||||
public final static double UNSET_QUANTITIATIVE_TRAIT_VALUE = Double.NaN;
|
||||
|
||||
public Sample(String id) {
|
||||
/* if (id == null) {
|
||||
throw new StingException("Error creating sample: sample ID cannot be null");
|
||||
}*/
|
||||
this.id = id;
|
||||
public Sample(final String ID, final SampleDataSource dataSource,
|
||||
final String familyID, final String paternalID, final String maternalID,
|
||||
final Gender gender, final double quantitativePhenotype, final Affection affection,
|
||||
final String population) {
|
||||
this.familyID = familyID;
|
||||
this.paternalID = paternalID;
|
||||
this.maternalID = maternalID;
|
||||
this.gender = gender;
|
||||
this.quantitativePhenotype = quantitativePhenotype;
|
||||
this.affection = affection;
|
||||
this.population = population;
|
||||
this.ID = ID;
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Map<String, Object> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setSampleFileEntry(boolean value) {
|
||||
this.hasSampleFileEntry = value;
|
||||
public Sample(String id, SampleDataSource dataSource) {
|
||||
this(id, dataSource,
|
||||
null, null, null,
|
||||
Gender.UNKNOWN, UNSET_QUANTITIATIVE_TRAIT_VALUE, Affection.UNKNOWN, null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
|
@ -79,58 +75,39 @@ public class Sample implements java.io.Serializable {
|
|||
this.hasSAMFileEntry = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one property
|
||||
* @param key key of property
|
||||
* @return value of property as generic object
|
||||
*/
|
||||
public Object getProperty(String key) {
|
||||
return properties.get(key);
|
||||
// -------------------------------------------------------------------------------------
|
||||
//
|
||||
// standard property getters
|
||||
//
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
public String getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property
|
||||
* If property already exists, it is overwritten
|
||||
* @param key key of property
|
||||
* @param value object to be stored in properties array
|
||||
*/
|
||||
public void setProperty(String key, Object value) {
|
||||
|
||||
if (relationships.containsKey(key)) {
|
||||
throw new StingException("The same key cannot exist as a property and a relationship");
|
||||
}
|
||||
|
||||
if (key.equals(GENDER) && value.getClass() != Gender.class) {
|
||||
throw new StingException("'gender' property must be of type Sample.Gender");
|
||||
}
|
||||
|
||||
if (key.equals(POPULATION) && value.getClass() != String.class) {
|
||||
throw new StingException("'population' property must be of type String");
|
||||
}
|
||||
|
||||
properties.put(key, value);
|
||||
public String getFamilyID() {
|
||||
return familyID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one relationship
|
||||
* @param key of relationship
|
||||
* @return Sample object that this relationship points to
|
||||
*/
|
||||
public Sample getRelationship(String key) {
|
||||
return relationships.get(key);
|
||||
public String getPaternalID() {
|
||||
return paternalID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set one relationship
|
||||
* If already set, it is overwritten
|
||||
* @param key key of the relationship
|
||||
* @param value Sample object this relationship points to
|
||||
*/
|
||||
public void setRelationship(String key, Sample value) {
|
||||
if (properties.containsKey(key)) {
|
||||
throw new StingException("The same key cannot exist as a property and a relationship");
|
||||
}
|
||||
relationships.put(key, value);
|
||||
public String getMaternalID() {
|
||||
return maternalID;
|
||||
}
|
||||
|
||||
public Affection getAffection() {
|
||||
return affection;
|
||||
}
|
||||
|
||||
public boolean hasQuantitativeTrait() {
|
||||
return affection == Affection.QUANTITATIVE;
|
||||
}
|
||||
|
||||
public double getQuantitativePhenotype() {
|
||||
return quantitativePhenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -138,7 +115,7 @@ public class Sample implements java.io.Serializable {
|
|||
* @return sample object with relationship mother, if exists, or null
|
||||
*/
|
||||
public Sample getMother() {
|
||||
return getRelationship(MOTHER);
|
||||
return dataSource.getSampleById(maternalID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -146,7 +123,7 @@ public class Sample implements java.io.Serializable {
|
|||
* @return sample object with relationship father, if exists, or null
|
||||
*/
|
||||
public Sample getFather() {
|
||||
return getRelationship(FATHER);
|
||||
return dataSource.getSampleById(paternalID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -154,29 +131,48 @@ public class Sample implements java.io.Serializable {
|
|||
* @return property of key "gender" - must be of type Gender
|
||||
*/
|
||||
public Gender getGender() {
|
||||
return (Gender) properties.get(GENDER);
|
||||
return gender;
|
||||
}
|
||||
|
||||
public String getPopulation() {
|
||||
return (String) properties.get(POPULATION);
|
||||
return population;
|
||||
}
|
||||
|
||||
public String getFamilyId() {
|
||||
return (String) properties.get(FAMILY);
|
||||
return familyID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if sample is male, false if female, unknown, or null
|
||||
*/
|
||||
public boolean isMale() {
|
||||
return properties.get(GENDER) == Gender.MALE;
|
||||
return getGender() == Gender.MALE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if sample is female, false if male, unknown or null
|
||||
*/
|
||||
public boolean isFemale() {
|
||||
return properties.get(GENDER) == Gender.MALE;
|
||||
return getGender() == Gender.MALE;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//
|
||||
// code for working with additional -- none standard -- properites
|
||||
//
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
public Map<String, Object> getExtraProperties() {
|
||||
return Collections.unmodifiableMap(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one property
|
||||
* @param key key of property
|
||||
* @return value of property as generic object
|
||||
*/
|
||||
public Object getExtraPropertyValue(final String key) {
|
||||
return properties.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -184,7 +180,7 @@ public class Sample implements java.io.Serializable {
|
|||
* @param key property key
|
||||
* @return true if sample has this property (even if its value is null)
|
||||
*/
|
||||
public boolean hasProperty(String key) {
|
||||
public boolean hasExtraProperty(String key) {
|
||||
return properties.containsKey(key);
|
||||
}
|
||||
|
||||
|
|
@ -196,17 +192,14 @@ public class Sample implements java.io.Serializable {
|
|||
Sample sample = (Sample) o;
|
||||
|
||||
if (hasSAMFileEntry != sample.hasSAMFileEntry) return false;
|
||||
if (hasSampleFileEntry != sample.hasSampleFileEntry) return false;
|
||||
if (id != null ? !id.equals(sample.id) : sample.id != null) return false;
|
||||
if (ID != null ? !ID.equals(sample.ID) : sample.ID != null) return false;
|
||||
if (properties != null ? !properties.equals(sample.properties) : sample.properties != null) return false;
|
||||
if (relationships != null ? !relationships.equals(sample.relationships) : sample.relationships != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id != null ? id.hashCode() : "".hashCode();
|
||||
return ID != null ? ID.hashCode() : "".hashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,12 +46,6 @@ public class SampleDataSource {
|
|||
*/
|
||||
private HashMap<String, String> sampleAliases = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
* While loading sample files, we must be aware of "special" properties and relationships that are always allowed
|
||||
*/
|
||||
public static final String[] specialProperties = new String[] {"familyId", "population", "gender"};
|
||||
public static final String[] specialRelationships = new String[] {"mother", "father"};
|
||||
|
||||
/**
|
||||
* Constructor takes both a SAM header and sample files because the two must be integrated.
|
||||
* @param header SAMFileHeader that has been created for this analysis
|
||||
|
|
@ -63,8 +57,7 @@ public class SampleDataSource {
|
|||
// create empty sample object for each sample referenced in the SAM header
|
||||
for (String sampleName : SampleUtils.getSAMFileSamples(header)) {
|
||||
if (!hasSample(sampleName)) {
|
||||
Sample newSample = new Sample(sampleName);
|
||||
newSample.setSAMFileEntry(true);
|
||||
Sample newSample = new Sample(sampleName, this);
|
||||
samples.put(sampleName, newSample);
|
||||
}
|
||||
}
|
||||
|
|
@ -78,7 +71,7 @@ public class SampleDataSource {
|
|||
}
|
||||
|
||||
public SampleDataSource() {
|
||||
samples.put(null, new Sample(null));
|
||||
samples.put(null, new Sample(null, this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -87,7 +80,7 @@ public class SampleDataSource {
|
|||
public void addSamplesFromSAMHeader(SAMFileHeader header) {
|
||||
for (String sampleName : SampleUtils.getSAMFileSamples(header)) {
|
||||
if (!hasSample(sampleName)) {
|
||||
Sample newSample = new Sample(sampleName);
|
||||
Sample newSample = new Sample(sampleName, this);
|
||||
newSample.setSAMFileEntry(true);
|
||||
samples.put(sampleName, newSample);
|
||||
}
|
||||
|
|
@ -151,9 +144,9 @@ public class SampleDataSource {
|
|||
//
|
||||
// try {
|
||||
// // step 1: add the sample if it doesn't already exist
|
||||
// Sample sample = getSampleById(sampleParser.getId());
|
||||
// Sample sample = getSampleById(sampleParser.getID());
|
||||
// if (sample == null) {
|
||||
// sample = new Sample(sampleParser.getId());
|
||||
// sample = new Sample(sampleParser.getID());
|
||||
// }
|
||||
// addSample(sample);
|
||||
// sample.setSampleFileEntry(true);
|
||||
|
|
@ -207,7 +200,7 @@ public class SampleDataSource {
|
|||
//
|
||||
// // next check that there isn't already a conflicting property there
|
||||
// if (sample.getRelationship(relationship) != null) {
|
||||
// if (sample.getRelationship(relationship).getId() != sampleParser.getProperties().get(relationship)) {
|
||||
// if (sample.getRelationship(relationship).getID() != sampleParser.getProperties().get(relationship)) {
|
||||
// throw new StingException(relationship + " is a conflicting relationship!");
|
||||
// }
|
||||
// // if the relationship is already set - and consistent with what we're reading now - no need to continue
|
||||
|
|
@ -222,7 +215,7 @@ public class SampleDataSource {
|
|||
// }
|
||||
// } catch (Exception e) {
|
||||
// throw new StingException("An error occurred while loading this sample from the sample file: " +
|
||||
// sampleParser.getId(), e);
|
||||
// sampleParser.getID(), e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
@ -377,7 +370,7 @@ public class SampleDataSource {
|
|||
* @param sample to be added
|
||||
*/
|
||||
private void addSample(Sample sample) {
|
||||
samples.put(sample.getId(), sample);
|
||||
samples.put(sample.getID(), sample);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -496,7 +489,7 @@ public class SampleDataSource {
|
|||
public Set<Sample> getSamplesWithProperty(String key) {
|
||||
HashSet<Sample> toReturn = new HashSet<Sample>();
|
||||
for (Sample s : samples.values()) {
|
||||
if (s.hasProperty(key))
|
||||
if (s.hasExtraProperty(key))
|
||||
toReturn.add(s);
|
||||
}
|
||||
return toReturn;
|
||||
|
|
@ -513,7 +506,7 @@ public class SampleDataSource {
|
|||
public Set<Sample> getSamplesWithProperty(String key, String value) {
|
||||
Set<Sample> toReturn = getSamplesWithProperty(key);
|
||||
for (Sample s : toReturn) {
|
||||
if (!s.getProperty(key).equals(value))
|
||||
if (!s.getExtraPropertyValue(key).equals(value))
|
||||
toReturn.remove(s);
|
||||
}
|
||||
return toReturn;
|
||||
|
|
@ -522,7 +515,7 @@ public class SampleDataSource {
|
|||
public Sample getOrCreateSample(String id) {
|
||||
Sample sample = getSampleById(id);
|
||||
if (sample == null) {
|
||||
sample = new Sample(id);
|
||||
sample = new Sample(id, this);
|
||||
addSample(sample);
|
||||
}
|
||||
return sample;
|
||||
|
|
@ -568,16 +561,10 @@ public class SampleDataSource {
|
|||
Set<String> samplesWithProperty = new HashSet<String>();
|
||||
for (String sampleName : context.getSampleNames()) {
|
||||
Sample s = samples.get(sampleName);
|
||||
if (s != null && s.hasProperty(key) && s.getProperty(key).equals(value))
|
||||
if (s != null && s.hasExtraProperty(key) && s.getExtraPropertyValue(key).equals(value))
|
||||
samplesWithProperty.add(sampleName);
|
||||
}
|
||||
Map<String, Genotype> genotypes = context.getGenotypes(samplesWithProperty);
|
||||
return context.subContextFromGenotypes(genotypes.values());
|
||||
}
|
||||
|
||||
public static SampleDataSource createEmptyDataSource() {
|
||||
SAMFileHeader header = new SAMFileHeader();
|
||||
return new SampleDataSource(header, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import org.apache.log4j.Logger;
|
|||
import org.broadinstitute.sting.gatk.CommandLineGATK;
|
||||
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine;
|
||||
import org.broadinstitute.sting.gatk.filters.MalformedReadFilter;
|
||||
import org.broadinstitute.sting.gatk.samples.Sample;
|
||||
import org.broadinstitute.sting.gatk.samples.SampleDataSource;
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
import org.broadinstitute.sting.utils.baq.BAQ;
|
||||
import org.broadinstitute.sting.utils.collections.Pair;
|
||||
|
|
@ -87,6 +89,14 @@ public abstract class Walker<MapType, ReduceType> {
|
|||
return getToolkit().getMasterSequenceDictionary();
|
||||
}
|
||||
|
||||
protected SampleDataSource getSampleDB() {
|
||||
return getToolkit().getSampleDB();
|
||||
}
|
||||
|
||||
protected Sample getSampleByID(final String id) {
|
||||
return getToolkit().getSampleDB().getSampleById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* (conceptual static) method that states whether you want to see reads piling up at a locus
|
||||
* that contain a deletion at the locus.
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ public class ProduceBeagleInputWalker extends RodWalker<Integer, Integer> {
|
|||
Map<String,Genotype> preferredGenotypes = preferredVC.getGenotypes();
|
||||
Map<String,Genotype> otherGenotypes = goodSite(otherVC) ? otherVC.getGenotypes() : null;
|
||||
for ( String sample : samples ) {
|
||||
boolean isMaleOnChrX = CHECK_IS_MALE_ON_CHR_X && getToolkit().getSampleById(sample).isMale();
|
||||
boolean isMaleOnChrX = CHECK_IS_MALE_ON_CHR_X && getSampleByID(sample).isMale();
|
||||
|
||||
Genotype genotype;
|
||||
boolean isValidation;
|
||||
|
|
|
|||
|
|
@ -227,9 +227,9 @@ public class CallableLociWalker extends LocusWalker<CallableLociWalker.CallableB
|
|||
|
||||
@Override
|
||||
public void initialize() {
|
||||
if ( getToolkit().getSamples().size() != 2 ) {
|
||||
if ( getSampleDB().getSamples().size() != 2 ) {
|
||||
// unbelievably there are actually two samples even when there's just one in the header. God I hate this Samples system
|
||||
throw new UserException.BadArgumentValue("-I", "CallableLoci only works for a single sample, but multiple samples were found in the provided BAM files: " + getToolkit().getSamples());
|
||||
throw new UserException.BadArgumentValue("-I", "CallableLoci only works for a single sample, but multiple samples were found in the provided BAM files: " + getSampleDB().getSamples());
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1102,7 +1102,7 @@ public class ReadBackedPhasingWalker extends RodWalker<PhasingStatsAndOutput, Ph
|
|||
if (!p.isDeletion()) // IGNORE deletions for now
|
||||
readBases.putReadBase(p);
|
||||
}
|
||||
sampleReadBases.put(sample.getId(), readBases);
|
||||
sampleReadBases.put(sample.getID(), readBases);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class CountLociByPopulationWalker extends LocusWalker<Integer, Long> impl
|
|||
for (SAMRecord read : reads) {
|
||||
|
||||
// get the sample
|
||||
Sample sample = getToolkit().getSampleByRead(read);
|
||||
Sample sample = getSampleDB().getSampleByRead(read);
|
||||
if (sample == null)
|
||||
return 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import org.broadinstitute.sting.gatk.walkers.Requires;
|
|||
@Requires({DataSource.READS, DataSource.REFERENCE})
|
||||
public class CountMalesWalker extends ReadWalker<Integer, Integer> {
|
||||
public Integer map(ReferenceContext ref, SAMRecord read, ReadMetaDataTracker tracker) {
|
||||
Sample sample = getToolkit().getSampleByRead(read);
|
||||
Sample sample = getSampleDB().getSampleByRead(read);
|
||||
return sample.isMale() ? 1 : 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,9 +88,9 @@ public class MendelianViolation {
|
|||
* @param minGenotypeQualityP - the minimum phred scaled genotype quality score necessary to asses mendelian violation
|
||||
*/
|
||||
public MendelianViolation(Sample sample, double minGenotypeQualityP) {
|
||||
sampleMom = sample.getMother().getId();
|
||||
sampleDad = sample.getFather().getId();
|
||||
sampleChild = sample.getId();
|
||||
sampleMom = sample.getMother().getID();
|
||||
sampleDad = sample.getFather().getID();
|
||||
sampleChild = sample.getID();
|
||||
minGenotypeQuality = minGenotypeQualityP;
|
||||
}
|
||||
|
||||
|
|
@ -102,13 +102,13 @@ public class MendelianViolation {
|
|||
*/
|
||||
public MendelianViolation(GenomeAnalysisEngine engine, double minGenotypeQualityP) {
|
||||
boolean gotSampleInformation = false;
|
||||
Collection<Sample> samples = engine.getSamples();
|
||||
Collection<Sample> samples = engine.getSampleDB().getSamples();
|
||||
// Iterate through all samples in the sample_metadata file but we really can only take one.
|
||||
for (Sample sample : samples) {
|
||||
if (sample.getMother() != null && sample.getFather() != null) {
|
||||
sampleMom = sample.getMother().getId();
|
||||
sampleDad = sample.getFather().getId();
|
||||
sampleChild = sample.getId();
|
||||
sampleMom = sample.getMother().getID();
|
||||
sampleDad = sample.getFather().getID();
|
||||
sampleChild = sample.getID();
|
||||
minGenotypeQuality = minGenotypeQualityP;
|
||||
gotSampleInformation = true;
|
||||
break; // we can only deal with one trio information
|
||||
|
|
|
|||
|
|
@ -555,7 +555,7 @@ public abstract class AbstractReadBackedPileup<RBP extends AbstractReadBackedPil
|
|||
PerSamplePileupElementTracker<PE> tracker = (PerSamplePileupElementTracker<PE>)pileupElementTracker;
|
||||
Collection<String> sampleNames = new HashSet<String>();
|
||||
for (Sample sample : tracker.getSamples()) {
|
||||
sampleNames.add(sample.getId());
|
||||
sampleNames.add(sample.getID());
|
||||
}
|
||||
return sampleNames;
|
||||
}
|
||||
|
|
@ -700,7 +700,7 @@ public abstract class AbstractReadBackedPileup<RBP extends AbstractReadBackedPil
|
|||
for(PE p: pileupElementTracker) {
|
||||
SAMRecord read = p.getRead();
|
||||
if(sample != null) {
|
||||
if(read.getReadGroup() != null && sample.getId().equals(read.getReadGroup().getSample()))
|
||||
if(read.getReadGroup() != null && sample.getID().equals(read.getReadGroup().getSample()))
|
||||
filteredTracker.add(p);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class PerSamplePileupElementTracker<PE extends PileupElement> extends PileupElem
|
|||
Sample sample = entry.getKey();
|
||||
AbstractReadBackedPileup<?,PE> pileupBySample = entry.getValue();
|
||||
pileup.put(sample,pileupBySample.pileupElementTracker);
|
||||
sampleNames.put(sample.getId(), sample);
|
||||
sampleNames.put(sample.getID(), sample);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ class PerSamplePileupElementTracker<PE extends PileupElement> extends PileupElem
|
|||
|
||||
public void addElements(final Sample sample, PileupElementTracker<PE> elements) {
|
||||
pileup.put(sample,elements);
|
||||
sampleNames.put(sample.getId(), sample);
|
||||
sampleNames.put(sample.getID(), sample);
|
||||
size += elements.size();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,8 +149,8 @@ public class SampleDataSourceUnitTest extends BaseTest {
|
|||
|
||||
Iterator<Sample> i = ceuSamples.iterator();
|
||||
ArrayList<String> sampleNames = new ArrayList<String>();
|
||||
sampleNames.add(i.next().getId());
|
||||
sampleNames.add(i.next().getId());
|
||||
sampleNames.add(i.next().getID());
|
||||
sampleNames.add(i.next().getID());
|
||||
Assert.assertTrue(sampleNames.contains("sampleA"));
|
||||
Assert.assertTrue(sampleNames.contains("sampleB"));
|
||||
}
|
||||
|
|
@ -191,8 +191,8 @@ public class SampleDataSourceUnitTest extends BaseTest {
|
|||
// make sure both samples are included
|
||||
Iterator<Sample> i = set.iterator();
|
||||
ArrayList<String> sampleNames = new ArrayList<String>();
|
||||
sampleNames.add(i.next().getId());
|
||||
sampleNames.add(i.next().getId());
|
||||
sampleNames.add(i.next().getID());
|
||||
sampleNames.add(i.next().getID());
|
||||
Assert.assertTrue(sampleNames.contains("NA123"));
|
||||
Assert.assertTrue(sampleNames.contains("NA456"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class SampleUnitTest extends BaseTest {
|
|||
*/
|
||||
@Test()
|
||||
public void specialGettersTest() {
|
||||
Assert.assertTrue(sampleC.getId().equals("sampleC"));
|
||||
Assert.assertTrue(sampleC.getID().equals("sampleC"));
|
||||
Assert.assertTrue(sampleC.getPopulation().equals("pop1"));
|
||||
Assert.assertTrue(sampleC.isMale());
|
||||
Assert.assertFalse(sampleA.isMale()); // sample A doesn't have a gender, so this should be false
|
||||
|
|
|
|||
|
|
@ -168,9 +168,9 @@ public class ReadBackedPileupUnitTest {
|
|||
Sample sample2 = new Sample("sample2");
|
||||
|
||||
SAMReadGroupRecord readGroupOne = new SAMReadGroupRecord("rg1");
|
||||
readGroupOne.setSample(sample1.getId());
|
||||
readGroupOne.setSample(sample1.getID());
|
||||
SAMReadGroupRecord readGroupTwo = new SAMReadGroupRecord("rg2");
|
||||
readGroupTwo.setSample(sample2.getId());
|
||||
readGroupTwo.setSample(sample2.getID());
|
||||
|
||||
SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader(1,1,1000);
|
||||
header.addReadGroup(readGroupOne);
|
||||
|
|
@ -191,7 +191,7 @@ public class ReadBackedPileupUnitTest {
|
|||
Assert.assertEquals(sample1Pileup.size(),1,"Sample 1 pileup has wrong number of elements");
|
||||
Assert.assertEquals(sample1Pileup.getReads().get(0),read1,"Sample 1 pileup has incorrect read");
|
||||
|
||||
ReadBackedPileup sample2Pileup = pileup.getPileupForSampleName(sample2.getId());
|
||||
ReadBackedPileup sample2Pileup = pileup.getPileupForSampleName(sample2.getID());
|
||||
Assert.assertEquals(sample2Pileup.size(),1,"Sample 2 pileup has wrong number of elements");
|
||||
Assert.assertEquals(sample2Pileup.getReads().get(0),read2,"Sample 2 pileup has incorrect read");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue