Bug fix for incorrect logic in subsetSamples
-- Now properly handles the case where a sample isn't present (no longer adds a null to the genotypes list) -- Fix for logic failure where if the number of requested samples equals the number of known genotypes then all of the records were returned, which isn't correct when there are missing samples. -- Unit tests added to handle these cases
This commit is contained in:
parent
7ac8966184
commit
71b4bb12b7
|
|
@ -410,6 +410,12 @@ public class GenotypesContext implements List<Genotype> {
|
||||||
return getGenotypes().get(i);
|
return getGenotypes().get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sample associated with this sampleName, or null if none is found
|
||||||
|
*
|
||||||
|
* @param sampleName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Genotype get(final String sampleName) {
|
public Genotype get(final String sampleName) {
|
||||||
Integer offset = getSampleI(sampleName);
|
Integer offset = getSampleI(sampleName);
|
||||||
return offset == null ? null : getGenotypes().get(offset);
|
return offset == null ? null : getGenotypes().get(offset);
|
||||||
|
|
@ -648,16 +654,15 @@ public class GenotypesContext implements List<Genotype> {
|
||||||
@Ensures("result != null")
|
@Ensures("result != null")
|
||||||
public GenotypesContext subsetToSamples( final Set<String> samples ) {
|
public GenotypesContext subsetToSamples( final Set<String> samples ) {
|
||||||
final int nSamples = samples.size();
|
final int nSamples = samples.size();
|
||||||
final int nGenotypes = size();
|
|
||||||
|
|
||||||
if ( nSamples == nGenotypes )
|
if ( nSamples == 0 )
|
||||||
return this;
|
|
||||||
else if ( nSamples == 0 )
|
|
||||||
return NO_GENOTYPES;
|
return NO_GENOTYPES;
|
||||||
else { // nGenotypes < nSamples
|
else { // nGenotypes < nSamples
|
||||||
final GenotypesContext subset = create(samples.size());
|
final GenotypesContext subset = create(samples.size());
|
||||||
for ( final String sample : samples ) {
|
for ( final String sample : samples ) {
|
||||||
subset.add(get(sample));
|
final Genotype g = get(sample);
|
||||||
|
if ( g != null )
|
||||||
|
subset.add(g);
|
||||||
}
|
}
|
||||||
return subset;
|
return subset;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -704,11 +704,14 @@ public class VariantContextUnitTest extends BaseTest {
|
||||||
public Object[][] MakeSubContextTest() {
|
public Object[][] MakeSubContextTest() {
|
||||||
for ( boolean updateAlleles : Arrays.asList(true, false)) {
|
for ( boolean updateAlleles : Arrays.asList(true, false)) {
|
||||||
new SubContextTest(Collections.<String>emptySet(), updateAlleles);
|
new SubContextTest(Collections.<String>emptySet(), updateAlleles);
|
||||||
|
new SubContextTest(Collections.singleton("MISSING"), updateAlleles);
|
||||||
new SubContextTest(Collections.singleton("AA"), updateAlleles);
|
new SubContextTest(Collections.singleton("AA"), updateAlleles);
|
||||||
new SubContextTest(Collections.singleton("AT"), updateAlleles);
|
new SubContextTest(Collections.singleton("AT"), updateAlleles);
|
||||||
new SubContextTest(Collections.singleton("TT"), updateAlleles);
|
new SubContextTest(Collections.singleton("TT"), updateAlleles);
|
||||||
new SubContextTest(Arrays.asList("AA", "AT"), updateAlleles);
|
new SubContextTest(Arrays.asList("AA", "AT"), updateAlleles);
|
||||||
new SubContextTest(Arrays.asList("AA", "AT", "TT"), updateAlleles);
|
new SubContextTest(Arrays.asList("AA", "AT", "TT"), updateAlleles);
|
||||||
|
new SubContextTest(Arrays.asList("AA", "AT", "MISSING"), updateAlleles);
|
||||||
|
new SubContextTest(Arrays.asList("AA", "AT", "TT", "MISSING"), updateAlleles);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SubContextTest.getTests(SubContextTest.class);
|
return SubContextTest.getTests(SubContextTest.class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue