diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/phasing/PhasingUtils.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/phasing/PhasingUtils.java
index 6a4adfdf3..df70f8458 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/phasing/PhasingUtils.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/phasing/PhasingUtils.java
@@ -58,44 +58,33 @@ import org.broadinstitute.gatk.utils.GenomeLocParser;
import org.broadinstitute.gatk.utils.Utils;
import org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils;
import htsjdk.variant.vcf.VCFConstants;
-import org.broadinstitute.gatk.utils.exceptions.ReviewedGATKException;
import htsjdk.variant.variantcontext.*;
import java.util.*;
/**
- * [Short one sentence description of this walker]
- *
- *
- * [Functionality of this walker]
- *
- *
- * Input
- *
- * [Input description]
- *
- *
- * Output
- *
- * [Output description]
- *
- *
- * Examples
- *
- * java
- * -jar GenomeAnalysisTK.jar
- * -T $WalkerName
- *
- *
- * @author Your Name
- * @since Date created
+ * Utility class for phasing analysis
*/
class PhasingUtils {
+
+ /**
+ * Merge variants into a multi-nucleotide polymorphism (MNP)
+ *
+ * @param genomeLocParser parse the genome locations
+ * @param vc1 variant context 1
+ * @param vc2 variant context 2
+ * @param referenceFile sequence file containing the reference genome
+ * @param alleleMergeRule rule for merging variants
+ * @return merged variant or null if the variants are NOT an SNP or MNP, on the same contig, variant location 1 is the same or after the variant location 2,
+ * their genotypes do NOT have the same number of chromosomes, haplotype, number of attributes as chromosomes, are both hetrozygous or do not abide by the merge rule
+ */
static VariantContext mergeIntoMNP(GenomeLocParser genomeLocParser, VariantContext vc1, VariantContext vc2, ReferenceSequenceFile referenceFile, AlleleMergeRule alleleMergeRule) {
+
+ // Check if variants are an SNP or MNP, on the same contig, variant location 1 is not before variant location 2
if (!mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2))
return null;
- // Check that it's logically possible to merge the VCs:
+ // Check if variant genotypes have the same number of chromosomes, haplotype, number of attributes as chromosomes, and either genotype is homozygous
if (!allSamplesAreMergeable(vc1, vc2))
return null;
@@ -106,32 +95,50 @@ class PhasingUtils {
return reallyMergeIntoMNP(vc1, vc2, referenceFile);
}
- // Assumes: alleleSegregationIsKnown(gt1, gt2)
+ /**
+ * Find the alleles with the same haplotype
+ * assumes alleleSegregationIsKnown
+ * TODO - should alleleSegregationIsKnown be called within this method?
+ *
+ * @param gt1 genotype 1
+ * @param gt2 genotype 2
+ * @return gt1 and gt2 alleles with the same haplotype
+ */
static SameHaplotypeAlleles matchHaplotypeAlleles(final Genotype gt1, final Genotype gt2) {
+
final SameHaplotypeAlleles hapAlleles = new SameHaplotypeAlleles();
- final int nalleles = gt1.getPloidy();
- final Allele[] site1AllelesArray = gt1.getAlleles().toArray(new Allele[nalleles]);
- final Allele[] site2AllelesArray = gt2.getAlleles().toArray(new Allele[nalleles]);
+ // Get the alleles
+ final int numAlleles = gt1.getPloidy();
+ final Allele[] site1AllelesArray = gt1.getAlleles().toArray(new Allele[numAlleles]);
+ final Allele[] site2AllelesArray = gt2.getAlleles().toArray(new Allele[numAlleles]);
- final int[] site1ToSite2Inds = new int[nalleles];
+ // locations of the same HP attribute in gt2 to gt2
+ final int[] site1ToSite2Inds = new int[numAlleles];
+
+ // If both genotypes have read-backed phasing haplotype identifiers (HP)
+ // Find the gt1 and gt2 alleles with the same haplotpe
if (gt1.hasAnyAttribute(ReadBackedPhasing.HP_KEY) && gt2.hasAnyAttribute(ReadBackedPhasing.HP_KEY)) {
final String[] hp1 = (String[]) gt1.getAnyAttribute(ReadBackedPhasing.HP_KEY);
final String[] hp2 = (String[]) gt2.getAnyAttribute(ReadBackedPhasing.HP_KEY);
- final HashMap HPnameToSite1Inds = new HashMap();
+ // Map of HP attribute to it's array index
+ final HashMap hpNameToSite1Inds = new HashMap();
+
+ // Hp name to index
for (int ind1 = 0; ind1 < hp1.length; ++ind1) {
- final String h1 = hp1[ind1];
- HPnameToSite1Inds.put(h1, ind1);
+ hpNameToSite1Inds.put(hp1[ind1], ind1);
}
+ // Find the index of the gt2 HP attribute in gt1 HP attribute array
for (int ind2 = 0; ind2 < hp2.length; ++ind2) {
- final String h2 = hp2[ind2];
- final int ind1 = HPnameToSite1Inds.get(h2);
+ final int ind1 = hpNameToSite1Inds.get(hp2[ind2]);
+ // attributes are not in the same position in both genotypes
if (ind2 != ind1)
hapAlleles.requiresSwap = true;
- site1ToSite2Inds[ind1] = ind2; // this is OK, since allSamplesAreMergeable()
+
+ site1ToSite2Inds[ind1] = ind2;
}
}
else { // gt1.isHom() || gt2.isHom() ; so, we trivially merge the corresponding alleles
@@ -139,31 +146,46 @@ class PhasingUtils {
site1ToSite2Inds[ind] = ind;
}
- for (int ind1 = 0; ind1 < nalleles; ++ind1) {
+ // Get the alleles for gt1 and gt2 with the same haplotype
+ for (int ind1 = 0; ind1 < numAlleles; ++ind1) {
final Allele all1 = site1AllelesArray[ind1];
final int ind2 = site1ToSite2Inds[ind1];
final Allele all2 = site2AllelesArray[ind2]; // this is OK, since alleleSegregationIsKnown(gt1, gt2)
+ // add the 2 alleles
hapAlleles.hapAlleles.add(new AlleleOneAndTwo(all1, all2));
}
return hapAlleles;
}
+ /**
+ * Merge variants into a multi-nucleotide polymorphism (MNP)
+ *
+ * @param vc1 variant context 1
+ * @param vc2 variant context 2
+ * @param referenceFile sequence file containing the reference genome
+ * @return variant with the merged MNP
+ */
static VariantContext reallyMergeIntoMNP(VariantContext vc1, VariantContext vc2, ReferenceSequenceFile referenceFile) {
final int startInter = vc1.getEnd() + 1;
final int endInter = vc2.getStart() - 1;
byte[] intermediateBases = null;
+
+ // get bases between vc1 and vc2 in the reference sequence
if (startInter <= endInter) {
intermediateBases = referenceFile.getSubsequenceAt(vc1.getChr(), startInter, endInter).getBases();
StringUtil.toUpperCase(intermediateBases);
}
+
+ // merge the reference bases with vc1 and vc2
final MergedAllelesData mergeData = new MergedAllelesData(intermediateBases, vc1, vc2); // ensures that the reference allele is added
final GenotypesContext mergedGenotypes = GenotypesContext.create();
for (final Genotype gt1 : vc1.getGenotypes()) {
final Genotype gt2 = vc2.getGenotype(gt1.getSampleName());
+ // Alleles with the same haplotype
final SameHaplotypeAlleles hapAlleles = matchHaplotypeAlleles(gt1, gt2);
boolean isPhased = gt1.isPhased() && gt2.isPhased();
@@ -180,6 +202,7 @@ class PhasingUtils {
final Map mergedGtAttribs = new HashMap();
+ // get the min read backed phasing quality
double PQ = Double.MAX_VALUE;
if (gt1.hasAnyAttribute(ReadBackedPhasing.PQ_KEY)) {
PQ = Math.min(PQ, (double) gt1.getAnyAttribute(ReadBackedPhasing.PQ_KEY));
@@ -190,6 +213,7 @@ class PhasingUtils {
if (PQ != Double.MAX_VALUE)
mergedGtAttribs.put(ReadBackedPhasing.PQ_KEY, PQ);
+ // get the read backed phasing phasing haplotype identifier
if (gt1.hasAnyAttribute(ReadBackedPhasing.HP_KEY)) {
mergedGtAttribs.put(ReadBackedPhasing.HP_KEY, gt1.getAnyAttribute(ReadBackedPhasing.HP_KEY));
}
@@ -197,44 +221,65 @@ class PhasingUtils {
mergedGtAttribs.put(ReadBackedPhasing.HP_KEY, gt2.getAnyAttribute(ReadBackedPhasing.HP_KEY));
}
+ // make the merged genotype
final Genotype mergedGt = new GenotypeBuilder(gt1.getSampleName(), mergedAllelesForSample).log10PError(mergedGQ).attributes(mergedGtAttribs).phased(isPhased).make();
mergedGenotypes.add(mergedGt);
}
+ // get the merged name
final String mergedName = mergeVariantContextNames(vc1.getSource(), vc2.getSource());
final double mergedLog10PError = Math.min(vc1.getLog10PError(), vc2.getLog10PError());
final Set mergedFilters = new HashSet(); // Since vc1 and vc2 were unfiltered, the merged record remains unfiltered
final Map mergedAttribs = mergeVariantContextAttributes(vc1, vc2);
- // ids
+ // get the merged ID
final List mergedIDs = new ArrayList();
if ( vc1.hasID() ) mergedIDs.add(vc1.getID());
if ( vc2.hasID() ) mergedIDs.add(vc2.getID());
final String mergedID = mergedIDs.isEmpty() ? VCFConstants.EMPTY_ID_FIELD : Utils.join(VCFConstants.ID_FIELD_SEPARATOR, mergedIDs);
+ // make the merged variant context
final VariantContextBuilder mergedBuilder = new VariantContextBuilder(mergedName, vc1.getChr(), vc1.getStart(), vc2.getEnd(), mergeData.getAllMergedAlleles()).id(mergedID).genotypes(mergedGenotypes).log10PError(mergedLog10PError).filters(mergedFilters).attributes(mergedAttribs);
VariantContextUtils.calculateChromosomeCounts(mergedBuilder, true);
return mergedBuilder.make();
}
+ /**
+ * Merge variant context names
+ *
+ * @param name1 variant context 1 name
+ * @param name2 variant context 2 name
+ * @return merged variant names (name1_name2)
+ */
static String mergeVariantContextNames(String name1, String name2) {
return name1 + "_" + name2;
}
+ /**
+ * Get preset attributes and that are in vc1 or vc2
+ * TODO: Will always return an empty map because MERGE_OR_ATTRIBS is empty
+ *
+ * @param vc1 variant context 1
+ * @param vc2 variant context 2
+ * @return merged attributes in vc1 or vc2
+ */
static Map mergeVariantContextAttributes(VariantContext vc1, VariantContext vc2) {
+ // Map of attribute name to value
Map mergedAttribs = new HashMap();
final List vcList = new LinkedList();
vcList.add(vc1);
vcList.add(vc2);
+ // Attribute of interest
//String[] MERGE_OR_ATTRIBS = {VCFConstants.DBSNP_KEY};
final String[] MERGE_OR_ATTRIBS = {};
for (String orAttrib : MERGE_OR_ATTRIBS) {
boolean attribVal = false;
for (VariantContext vc : vcList) {
+ // Does the variant have the attribute?
attribVal = vc.getAttributeAsBoolean(orAttrib, false);
- if (attribVal) // already true, so no reason to continue:
+ if ( attribVal ) // already true, so no reason to continue:
break;
}
mergedAttribs.put(orAttrib, attribVal);
@@ -243,6 +288,15 @@ class PhasingUtils {
return mergedAttribs;
}
+ /**
+ * Check if variants can be merged into the multi-nucleotide polymorphism (MNP)
+ *
+ * @param genomeLocParser parse the genome locations
+ * @param vc1 variant context 1
+ * @param vc2 variant context 2
+ * @return true if variants are an SNP or MNP, on the same contig, variant location 1 is not before variant location 2, unfiltered, from the same sample set and are called,
+ * false otherwise
+ */
static boolean mergeIntoMNPvalidationCheck(GenomeLocParser genomeLocParser, VariantContext vc1, VariantContext vc2) {
// Can only merge "simple" base strings (i.e., SNPs or MNPs, but not indels):
final boolean vc1CanBeMerged = vc1.isSNP() || vc1.isMNP();
@@ -253,18 +307,23 @@ class PhasingUtils {
final GenomeLoc loc1 = GATKVariantContextUtils.getLocation(genomeLocParser, vc1);
final GenomeLoc loc2 = GATKVariantContextUtils.getLocation(genomeLocParser, vc2);
+ // Must be on same contig
if (!loc1.onSameContig(loc2))
return false;
+ // Variant 1 location must not be before variant context 2
if (!loc1.isBefore(loc2))
return false;
+ // Variants can not be filtered
if (vc1.isFiltered() || vc2.isFiltered())
return false;
- if (!vc1.getSampleNames().equals(vc2.getSampleNames())) // vc1, vc2 refer to different sample sets
+ // Variants must come from the same sample set
+ if (!vc1.getSampleNames().equals(vc2.getSampleNames()))
return false;
+ // All of the variant genotypes must be unfiltered and called
if (!allGenotypesAreUnfilteredAndCalled(vc1) || !allGenotypesAreUnfilteredAndCalled(vc2))
return false;
@@ -280,10 +339,19 @@ class PhasingUtils {
return true;
}
+ /**
+ * Check if can merge genotypes from the same sample
+ *
+ * @param vc1 variant context 1
+ * @param vc2 variant context 2
+ * @return true if variants are phased or either is a homozygous, false otherwise
+ */
static boolean allSamplesAreMergeable(VariantContext vc1, VariantContext vc2) {
- // Check that each sample's genotype in vc2 is uniquely appendable onto its genotype in vc1:
+ // Check that each sample's genotype in vc2 is uniquely appendable onto its genotype in vc1
for (final Genotype gt1 : vc1.getGenotypes()) {
final Genotype gt2 = vc2.getGenotype(gt1.getSampleName());
+ if ( gt2 == null ) // gt2 does not have sample name
+ return false;
if (!alleleSegregationIsKnown(gt1, gt2)) // can merge if: phased, or if either is a hom
return false;
@@ -292,46 +360,76 @@ class PhasingUtils {
return true;
}
+ /**
+ * Check if the allele segregation is known
+ *
+ * @param gt1 genotype 1
+ * @param gt2 genotype 2
+ * @return true if genotypes have the same number of chromosomes, haplotype, number of attributes
+ * as chromosomes, and either genotype is homozygous, false otherwise
+ */
static boolean alleleSegregationIsKnown(Genotype gt1, Genotype gt2) {
+ // If gt1 or gt2 do not have the same number of chromosomes, then can not be merged.
if (gt1.getPloidy() != gt2.getPloidy())
return false;
- // If gt1 or gt2 are hom, then could be MERGED:
+ // If gt1 or gt2 are homozygous, then could be merged.
if (gt1.isHom() || gt2.isHom())
return true;
- // Otherwise, need to check that alleles from gt1 can be matched up with alleles from gt2:
+ // If gt1 or gt2 do not have a read backed phasing haplotype, then can not be merged
if (!gt1.hasAnyAttribute(ReadBackedPhasing.HP_KEY) || !gt2.hasAnyAttribute(ReadBackedPhasing.HP_KEY))
return false;
+ // If gt1 or gt2 do not same number of HP attributes as chromosomes, then can not be merged.
final String[] hp1 = (String[]) gt1.getAnyAttribute(ReadBackedPhasing.HP_KEY);
final String[] hp2 = (String[]) gt2.getAnyAttribute(ReadBackedPhasing.HP_KEY);
if (hp1.length != gt1.getPloidy() || hp2.length != gt2.getPloidy())
return false;
- final String[] hp1Copy = Arrays.copyOf(hp1, hp1.length);
- final String[] hp2Copy = Arrays.copyOf(hp2, hp2.length);
+ // gt1 and gt2 must have the same read backed phasing haplotype identifier attributes to be merged
+ final String[] hp1Copy = Arrays.copyOf(hp1, hp1.length);
+ final String[] hp2Copy = Arrays.copyOf(hp2, hp2.length);
Arrays.sort(hp1Copy);
Arrays.sort(hp2Copy);
return (Arrays.equals(hp1Copy, hp2Copy)); // The haplotype names match (though possibly in a different order)
}
+ /**
+ * Check if some samples have double alternate alleles
+ *
+ * @param vc1 variant context 1
+ * @param vc2 variant context 2
+ * @return true if there is a sample with double alternate alleles, false otherwise
+ */
static boolean someSampleHasDoubleNonReferenceAllele(VariantContext vc1, VariantContext vc2) {
for (final Genotype gt1 : vc1.getGenotypes()) {
+ // gt2 from the same sample as gt1
final Genotype gt2 = vc2.getGenotype(gt1.getSampleName());
- final SameHaplotypeAlleles hapAlleles = matchHaplotypeAlleles(gt1, gt2);
- for (AlleleOneAndTwo all1all2 : hapAlleles.hapAlleles) {
- if (all1all2.all1.isNonReference() && all1all2.all2.isNonReference()) // corresponding alleles are alternate
- return true;
+ if ( gt2 != null ) {
+ // Find the alleles with the same haplotype
+ final SameHaplotypeAlleles hapAlleles = matchHaplotypeAlleles(gt1, gt2);
+
+ // Find corresponding alternate alleles
+ for (AlleleOneAndTwo all1all2 : hapAlleles.hapAlleles) {
+ if (all1all2.all1.isNonReference() && all1all2.all2.isNonReference())
+ return true;
+ }
}
}
return false;
}
+ /**
+ * Check that alleles at vc1 and at vc2 always segregate together in all samples (including reference)
+ *
+ * @param vc1 variant context 1
+ * @param vc2 variant context 2
+ * @return true if alleles segregate together, false otherwise
+ */
static boolean doubleAllelesSegregatePerfectlyAmongSamples(VariantContext vc1, VariantContext vc2) {
- // Check that Alleles at vc1 and at vc2 always segregate together in all samples (including reference):
final Map allele1ToAllele2 = new HashMap();
final Map allele2ToAllele1 = new HashMap();
@@ -365,6 +463,9 @@ class PhasingUtils {
return true;
}
+ /**
+ * Class for variants merging rules
+ */
abstract static class AlleleMergeRule {
// vc1, vc2 are ONLY passed to allelesShouldBeMerged() if mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2) AND allSamplesAreMergeable(vc1, vc2):
abstract public boolean allelesShouldBeMerged(VariantContext vc1, VariantContext vc2);
@@ -374,8 +475,15 @@ class PhasingUtils {
}
}
+ /**
+ * Class for storing the alleles with the same haplotype
+ */
static class SameHaplotypeAlleles {
+
+ /// Alleles are not in the same order
public boolean requiresSwap;
+
+ /// Lisgt of gthe 2 alleles with the same haplotype
public List hapAlleles;
public SameHaplotypeAlleles() {
@@ -384,19 +492,41 @@ class PhasingUtils {
}
}
+ /**
+ * Class for holding 2 alleles
+ */
static class AlleleOneAndTwo {
+ /// allele 1
private Allele all1;
+ /// allele2
private Allele all2;
+ /**
+ * Constructor
+ *
+ * @param all1 allele 1
+ * @param all2 allele 2
+ */
public AlleleOneAndTwo(Allele all1, Allele all2) {
this.all1 = all1;
this.all2 = all2;
}
+ /**
+ * Get the hah code for alleles 1 and 2
+ *
+ * @return hash code for alleles 1 and 2
+ */
public int hashCode() {
return all1.hashCode() + all2.hashCode();
}
+ /**
+ * Check if equal to another 2 alleles
+ *
+ * @param other allele to compare to
+ * @return true if equal, false otherwise
+ */
public boolean equals(Object other) {
if (!(other instanceof AlleleOneAndTwo))
return false;
@@ -406,28 +536,60 @@ class PhasingUtils {
}
}
+ /**
+ * Class for merging alleles
+ */
static class MergedAllelesData {
+ /// merged alleles
private Map mergedAlleles;
+
+ /// bases between the alleles
private byte[] intermediateBases;
+
+ /// number of bases between the alleles
private int intermediateLength;
+ /**
+ * Constructor
+ *
+ * @param intermediateBases array of bases
+ * @param vc1 variant context 1
+ * @param vc2 variant context 2
+ */
public MergedAllelesData(byte[] intermediateBases, VariantContext vc1, VariantContext vc2) {
this.mergedAlleles = new HashMap(); // implemented equals() and hashCode() for AlleleOneAndTwo
this.intermediateBases = intermediateBases;
this.intermediateLength = this.intermediateBases != null ? this.intermediateBases.length : 0;
+ // merge the reference bases from vc1 before and vc2 after the reference (intermediate) bases
this.ensureMergedAllele(vc1.getReference(), vc2.getReference(), true);
}
+ /**
+ * Ensure that the alleles are merged. The merged allele is alternate.
+ *
+ * @param all1 allele 1
+ * @param all2 allele 2
+ * @return merged allele
+ */
public Allele ensureMergedAllele(Allele all1, Allele all2) {
return ensureMergedAllele(all1, all2, false); // false <-> since even if all1+all2 = reference, it was already created in the constructor
}
- private Allele ensureMergedAllele(Allele all1, Allele all2, boolean creatingReferenceForFirstTime) {
+ /**
+ * Ensure that the alleles are merged.
+ * all1 is before all2, if there is a gap between them, join with the intermediate bases
+ *
+ * @param all1 allele 1
+ * @param all2 allele 2
+ * @param isRef if true, merged allele is reference, if false, merged allele is alternate
+ * @return merged allele
+ */
+ private Allele ensureMergedAllele(Allele all1, Allele all2, boolean isRef) {
AlleleOneAndTwo all12 = new AlleleOneAndTwo(all1, all2);
Allele mergedAllele = mergedAlleles.get(all12);
- if (mergedAllele == null) {
+ if (mergedAllele == null) {
final byte[] bases1 = all1.getBases();
final byte[] bases2 = all2.getBases();
@@ -437,13 +599,18 @@ class PhasingUtils {
System.arraycopy(intermediateBases, 0, mergedBases, bases1.length, intermediateLength);
System.arraycopy(bases2, 0, mergedBases, bases1.length + intermediateLength, bases2.length);
- mergedAllele = Allele.create(mergedBases, creatingReferenceForFirstTime);
+ mergedAllele = Allele.create(mergedBases, isRef);
mergedAlleles.put(all12, mergedAllele);
}
return mergedAllele;
}
+ /**
+ * Get all merged alleles
+ *
+ * @return set of merged alleles values
+ */
public Set getAllMergedAlleles() {
return new HashSet(mergedAlleles.values());
}
diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/phasing/PhasingUtilsUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/phasing/PhasingUtilsUnitTest.java
new file mode 100644
index 000000000..26a4a92f7
--- /dev/null
+++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/phasing/PhasingUtilsUnitTest.java
@@ -0,0 +1,288 @@
+/*
+* 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 415 Main Street, 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 GATK3 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute.org/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. LICENSEE hereby automatically grants to BROAD a non-exclusive, royalty-free, irrevocable license to any LICENSEE bug fixes or modifications to the PROGRAM with unlimited rights to sublicense and/or distribute. LICENSEE agrees to provide any such modifications and bug fixes to BROAD promptly upon their creation.
+* 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. PHONE-HOME FEATURE
+* LICENSEE expressly acknowledges that the PROGRAM contains an embedded automatic reporting system (“PHONE-HOME”) which is enabled by default upon download. Unless LICENSEE requests disablement of PHONE-HOME, LICENSEE agrees that BROAD may collect limited information transmitted by PHONE-HOME regarding LICENSEE and its use of the PROGRAM. Such information shall include LICENSEE’S user identification, version number of the PROGRAM and tools being run, mode of analysis employed, and any error reports generated during run-time. Collection of such information is used by BROAD solely to monitor usage rates, fulfill reporting requirements to BROAD funding agencies, drive improvements to the PROGRAM, and facilitate adjustments to PROGRAM-related documentation.
+*
+* 4. 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-2014 Broad Institute, Inc.
+* Notice of attribution: The GATK3 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.
+*
+* 5. 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.
+*
+* 6. 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.
+*
+* 7. 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.
+*
+* 8. MISCELLANEOUS
+* 8.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.
+* 8.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.
+* 8.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.
+* 8.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.
+* 8.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.
+* 8.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.
+* 8.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.gatk.tools.walkers.phasing;
+
+import htsjdk.samtools.reference.ReferenceSequenceFile;
+import htsjdk.variant.variantcontext.*;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.broadinstitute.gatk.utils.GenomeLocParser;
+import org.broadinstitute.gatk.utils.BaseTest;
+import org.broadinstitute.gatk.utils.fasta.CachingIndexedFastaSequenceFile;
+import org.testng.Assert;
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
+
+class AlwaysTrueMergeRule extends PhasingUtils.AlleleMergeRule {
+ public boolean allelesShouldBeMerged(VariantContext vc1, VariantContext vc2) {
+ return true;
+ }
+}
+
+public class PhasingUtilsUnitTest extends BaseTest {
+
+ private final int start = 10;
+ GenomeLocParser genomeLocParser;
+ private ReferenceSequenceFile referenceFile;
+ private Genotype genotype1;
+ private Genotype genotype2;
+ private String contig;
+ private List alleleList1;
+ private List alleleList2;
+ VariantContext vc1;
+ VariantContext vc2;
+
+ @BeforeSuite
+ public void init() throws FileNotFoundException {
+ referenceFile = new CachingIndexedFastaSequenceFile(new File(b37KGReference));
+ genomeLocParser = new GenomeLocParser(referenceFile);
+ alleleList1 = Arrays.asList(Allele.create("T", true), Allele.create("C", false));
+ alleleList2 = Arrays.asList(Allele.create("G", true), Allele.create("A", false));
+ genotype1 = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).attribute("PQ", 100.0).alleles(alleleList1).make();
+ genotype2 = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-2", "10-1"}).attribute("PQ", 200.0).alleles(alleleList2).make();
+ contig = new String("1");
+ vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype1).make();
+ vc2 = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype2).make();
+ }
+
+ @Test
+ public void TestMatchHaplotypeAllelesKeyHP() {
+
+ final PhasingUtils.SameHaplotypeAlleles sameHaplotypeAlleles = PhasingUtils.matchHaplotypeAlleles(genotype1, genotype2);
+
+ final PhasingUtils.SameHaplotypeAlleles sameHaplotypeAllelesExpected = new PhasingUtils.SameHaplotypeAlleles();
+ sameHaplotypeAllelesExpected.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("T", true), Allele.create("A", false)));
+ sameHaplotypeAllelesExpected.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("C", false), Allele.create("G", true)));
+ sameHaplotypeAllelesExpected.requiresSwap = true;
+
+ Assert.assertEquals(sameHaplotypeAlleles.hapAlleles, sameHaplotypeAllelesExpected.hapAlleles);
+ Assert.assertEquals(sameHaplotypeAlleles.requiresSwap, sameHaplotypeAllelesExpected.requiresSwap);
+ }
+
+ @Test
+ public void TestMatchHaplotypeAllelesNoKeyHP() {
+
+ final Genotype genotypeNoKeyHP1 = new GenotypeBuilder().name("TC").alleles(alleleList1).make();
+ final Genotype genotypeNoKeyHP2 = new GenotypeBuilder().name("GA").alleles(alleleList2).make();
+
+ final PhasingUtils.SameHaplotypeAlleles sameHaplotypeAlleles = PhasingUtils.matchHaplotypeAlleles(genotypeNoKeyHP1, genotypeNoKeyHP2);
+ final PhasingUtils.SameHaplotypeAlleles sameHaplotypeAllelesExpected = new PhasingUtils.SameHaplotypeAlleles();
+ sameHaplotypeAllelesExpected.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("T", true), Allele.create("G", true)));
+ sameHaplotypeAllelesExpected.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("C", false), Allele.create("A", false)));
+ Assert.assertEquals(sameHaplotypeAlleles.hapAlleles, sameHaplotypeAllelesExpected.hapAlleles);
+ Assert.assertEquals(sameHaplotypeAlleles.requiresSwap, sameHaplotypeAllelesExpected.requiresSwap);
+ }
+
+ @Test
+ public void TestMergeIntoMNPvalidationTrueCheck() {
+ Assert.assertTrue(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2));
+ }
+
+ @Test
+ public void TestMergeIntoMNPvalidationCheckLocBefore() {
+ final VariantContext vc1before = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start+1).stop(start+1).alleles(alleleList1).make();
+ final VariantContext vc2after = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start).stop(start).alleles(alleleList2).make();
+ Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1before, vc2after));
+ }
+
+ @Test
+ public void TestMergeIntoMNPvalidationFiltered() {
+ final List filters = Arrays.asList("filter");
+ final Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList1).filters(filters).make();
+ final VariantContext vc = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype).make();
+ Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc, vc2));
+ }
+
+ @Test
+ public void TestMergeIntoMNPvalidationFilterNoCall() {
+ final List filters = Arrays.asList("filter");
+ final List alleleList = Arrays.asList(Allele.create("T", true), Allele.create(".", false));
+ final Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList).filters(filters).make();
+ final VariantContext vc = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype).make();
+ Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc, vc2));
+ }
+
+ @Test
+ public void TestMergeIntoMNPvalidationDiffSampleNames() {
+ final Genotype genotype = new GenotypeBuilder().name("sample1").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList1).make();
+ final VariantContext vc = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype).make();
+ Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc, vc2));
+ }
+
+ @Test
+ public void TestMergeIntoMNPvalidationDiffContigs() {
+ final String contig = new String("2");
+ final VariantContext vc = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype2).make();
+ Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc));
+ }
+
+ @Test
+ public void TestMergeVariantContextAttributes() {
+ Assert.assertEquals(0, PhasingUtils.mergeVariantContextAttributes(vc1, vc2).size());
+ }
+
+ @Test
+ public void TestAllSamplesAreMergeable() {
+ Assert.assertTrue(PhasingUtils.allSamplesAreMergeable(vc1, vc2));
+ }
+
+ @Test
+ public void TestAlleleSegregationIsKnown(){
+ Assert.assertTrue(PhasingUtils.alleleSegregationIsKnown(genotype1, genotype2));
+ }
+
+ @Test
+ public void TestSomeSampleHasDoubleNonReferenceAlleleTrue(){
+ Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList2).make();
+ VariantContext vc = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype).make();
+ Assert.assertTrue(PhasingUtils.someSampleHasDoubleNonReferenceAllele(vc1, vc));
+ }
+
+ @Test
+ public void TestSomeSampleHasDoubleNonReferenceAlleleFalse(){
+ Assert.assertFalse(PhasingUtils.someSampleHasDoubleNonReferenceAllele(vc1, vc2));
+ }
+
+ @Test
+ public void TestDoubleAllelesSegregatePerfectlyAmongSamples(){
+ final Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList2).make();
+ final VariantContext vc = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype).make();
+ Assert.assertTrue(PhasingUtils.doubleAllelesSegregatePerfectlyAmongSamples(vc1, vc));
+ }
+
+ @Test
+ public void TestMergeVariantContextNames() {
+ final String result = new String("A_B");
+ Assert.assertEquals(result, PhasingUtils.mergeVariantContextNames("A", "B"));
+ }
+
+ @Test
+ public void TestMergeIntoMNP(){
+ final AlwaysTrueMergeRule alleleMergeRule = new AlwaysTrueMergeRule();
+ final VariantContext vc = PhasingUtils.mergeIntoMNP(genomeLocParser, vc1, vc2, referenceFile, alleleMergeRule);
+
+ final List alleleList = Arrays.asList(Allele.create("TG", true), Allele.create("TA", false), Allele.create("CG", false));
+ final Map attributes = new HashMap(){{
+ put("AC", new ArrayList(Arrays.asList(1, 1)));
+ put("AF", new ArrayList(Arrays.asList(0.5, 0.5)));
+ put("AN", 2);
+ }};
+ final Map extendedAttributes = new HashMap(){{
+ put("PQ", 100.0); put("HP", new String[]{"10-1", "10-2"});
+ }};
+ final List alleleListMeged = Arrays.asList(Allele.create("TA"), Allele.create("CG"));
+ final Genotype genotype = new GenotypeBuilder().name("sample").attributes(extendedAttributes).alleles(alleleListMeged).make();
+ final VariantContext vcExpected = new VariantContextBuilder().chr(contig).id("id1;id2").source("TC_GA").start(start).stop(start+1).alleles(alleleList).genotypes(genotype).attributes(attributes).make();
+ Assert.assertTrue(genotype.sameGenotype(vcExpected.getGenotypes().get("sample")));
+ Assert.assertTrue(vcExpected.hasSameAllelesAs(vc));
+ Assert.assertEquals(vcExpected.getChr(), vc.getChr());
+ Assert.assertEquals(vcExpected.getStart(), vc.getStart());
+ Assert.assertEquals(vcExpected.getEnd(), vc.getEnd());
+ Assert.assertEquals(vcExpected.getID(), vc.getID());
+ Assert.assertEquals(vcExpected.getSource(), vc.getSource());
+ Assert.assertEquals(vcExpected.isFiltered(), vc.isFiltered());
+ Assert.assertEquals(vcExpected.getPhredScaledQual(), vc.getPhredScaledQual());
+ Assert.assertEquals(vcExpected.getAttribute("PQ"), vc.getAttribute("PQ"));
+ Assert.assertEquals(vcExpected.getAttribute("HP"), vc.getAttribute("HP"));
+ }
+
+ @Test
+ public void TestReallyMergeIntoMNP( ){
+ final VariantContext vc = PhasingUtils.reallyMergeIntoMNP(vc1, vc2, referenceFile);
+
+ final List alleleList = Arrays.asList(Allele.create("TG", true), Allele.create("TA", false), Allele.create("CG", false));
+ final Map attributes = new HashMap(){{
+ put("AC", new ArrayList(Arrays.asList(1, 1)));
+ put("AF", new ArrayList(Arrays.asList(0.5, 0.5)));
+ put("AN", 2);
+ }};
+ final Map extendedAttributes = new HashMap(){{
+ put("PQ", 100.0); put("HP", new String[]{"10-1", "10-2"});
+ }};
+ final List alleleListMeged = Arrays.asList(Allele.create("TA"), Allele.create("CG"));
+ final Genotype genotype = new GenotypeBuilder().name("sample").attributes(extendedAttributes).alleles(alleleListMeged).make();
+ final VariantContext vcExpected = new VariantContextBuilder().chr(contig).id("id1;id2").source("TC_GA").start(start).stop(start+1).alleles(alleleList).genotypes(genotype).attributes(attributes).make();
+ Assert.assertTrue(genotype.sameGenotype(vcExpected.getGenotypes().get("sample")));
+ Assert.assertTrue(vcExpected.hasSameAllelesAs(vc));
+ Assert.assertEquals(vcExpected.getChr(), vc.getChr());
+ Assert.assertEquals(vcExpected.getStart(), vc.getStart());
+ Assert.assertEquals(vcExpected.getEnd(), vc.getEnd());
+ Assert.assertEquals(vcExpected.getID(), vc.getID());
+ Assert.assertEquals(vcExpected.getSource(), vc.getSource());
+ Assert.assertEquals(vcExpected.isFiltered(), vc.isFiltered());
+ Assert.assertEquals(vcExpected.getPhredScaledQual(), vc.getPhredScaledQual());
+ Assert.assertEquals(vcExpected.getAttribute("PQ"), vc.getAttribute("PQ"));
+ Assert.assertEquals(vcExpected.getAttribute("HP"), vc.getAttribute("HP"));
+ }
+
+ @Test
+ public void TestAllGenotypesAreUnfilteredAndCalled(){
+ final VariantContext vc = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype1).make();
+ Assert.assertTrue(PhasingUtils.allGenotypesAreUnfilteredAndCalled(vc));
+ }
+
+ @Test
+ public void TestEnsureMergedAllele(){
+ byte[] intermediateBases = new byte[]{'A','T'};
+ final PhasingUtils.MergedAllelesData mergeData = new PhasingUtils.MergedAllelesData(intermediateBases, vc1, vc2);
+ final Allele allele = mergeData.ensureMergedAllele(Allele.create("T", true), Allele.create("C", true));
+ final Allele expectedAllele = Allele.create(new byte[]{'T', 'A', 'T', 'C'}, false);
+ Assert.assertEquals(allele, expectedAllele);
+ }
+
+}
diff --git a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/BaseTest.java b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/BaseTest.java
index 5689dbc4c..1669406c8 100644
--- a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/BaseTest.java
+++ b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/BaseTest.java
@@ -96,7 +96,6 @@ public abstract class BaseTest {
public static final String hg18Reference = "/seq/references/Homo_sapiens_assembly18/v0/Homo_sapiens_assembly18.fasta";
public static final String hg19Reference = "/seq/references/Homo_sapiens_assembly19/v1/Homo_sapiens_assembly19.fasta";
public static final String b36KGReference = "/humgen/1kg/reference/human_b36_both.fasta";
- //public static final String b37KGReference = "/Users/depristo/Desktop/broadLocal/localData/human_g1k_v37.fasta";
public static final String b37KGReference = "/humgen/1kg/reference/human_g1k_v37.fasta";
public static final String b37KGReferenceWithDecoy = "/humgen/gsa-hpprojects/GATK/bundle/current/b37/human_g1k_v37_decoy.fasta";
public static final String hg19RefereneWithChrPrefixInChromosomeNames = "/humgen/gsa-hpprojects/GATK/bundle/current/hg19/ucsc.hg19.fasta";