CanvasClean.EnrichmentUtilities.GetCountsByGC C# (CSharp) Method

GetCountsByGC() public static method

Assumes the bins are sorted by genomic coordinates
public static GetCountsByGC ( List bins, NexteraManifest manifest, List &countsByGC, List &counts ) : void
bins List Bins whose counts are to be normalized
manifest NexteraManifest
countsByGC List An array of lists. Each array element (0-100) will hold a list of counts whose bins have the same GC content.
counts List Will hold all of the autosomal counts present in 'bins'
return void
        public static void GetCountsByGC(List<GenomicBin> bins, NexteraManifest manifest, out List<float>[] countsByGC, out List<float> counts)
        {
            countsByGC = new List<float>[numberOfGCbins];
            counts = new List<float>(bins.Count);

            // Initialize the lists
            for (int i = 0; i < countsByGC.Length; i++)
                countsByGC[i] = new List<float>();

            foreach (GenomicBin bin in manifest == null ? bins : EnrichmentUtilities.GetOnTargetBins(bins, manifest))
            {
                if (!GenomeMetadata.SequenceMetadata.IsAutosome(bin.Chromosome)) { continue; }

                // Put the observed count in the GC-appropriate list.
                countsByGC[bin.GC].Add(bin.Count);

                // Add to the global list of counts.
                counts.Add(bin.Count);
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Perform a simple GC normalization.
        /// </summary>
        /// <param name="bins">Bins whose counts are to be normalized.</param>
        /// <param name="manifest"></param>
        static void NormalizeByGC(List <SampleGenomicBin> bins, NexteraManifest manifest = null)
        {
            // DebugPrintCountsByGC(bins, "CountsByGC-Before.txt");
            // An array of lists. Each array element (0-100) will hold a list of counts whose bins have the same GC content.
            List <float>[] countsByGC;

            // Will hold all of the autosomal counts present in 'bins'
            List <float> counts;

            EnrichmentUtilities.GetCountsByGC(bins, manifest, out countsByGC, out counts);

            double globalMedian = Utilities.Median(counts);

            double?[] medians = new double?[countsByGC.Length];

            // Compute the median count for each GC bin
            for (int gcBinIndex = 0; gcBinIndex < countsByGC.Length; gcBinIndex++)
            {
                if (countsByGC[gcBinIndex].Count >= defaultMinNumberOfBinsPerGC)
                {
                    medians[gcBinIndex] = Utilities.Median(countsByGC[gcBinIndex]);
                }
                else
                {
                    List <Tuple <float, float> > weightedCounts = GetWeightedCounts(countsByGC, gcBinIndex);
                    medians[gcBinIndex] = Utilities.WeightedMedian(weightedCounts);
                }
            }

            // Divide each count by the median count of bins with the same GC content
            for (int gcBinIndex = 0; gcBinIndex < bins.Count; gcBinIndex++)
            {
                double?median = medians[bins[gcBinIndex].GenomicBin.GC];
                if (median != null && median > 0)
                {
                    bins[gcBinIndex].Count = (float)(globalMedian * (double)bins[gcBinIndex].Count / median);
                }
            }
            // DebugPrintCountsByGC(bins, "CountsByGC-After.txt");
        }
All Usage Examples Of CanvasClean.EnrichmentUtilities::GetCountsByGC