Spotted a potential bug where sample IDs passed in from the meta data were only checked against the sample IDs in the VCF header if the input file happened to be a meta data file rather than a fam file. Added a check for fam files as well, and added an integration test to cover each case.

This commit is contained in:
Christopher Hartl 2012-08-23 11:43:19 -07:00
parent 2ae5ec5596
commit f1166d6d00
2 changed files with 31 additions and 0 deletions

View File

@ -104,6 +104,12 @@ public class VariantsToBinaryPed extends RodWalker<Integer,Integer> {
String sex = mVals.containsKey("sex") ? mVals.get("sex") : "3";
String pheno = mVals.get("phenotype");
outFam.printf("%s\t%s\t%s\t%s\t%s\t%s%n",fid,sample,pid,mid,sex,pheno);
} else {
// even if a fam file is input, we can't diverge the bed file from the fam file, which
// could lead to a malformed plink trio. Fail fast if there's any extra sample in the VCF.
if ( ! sampleMetaValues.containsKey(sample) ) {
throw new UserException("No metadata provided for sample "+sample);
}
}
try {
File temp = File.createTempFile("VariantsToBPed_"+sample, ".tmp");

View File

@ -87,6 +87,31 @@ public class VariantsToBinaryPedIntegrationTest extends WalkerTest {
executeTest(testName, spec);
}
@Test
public void testFailFast() {
String testName = "testFailFast";
WalkerTestSpec spec = new WalkerTestSpec(
baseTestString("HapMap.testFailFast.vcf", "HapMap_only_famids.fam",10),
3,
UserException.class
);
executeTest(testName, spec);
}
@Test
public void testFailFastMeta() {
String testName = "testFailFastMeta";
WalkerTestSpec spec = new WalkerTestSpec(
baseTestString("HapMap.testFailFast.vcf", "HapMap_only_famids.metadata.txt",10),
3,
UserException.class
);
executeTest(testName, spec);
}
}