From 0b73573abca491ea2c32dba8446902ed9ea28a72 Mon Sep 17 00:00:00 2001 From: Eric Banks Date: Wed, 2 Apr 2014 21:34:25 -0400 Subject: [PATCH] Slightly modifying the way to use the IUPAC ambiguity codes in the FastaAlternateReferenceMaker. Previously it required you to create a single sample VCF and then to pass that in to the tool, but Geraldine convinced me that this was a pain for users (because they usually have multi-sample VCFs). Instead now you can pass in a multi-sample VCF and specify which sample's genotypes should be used for the IUPAC encoding. Therefore the argument changed from '--useIUPAC' to '--use_IUPAC_sample NA12878'. --- .../FastaAlternateReferenceIntegrationTest.java | 4 ++-- .../fasta/FastaAlternateReferenceMaker.java | 14 ++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceIntegrationTest.java b/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceIntegrationTest.java index 58ff0a7b3..8130fa07b 100644 --- a/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceIntegrationTest.java +++ b/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceIntegrationTest.java @@ -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 try { 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, Arrays.asList("FAILFAILFAILFAILFAILFAILFAILFAIL")); executeTest("test bad input", spec); @@ -101,7 +101,7 @@ public class FastaAlternateReferenceIntegrationTest extends WalkerTest { public void testIupac() { 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, Arrays.asList("5feb2a576ff2ed1745a007eaa36448b3")); executeTest("test iupac", spec); diff --git a/public/gatk-framework/src/main/java/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceMaker.java b/public/gatk-framework/src/main/java/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceMaker.java index 2ff9ade5f..9a02e2fac 100644 --- a/public/gatk-framework/src/main/java/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceMaker.java +++ b/public/gatk-framework/src/main/java/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceMaker.java @@ -109,11 +109,10 @@ public class FastaAlternateReferenceMaker extends FastaReferenceMaker { protected RodBinding 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. */ - @Argument(fullName="useIUPAC", shortName="useIUPAC", doc = "If specified, heterozygous SNP sites will be output using IUPAC codes", required=false) - protected boolean useIUPACcodes = 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) private String iupacSample = null; private int deletionBasesRemaining = 0; @@ -121,12 +120,11 @@ public class FastaAlternateReferenceMaker extends FastaReferenceMaker { @Override public void initialize() { super.initialize(); - if ( useIUPACcodes ) { + if ( iupacSample != null ) { final List rodName = Arrays.asList(variantCollection.variants.getName()); final Set samples = SampleUtils.getUniqueSamplesFromRods(getToolkit(), rodName); - if ( samples.size() != 1 ) - 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"); - iupacSample = samples.iterator().next(); + if ( !samples.contains(iupacSample) ) + throw new UserException.BadInput("the IUPAC sample specified is not present in the provided VCF file"); } } @@ -152,7 +150,7 @@ public class FastaAlternateReferenceMaker extends FastaReferenceMaker { } else if ( vc.isSimpleInsertion()) { return new Pair<>(context.getLocation(), vc.getAlternateAllele(0).toString()); } 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); } }