diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariantsIntegrationTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignAndTrimVariantsIntegrationTest.java similarity index 96% rename from protected/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariantsIntegrationTest.java rename to protected/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignAndTrimVariantsIntegrationTest.java index 721eb2874..0b3d9c930 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariantsIntegrationTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignAndTrimVariantsIntegrationTest.java @@ -52,14 +52,14 @@ import org.testng.annotations.Test; import java.util.Arrays; /** - * Tests LeftAlignVariants + * Tests LeftAlignAndTrimVariants */ -public class LeftAlignVariantsIntegrationTest extends WalkerTest { +public class LeftAlignAndTrimVariantsIntegrationTest extends WalkerTest { @Test public void testLeftAlignment() { WalkerTestSpec spec = new WalkerTestSpec( - "-T LeftAlignVariants -o %s -R " + b37KGReference + " --variant:vcf " + privateTestDir + "forLeftAlignVariantsTest.vcf --no_cmdline_in_header", + "-T LeftAlignAndTrimVariants -o %s -R " + b37KGReference + " --variant:vcf " + privateTestDir + "forLeftAlignVariantsTest.vcf --no_cmdline_in_header", 1, Arrays.asList("bcf05f56adbb32a47b6d6b27b327d5c2")); executeTest("test left alignment", spec); diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignAndTrimVariantsUnitTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignAndTrimVariantsUnitTest.java new file mode 100644 index 000000000..a8739dac2 --- /dev/null +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignAndTrimVariantsUnitTest.java @@ -0,0 +1,177 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.variantutils; + +import net.sf.picard.reference.IndexedFastaSequenceFile; +import net.sf.samtools.SAMFileHeader; +import net.sf.samtools.SAMReadGroupRecord; +import org.broadinstitute.sting.BaseTest; +import org.broadinstitute.sting.gatk.contexts.ReferenceContext; +import org.broadinstitute.sting.utils.GenomeLoc; +import org.broadinstitute.sting.utils.GenomeLocParser; +import org.broadinstitute.sting.utils.Utils; +import org.broadinstitute.sting.utils.collections.Pair; +import org.broadinstitute.sting.utils.fasta.CachingIndexedFastaSequenceFile; +import org.broadinstitute.sting.utils.sam.ArtificialSAMUtils; +import org.broadinstitute.sting.utils.sam.GATKSAMReadGroupRecord; +import org.broadinstitute.sting.utils.variant.GATKVariantContextUtils; +import org.broadinstitute.variant.variantcontext.Allele; +import org.broadinstitute.variant.variantcontext.VariantContext; +import org.broadinstitute.variant.variantcontext.VariantContextBuilder; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.*; + +/** + * Created with IntelliJ IDEA. + * User: delangel + * Date: 3/22/13 + * Time: 6:09 PM + * To change this template use File | Settings | File Templates. + */ +public class LeftAlignAndTrimVariantsUnitTest extends BaseTest { + final String refBases1 = "ACAGAGCTGACCCTCCCTCCCCTCTCCCAGTGCAACAGCACGGGCGGCGACTGCTTTTACCGAGGCTACACGTCAGGCGTGGCGGCTGTCCAGGACTGGTACCACTTCCACTATGTGGATCTCTGCTGAGGACCAGGAAAGCCAGCACCCGCAGAGACTCTTCCCCAGTGCTCCATACGATCACCATTCTCTGCAGAAGG"; + final String longPiece = "AAAAAAAAAAAAAAAAAAAAAAAAAAAA"; // where we'll perform tests + final String refBases = refBases1 + longPiece + refBases1; + + final int contigStop = refBases.length(); + final SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader(1, 1, contigStop ); + final String artificialContig = "chr1"; + final int locStart = refBases1.length(); // start position where we desire artificial variant + final GenomeLocParser genomeLocParser = new GenomeLocParser(header.getSequenceDictionary()); + final GenomeLoc window = genomeLocParser.createGenomeLoc(artificialContig,1,refBases.length()); + final String windowBases = refBases; + + + + @DataProvider(name = "LeftAlignDataProvider") + public Object[][] makeLeftAlignDataProvider() { + List tests = new ArrayList(); + + // this functionality can be adapted to provide input data for whatever you might want in your data + for ( int offset = 1; offset < longPiece.length(); offset++ ) { + for ( int indelSize = -longPiece.length()+offset; indelSize < longPiece.length()-offset; indelSize++ ) { + tests.add(new Object[]{offset, indelSize}); + } + } + + return tests.toArray(new Object[][]{}); + } + + @Test(dataProvider = "LeftAlignDataProvider") + public void testLeftAlignNoTrimming(final int offset, final int indelSize) { + if (indelSize == 0) + return; + + final List alleles = new ArrayList(); + + if (indelSize < 0) { // deletion + alleles.add(Allele.create(Utils.dupString("A",Math.abs(indelSize)+1),true)); + alleles.add(Allele.create("A", false)); + } + else { + alleles.add(Allele.create("A", true)); + alleles.add(Allele.create(Utils.dupString("A",Math.abs(indelSize)+1),false)); + + } + final GenomeLoc loc = genomeLocParser.createGenomeLoc(artificialContig,locStart+offset,locStart+offset); + final ReferenceContext referenceContext = new ReferenceContext(genomeLocParser,loc,window,windowBases.getBytes()); + + final VariantContext vc = new VariantContextBuilder("test", artificialContig, locStart+offset, locStart+offset+alleles.get(0).length()-1, alleles).make(); + final Pair result = LeftAlignAndTrimVariants.alignAndWrite(vc,referenceContext); + Assert.assertTrue(result.second == (offset>0?1:0)); + Assert.assertEquals(result.first.getStart(), locStart); + + + } + + @DataProvider(name = "TrimDataProvider") + public Object[][] makeTrimDataProvider() { + List tests = new ArrayList(); + + for ( int offset = 1; offset < longPiece.length(); offset++ ) { + for ( int indelSize = -longPiece.length()+offset; indelSize < longPiece.length()-offset; indelSize++ ) + tests.add(new Object[]{indelSize, offset}); + } + + return tests.toArray(new Object[][]{}); + } + + @Test(dataProvider = "TrimDataProvider") + public void testTrimming(final int indelSize, final int offset) { + if (indelSize == 0) + return; + + final List alleles = new ArrayList(); + + final GenomeLoc loc = genomeLocParser.createGenomeLoc(artificialContig,locStart+offset,locStart+offset); + final ReferenceContext referenceContext = new ReferenceContext(genomeLocParser,loc,window,windowBases.getBytes()); + + final int prefixLen = 10; + final String prefix = refBases.substring(locStart+offset-prefixLen,locStart+offset); + if (indelSize < 0) { // deletion + alleles.add(Allele.create(prefix+Utils.dupString("A",Math.abs(indelSize)+1),true)); + alleles.add(Allele.create(prefix+"A", false)); + } + else { + alleles.add(Allele.create(prefix+"A", true)); + alleles.add(Allele.create(prefix+Utils.dupString("A",Math.abs(indelSize)+1),false)); + + } + + final VariantContext vc = GATKVariantContextUtils.trimAlleles( new VariantContextBuilder("test", artificialContig, locStart + offset, locStart + offset + alleles.get(0).length() - 1, alleles).make(),true,true); + if (indelSize>0) + Assert.assertEquals(vc.getReference().length(),1); + else + Assert.assertEquals(vc.getReference().length(),Math.abs(indelSize)+1); + } +} \ No newline at end of file diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignAndTrimVariants.java similarity index 65% rename from public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java rename to public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignAndTrimVariants.java index 700b34b38..25e3e9857 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignAndTrimVariants.java @@ -25,9 +25,12 @@ package org.broadinstitute.sting.gatk.walkers.variantutils; +import com.google.java.contract.Ensures; +import com.google.java.contract.Requires; import net.sf.samtools.Cigar; import net.sf.samtools.CigarElement; import net.sf.samtools.CigarOperator; +import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.ArgumentCollection; import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.CommandLineGATK; @@ -38,8 +41,11 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.Reference; import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.gatk.walkers.Window; +import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.SampleUtils; +import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.help.HelpConstants; +import org.broadinstitute.sting.utils.variant.GATKVariantContextUtils; import org.broadinstitute.variant.vcf.VCFHeader; import org.broadinstitute.variant.vcf.VCFHeaderLine; import org.broadinstitute.sting.utils.variant.GATKVCFUtils; @@ -55,14 +61,15 @@ import java.util.*; * Left-aligns indels from a variants file. * *

- * LeftAlignVariants is a tool that takes a VCF file and left-aligns the indels inside it. The same indel can often be + * LeftAlignAndTrimVariants is a tool that takes a VCF file and left-aligns the indels inside it. The same indel can often be * placed at multiple positions and still represent the same haplotype. While the standard convention with VCF is to * place an indel at the left-most position this doesn't always happen, so this tool can be used to left-align them. * Note that this tool cannot handle anything other than bi-allelic, simple indels. Complex events are written out unchanged. + * Optionally, the tool will also trim common bases from indels, leaving them with a minimum representation. * *

Input

*

- * A variant set to left-align. + * A variant set to left-align and trim. *

* *

Output

@@ -74,24 +81,39 @@ import java.util.*; *
  * java -Xmx2g -jar GenomeAnalysisTK.jar \
  *   -R ref.fasta \
- *   -T LeftAlignVariants \
+ *   -T LeftAlignAndTrimVariants \
  *   --variant input.vcf \
  *   -o output.vcf
  * 
* */ @DocumentedGATKFeature( groupName = HelpConstants.DOCS_CAT_VARMANIP, extraDocs = {CommandLineGATK.class} ) -@Reference(window=@Window(start=-200,stop=200)) -public class LeftAlignVariants extends RodWalker { +@Reference(window=@Window(start=-200,stop=200)) // WARNING: if this changes,MAX_INDEL_LENGTH needs to change as well! +public class LeftAlignAndTrimVariants extends RodWalker { @ArgumentCollection protected StandardVariantContextInputArgumentCollection variantCollection = new StandardVariantContextInputArgumentCollection(); + /** + * If this argument is set, bases common to all alleles will be removed, leaving only their minimal representation. + */ + @Argument(fullName="trimAlleles", shortName="trim", doc="Trim alleles to remove bases common to all of them", required=false) + protected boolean trimAlleles = false; + + /** + * If this argument is set, split multiallelic records and left-align individual alleles. + * If this argument is not set, multiallelic records are not attempted to left-align and will be copied as is. + */ + @Argument(fullName="splitMultiallelics", shortName="split", doc="Split multiallelic records and left-align individual alleles", required=false) + protected boolean splitMultiallelics = false; + + @Output(doc="File to which variants should be written") protected VariantContextWriter baseWriter = null; private VariantContextWriter writer; + private static final int MAX_INDEL_LENGTH = 200; // needs to match reference window size! public void initialize() { String trackName = variantCollection.variants.getName(); Set samples = SampleUtils.getSampleListWithVCFHeader(getToolkit(), Arrays.asList(trackName)); @@ -110,8 +132,25 @@ public class LeftAlignVariants extends RodWalker { Collection VCs = tracker.getValues(variantCollection.variants, context.getLocation()); int changedSites = 0; - for ( VariantContext vc : VCs ) - changedSites += alignAndWrite(vc, ref); + for ( final VariantContext vc : VCs ) { + // split first into biallelics, and optionally trim alleles to minimal representation + Pair result = new Pair(vc,0); // default value + if (splitMultiallelics) { + final List vcList = GATKVariantContextUtils.splitVariantContextToBiallelics( vc); + for (final VariantContext biallelicVC: vcList) { + final VariantContext v = (trimAlleles ? GATKVariantContextUtils.trimAlleles(vc,true,true):biallelicVC); + result = alignAndWrite(v, ref); + + } + } + else if (trimAlleles) + result = alignAndWrite(GATKVariantContextUtils.trimAlleles(vc,true,true), ref); + else + result = alignAndWrite(vc,ref); + + writer.add(result.first); + changedSites += result.second; + } return changedSites; } @@ -127,18 +166,21 @@ public class LeftAlignVariants extends RodWalker { System.out.println(result + " variants were aligned"); } + /** + * Main routine workhorse. By definitio, it will only take biallelic vc's. Splitting into multiple alleles has to be + * handled by calling routine. + * @param vc Input VC with variants to left align + * @param ref Reference context + * @return # of records left-aligned (0 or 1) and new VC. + */ + @Requires({"vc != null","ref != null", "vc.isBiallelic() == true","ref.getBases().length>=2*MAX_INDEL_LENGTH+1"}) + @Ensures({"result != null","result.first != null", "result.second >=0"}) + protected static Pair alignAndWrite(final VariantContext vc, final ReferenceContext ref) { - private int alignAndWrite(VariantContext vc, final ReferenceContext ref) { - if ( vc.isBiallelic() && vc.isIndel() && !vc.isComplexIndel() ) - return writeLeftAlignedIndel(vc, ref); - else { - writer.add(vc); - return 0; + final Pair retValue = new Pair(vc,0); + if (!vc.isIndel() || vc.isComplexIndel() ) { + return retValue; } - } - - private int writeLeftAlignedIndel(final VariantContext vc, final ReferenceContext ref) { - final byte[] refSeq = ref.getBases(); // get the indel length final int indelLength; @@ -147,13 +189,20 @@ public class LeftAlignVariants extends RodWalker { else indelLength = vc.getAlternateAllele(0).length() - 1; - if ( indelLength > 200 ) { - writer.add(vc); - return 0; - } + if ( indelLength > MAX_INDEL_LENGTH ) + return retValue; + + if (vc.getReference().getBases()[0] != vc.getAlternateAllele(0).getBases()[0]) + return retValue; + + final byte[] refSeq = ref.getBases(); + + // create an indel haplotype. + // + final int originalIndex = vc.getStart() - ref.getWindow().getStart() + 1; + if (originalIndex < 0 || originalIndex >= ref.getBases().length) + return retValue; - // create an indel haplotype - final int originalIndex = ref.getLocus().getStart() - ref.getWindow().getStart() + 1; final byte[] originalIndel = makeHaplotype(vc, refSeq, originalIndex, indelLength); // create a CIGAR string to represent the event @@ -178,15 +227,24 @@ public class LeftAlignVariants extends RodWalker { System.arraycopy((vc.isSimpleDeletion() ? refSeq : originalIndel), indelIndex, newBases, 1, indelLength); final Allele newAllele = Allele.create(newBases, vc.isSimpleDeletion()); newVC = updateAllele(newVC, newAllele); + // overwrite default return value with new left-aligned VC + retValue.first = newVC; + retValue.second = 1; - writer.add(newVC); - return 1; - } else { - writer.add(vc); - return 0; } + return retValue; } + /** + * Make a haplotype from a given alt allele, using bases in input reference, index of an input reference + * @param vc Input VC - will use only alt allele from it + * @param ref Ref bases + * @param indexOfRef Index in ref where to create indel + * @param indelLength Indel length + * @return + */ + @Requires({"vc != null","ref != null", "indexOfRef +indelLength < ref.length", "vc.getNAlleles() == 2"}) + @Ensures("result != null") private static byte[] makeHaplotype(VariantContext vc, byte[] ref, int indexOfRef, int indelLength) { byte[] hap = new byte[ref.length + (indelLength * (vc.isSimpleDeletion() ? -1 : 1))]; diff --git a/public/java/src/org/broadinstitute/sting/utils/variant/GATKVariantContextUtils.java b/public/java/src/org/broadinstitute/sting/utils/variant/GATKVariantContextUtils.java index dee282056..0bd30c3a4 100644 --- a/public/java/src/org/broadinstitute/sting/utils/variant/GATKVariantContextUtils.java +++ b/public/java/src/org/broadinstitute/sting/utils/variant/GATKVariantContextUtils.java @@ -436,11 +436,15 @@ public class GATKVariantContextUtils { // the genotypes with PLs final GenotypesContext oldGTs = vc.getGenotypes(); + // the new genotypes to create + final GenotypesContext newGTs = GenotypesContext.create(); + // optimization: if no input genotypes, just exit + if (oldGTs.isEmpty()) + return newGTs; + // samples final List sampleIndices = oldGTs.getSampleNamesOrderedByName(); - // the new genotypes to create - final GenotypesContext newGTs = GenotypesContext.create(); // we need to determine which of the alternate alleles (and hence the likelihoods) to use and carry forward final int numOriginalAltAlleles = vc.getAlternateAlleles().size(); @@ -1007,7 +1011,8 @@ public class GATKVariantContextUtils { final int revTrim = trimReverse ? computeReverseClipping(inputVC.getAlleles(), inputVC.getReference().getDisplayString().getBytes()) : 0; final VariantContext revTrimVC = trimAlleles(inputVC, -1, revTrim); final int fwdTrim = trimForward ? computeForwardClipping(revTrimVC.getAlleles()) : -1; - return trimAlleles(revTrimVC, fwdTrim, 0); + final VariantContext vc= trimAlleles(revTrimVC, fwdTrim, 0); + return vc; } /**