Merge pull request #586 from broadinstitute/eb_allow_users_to_specify_iupac_sample

Slightly modifying the way to use the IUPAC ambiguity codes in the Fasta...
This commit is contained in:
Geraldine Van der Auwera 2014-04-03 09:29:56 -04:00
commit 890f4e8873
2 changed files with 8 additions and 10 deletions

View File

@ -90,7 +90,7 @@ public class FastaAlternateReferenceIntegrationTest extends WalkerTest {
// cannot use 'expectedExceptions = UserException.BadInput.class' because it technically gets thrown as a RuntimeException by the engine // cannot use 'expectedExceptions = UserException.BadInput.class' because it technically gets thrown as a RuntimeException by the engine
try { try {
WalkerTestSpec spec = new WalkerTestSpec( WalkerTestSpec spec = new WalkerTestSpec(
"-T FastaAlternateReferenceMaker -R " + b36KGReference + " --useIUPAC -V " + GATKDataLocation + "dbsnp_129_b36.vcf -L 1:10,023,400-10,023,500 -L 1:10,029,200-10,029,500 -o %s", "-T FastaAlternateReferenceMaker -R " + b37KGReference + " --use_IUPAC_sample NAXXXXX -V " + privateTestDir + "NA12878.WGS.b37.chr20.firstMB.vcf -L 20:61050-66380 -o %s",
1, 1,
Arrays.asList("FAILFAILFAILFAILFAILFAILFAILFAIL")); Arrays.asList("FAILFAILFAILFAILFAILFAILFAILFAIL"));
executeTest("test bad input", spec); executeTest("test bad input", spec);
@ -101,7 +101,7 @@ public class FastaAlternateReferenceIntegrationTest extends WalkerTest {
public void testIupac() { public void testIupac() {
WalkerTestSpec spec = new WalkerTestSpec( WalkerTestSpec spec = new WalkerTestSpec(
"-T FastaAlternateReferenceMaker -R " + b37KGReference + " --useIUPAC -V " + privateTestDir + "NA12878.WGS.b37.chr20.firstMB.vcf -L 20:61050-66380 -o %s", "-T FastaAlternateReferenceMaker -R " + b37KGReference + " --use_IUPAC_sample NA12878 -V " + privateTestDir + "NA12878.WGS.b37.chr20.firstMB.vcf -L 20:61050-66380 -o %s",
1, 1,
Arrays.asList("5feb2a576ff2ed1745a007eaa36448b3")); Arrays.asList("5feb2a576ff2ed1745a007eaa36448b3"));
executeTest("test iupac", spec); executeTest("test iupac", spec);

View File

@ -109,11 +109,10 @@ public class FastaAlternateReferenceMaker extends FastaReferenceMaker {
protected RodBinding<VariantContext> snpmask; protected RodBinding<VariantContext> snpmask;
/** /**
* This option works only for VCFs with genotypes for exactly one sample; anything else will generate an error. * This option will generate an error if the specified sample does not exist in the VCF.
* Non-diploid (or non-called) genotypes are ignored. * Non-diploid (or non-called) genotypes are ignored.
*/ */
@Argument(fullName="useIUPAC", shortName="useIUPAC", doc = "If specified, heterozygous SNP sites will be output using IUPAC codes", required=false) @Argument(fullName="use_IUPAC_sample", shortName="IUPAC", doc = "If specified, heterozygous SNP sites will be output using IUPAC ambiguity codes given the genotypes for this sample", required=false)
protected boolean useIUPACcodes = false;
private String iupacSample = null; private String iupacSample = null;
private int deletionBasesRemaining = 0; private int deletionBasesRemaining = 0;
@ -121,12 +120,11 @@ public class FastaAlternateReferenceMaker extends FastaReferenceMaker {
@Override @Override
public void initialize() { public void initialize() {
super.initialize(); super.initialize();
if ( useIUPACcodes ) { if ( iupacSample != null ) {
final List<String> rodName = Arrays.asList(variantCollection.variants.getName()); final List<String> rodName = Arrays.asList(variantCollection.variants.getName());
final Set<String> samples = SampleUtils.getUniqueSamplesFromRods(getToolkit(), rodName); final Set<String> samples = SampleUtils.getUniqueSamplesFromRods(getToolkit(), rodName);
if ( samples.size() != 1 ) if ( !samples.contains(iupacSample) )
throw new UserException.BadInput("the --useIUPAC option works only on VCF files with genotypes for exactly one sample, but the input file has " + samples.size() + " samples"); throw new UserException.BadInput("the IUPAC sample specified is not present in the provided VCF file");
iupacSample = samples.iterator().next();
} }
} }
@ -152,7 +150,7 @@ public class FastaAlternateReferenceMaker extends FastaReferenceMaker {
} else if ( vc.isSimpleInsertion()) { } else if ( vc.isSimpleInsertion()) {
return new Pair<>(context.getLocation(), vc.getAlternateAllele(0).toString()); return new Pair<>(context.getLocation(), vc.getAlternateAllele(0).toString());
} else if (vc.isSNP()) { } else if (vc.isSNP()) {
final String base = useIUPACcodes ? getIUPACbase(vc.getGenotype(iupacSample), refBase) : vc.getAlternateAllele(0).toString(); final String base = (iupacSample != null) ? getIUPACbase(vc.getGenotype(iupacSample), refBase) : vc.getAlternateAllele(0).toString();
return new Pair<>(context.getLocation(), base); return new Pair<>(context.getLocation(), base);
} }
} }