Quickly adding a new convenience method for retreiving a group of samples. The method is getSamples(Collection<String>) and returns a set of sample objects. There's also a test there.
Ryan is using this to modify VCF code today... git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4303 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
a898908918
commit
c6c6d32b46
|
|
@ -1037,4 +1037,14 @@ public class GenomeAnalysisEngine {
|
|||
return sampleDataSource.getChildren(sample);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
|
|
@ -464,5 +466,24 @@ public class SampleDataSource {
|
|||
return children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a collection of sample names and returns their corresponding sample objects
|
||||
* Note that, since a set is returned, if you pass in a list with duplicates names there will not be any duplicates in the returned set
|
||||
* @param sampleNameList Set of sample names
|
||||
* @return Corresponding set of samples
|
||||
*/
|
||||
public Set<Sample> getSamples(Collection<String> sampleNameList) {
|
||||
HashSet<Sample> samples = new HashSet<Sample>();
|
||||
for (String name : sampleNameList) {
|
||||
try {
|
||||
samples.add(getSampleById(name));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new StingException("Could not get sample with the following ID: " + name, e);
|
||||
}
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,13 @@ public class SampleDataSourceUnitTest extends BaseTest {
|
|||
Assert.assertTrue(family.size() == 2);
|
||||
Assert.assertTrue(family.contains(sampleA));
|
||||
Assert.assertTrue(family.contains(sampleB));
|
||||
|
||||
// make sure getSamples(List names) works
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
names.add("sampleA");
|
||||
names.add("sampleB");
|
||||
Set<Sample> testList = s.getSamples(names);
|
||||
Assert.assertTrue(testList.size() == 2);
|
||||
}
|
||||
|
||||
// but that file should fail if it has an extra character in it...
|
||||
|
|
|
|||
Loading…
Reference in New Issue