Exemple #1
0
		/// <summary>
		/// Update the attributes of the attributes map given the VariantContext to reflect the
		/// proper chromosome-based VCF tags
		/// </summary>
		/// <param name="vc">          the VariantContext </param>
		/// <param name="attributes">  the attributes map to populate; must not be null; may contain old values </param>
		/// <param name="removeStaleValues"> should we remove stale values from the mapping? </param>
		/// <param name="founderIds"> - Set of founders Ids to take into account. AF and FC will be calculated over the founders.
		///                  If empty or null, counts are generated for all samples as unrelated individuals </param>
		/// <returns> the attributes map provided as input, returned for programming convenience </returns>
		public static IDictionary<string, object> CalculateChromosomeCounts (VariantContext vc, IDictionary<string, object> attributes, bool removeStaleValues, ISet<string> founderIds)
		{
			int AN = vc.CalledChrCount;

			// if everyone is a no-call, remove the old attributes if requested
			if (AN == 0 && removeStaleValues) {
				if (attributes.ContainsKey (VCFConstants.ALLELE_COUNT_KEY)) {
					attributes.Remove (VCFConstants.ALLELE_COUNT_KEY);
				}
				if (attributes.ContainsKey (VCFConstants.ALLELE_FREQUENCY_KEY)) {
					attributes.Remove (VCFConstants.ALLELE_FREQUENCY_KEY);
				}
				if (attributes.ContainsKey (VCFConstants.ALLELE_NUMBER_KEY)) {
					attributes.Remove (VCFConstants.ALLELE_NUMBER_KEY);
				}
				return attributes;
			}

			if (vc.HasGenotypes) {
				attributes [VCFConstants.ALLELE_NUMBER_KEY] = AN;

				// if there are alternate alleles, record the relevant tags
				if (vc.AlternateAlleles.Count > 0) {
					List<double> alleleFreqs = new List<double> ();
					List<int> alleleCounts = new List<int> ();
					List<int> foundersAlleleCounts = new List<int> ();
					double totalFoundersChromosomes = (double)vc.GetCalledChrCount (founderIds);
					int foundersAltChromosomes;
					foreach (Allele allele in vc.AlternateAlleles) {
						foundersAltChromosomes = vc.GetCalledChrCount (allele, founderIds);
						alleleCounts.Add (vc.GetCalledChrCount (allele));
						foundersAlleleCounts.Add (foundersAltChromosomes);
						if (AN == 0) {
							alleleFreqs.Add (0.0);
						} else {
							double freq = (double)foundersAltChromosomes / totalFoundersChromosomes;
							alleleFreqs.Add (freq);
						}
					}
					if (alleleCounts.Count == 1) {
						attributes [VCFConstants.ALLELE_COUNT_KEY] = alleleCounts [0];
					} else {
						attributes [VCFConstants.ALLELE_COUNT_KEY] = alleleCounts;
					}
					if (alleleFreqs.Count == 1) {
						attributes [VCFConstants.ALLELE_FREQUENCY_KEY] = alleleFreqs [0];
					} else {
						attributes [VCFConstants.ALLELE_FREQUENCY_KEY] = alleleFreqs;
					}
				} else {
					// if there's no alt AC and AF shouldn't be present
					attributes.Remove (VCFConstants.ALLELE_COUNT_KEY);
					attributes.Remove (VCFConstants.ALLELE_FREQUENCY_KEY);
				}
			}
			return attributes;
		}
Exemple #2
0
        /// <summary>
        /// Update the attributes of the attributes map given the VariantContext to reflect the
        /// proper chromosome-based VCF tags
        /// </summary>
        /// <param name="vc">          the VariantContext </param>
        /// <param name="attributes">  the attributes map to populate; must not be null; may contain old values </param>
        /// <param name="removeStaleValues"> should we remove stale values from the mapping? </param>
        /// <param name="founderIds"> - Set of founders Ids to take into account. AF and FC will be calculated over the founders.
        ///                  If empty or null, counts are generated for all samples as unrelated individuals </param>
        /// <returns> the attributes map provided as input, returned for programming convenience </returns>
        public static IDictionary <string, object> CalculateChromosomeCounts(VariantContext vc, IDictionary <string, object> attributes, bool removeStaleValues, ISet <string> founderIds)
        {
            int AN = vc.CalledChrCount;

            // if everyone is a no-call, remove the old attributes if requested
            if (AN == 0 && removeStaleValues)
            {
                if (attributes.ContainsKey(VCFConstants.ALLELE_COUNT_KEY))
                {
                    attributes.Remove(VCFConstants.ALLELE_COUNT_KEY);
                }
                if (attributes.ContainsKey(VCFConstants.ALLELE_FREQUENCY_KEY))
                {
                    attributes.Remove(VCFConstants.ALLELE_FREQUENCY_KEY);
                }
                if (attributes.ContainsKey(VCFConstants.ALLELE_NUMBER_KEY))
                {
                    attributes.Remove(VCFConstants.ALLELE_NUMBER_KEY);
                }
                return(attributes);
            }

            if (vc.HasGenotypes)
            {
                attributes [VCFConstants.ALLELE_NUMBER_KEY] = AN;

                // if there are alternate alleles, record the relevant tags
                if (vc.AlternateAlleles.Count > 0)
                {
                    List <double> alleleFreqs              = new List <double> ();
                    List <int>    alleleCounts             = new List <int> ();
                    List <int>    foundersAlleleCounts     = new List <int> ();
                    double        totalFoundersChromosomes = (double)vc.GetCalledChrCount(founderIds);
                    int           foundersAltChromosomes;
                    foreach (Allele allele in vc.AlternateAlleles)
                    {
                        foundersAltChromosomes = vc.GetCalledChrCount(allele, founderIds);
                        alleleCounts.Add(vc.GetCalledChrCount(allele));
                        foundersAlleleCounts.Add(foundersAltChromosomes);
                        if (AN == 0)
                        {
                            alleleFreqs.Add(0.0);
                        }
                        else
                        {
                            double freq = (double)foundersAltChromosomes / totalFoundersChromosomes;
                            alleleFreqs.Add(freq);
                        }
                    }
                    if (alleleCounts.Count == 1)
                    {
                        attributes [VCFConstants.ALLELE_COUNT_KEY] = alleleCounts [0];
                    }
                    else
                    {
                        attributes [VCFConstants.ALLELE_COUNT_KEY] = alleleCounts;
                    }
                    if (alleleFreqs.Count == 1)
                    {
                        attributes [VCFConstants.ALLELE_FREQUENCY_KEY] = alleleFreqs [0];
                    }
                    else
                    {
                        attributes [VCFConstants.ALLELE_FREQUENCY_KEY] = alleleFreqs;
                    }
                }
                else
                {
                    // if there's no alt AC and AF shouldn't be present
                    attributes.Remove(VCFConstants.ALLELE_COUNT_KEY);
                    attributes.Remove(VCFConstants.ALLELE_FREQUENCY_KEY);
                }
            }
            return(attributes);
        }