示例#1
0
 protected IEnumerable<CNVCall> GetCnvCallsFromVcf(string vcfPath) 
 {
     using (VcfReader reader = new VcfReader(vcfPath, false))
     {
         foreach (VcfVariant variant in reader.GetVariants())
         {
             int end;
             int CN = GetCopyNumber(variant, out end);
             yield return new CNVCall(variant.ReferenceName, variant.ReferencePosition, end, CN);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Load the somatic SNV output (from Strelka), and use it to dervie an estimate of overall purity.
        /// Reference: https://ukch-confluence.illumina.com/display/collab/Estimate+purity+of+tumour+samples+using+somatic+SNVs
        /// </summary>
        protected double EstimatePurityFromSomaticSNVs()
        {
            Dictionary<string, List<CanvasSegment>> segmentsByChromosome = CanvasSegment.GetSegmentsByChromosome(Segments);
            int recordCount = 0;
            List<float> variantFrequencies = new List<float>();
            using (VcfReader reader = new VcfReader(this.SomaticVCFPath))
            {
                foreach (VcfVariant variant in reader.GetVariants())
                {
                    recordCount++;
                    // Skip non-PF variants:
                    if (variant.Filters != "PASS") continue;
                    // Skip everything but SNVs:
                    if (variant.ReferenceAllele.Length > 1 || variant.VariantAlleles.Length != 1 || variant.VariantAlleles[0].Length != 1
                        || variant.VariantAlleles[0] == ".")
                    {
                        continue;
                    }

                    string refTagName = string.Format("{0}U", variant.ReferenceAllele[0]);
                    string altTagName = string.Format("{0}U", variant.VariantAlleles[0][0]);
                    string[] counts = variant.Genotypes.Last()[refTagName].Split(',');
                    int refCount = 0;
                    foreach (string bit in counts) refCount += int.Parse(bit);
                    int altCount = 0;
                    counts = variant.Genotypes.Last()[altTagName].Split(',');
                    foreach (string bit in counts) altCount += int.Parse(bit);
                    float VF = altCount / (float)(altCount + refCount);
                    if (VF >= 0.5) continue;
                    variantFrequencies.Add(VF);
                }
            }
            Console.WriteLine(">>>Loaded {0} somatic variants; saved {1} somatic SNV frequencies", recordCount, variantFrequencies.Count);
            // Don't bother providing an estimate if we have very few events:
            if (variantFrequencies.Count < 100)
            {
                return double.NaN;
            }
            double mean = variantFrequencies.Average();
            double estimatedPurity = Math.Min(1, mean * 2);
            Console.WriteLine(">>>Estimated tumor purity of {0} from somatic SNV calls", estimatedPurity);

            return estimatedPurity;
        }
示例#3
0
        protected IEnumerable<CNVCall> GetCnvCallsFromVcf(string vcfPath, bool includePassingOnly)
        {
            using (VcfReader reader = new VcfReader(vcfPath, false))
            {
                foreach (VcfVariant variant in reader.GetVariants())
                {

                    int end;
                    int CN = GetCopyNumber(variant, out end);
                    if (includePassingOnly && variant.Filters != "PASS") continue;
                    yield return new CNVCall(variant.ReferenceName, variant.ReferencePosition, end, CN);
                }
            }
        }
示例#4
0
		/// <summary>
		/// Load a list of all variants in a file.  This is memory-intensive; don't do this for whole-genome vcf files!
		/// </summary>
		public static List<VcfVariant> GetAllVariantsInFile(string vcfPath)
		{
			List<VcfVariant> allVariants = new List<VcfVariant>();
			using (VcfReader reader = new VcfReader(vcfPath))
			{
				foreach (VcfVariant variant in reader.GetVariants())
				{
					allVariants.Add(variant);
				}
			}
			return allVariants;
		}