Esempio n. 1
0
        private double TTestUneuqalVariance(Comparison comparison, Dictionary<string, List<double>> testDict, ValueType typeOfValue)
        {
            double pvalue = 0;
            List<double[]> samples = new List<double[]>();

            string numeratorGroupString = comparison.NumeratorGroupString;
            string denominatorGroupString = comparison.DenominatorGroupString;

            samples.Add(testDict[numeratorGroupString].ToArray());
            samples.Add(testDict[denominatorGroupString].ToArray());

            double leftPvalue = 0;
            double rightPvalue = 0;
            double bothPvalue = 0;

            double[] set1 = samples[0];
            double[] set2 = samples[1];

            alglib.alglib.unequalvariancettest(set1, set1.Count(), set2, set2.Count(), out bothPvalue, out leftPvalue, out rightPvalue);

            pvalue = bothPvalue;

            double denominatorAverage = testDict[denominatorGroupString].Average();
            double numeratorAverage = testDict[numeratorGroupString].Average();

            double log2Ratio = numeratorAverage - denominatorAverage;
            double realReturnvalue = 0;
            if (typeOfValue == ValueType.IntensityFoldChange || typeOfValue == ValueType.MeanNormalizedFoldChange)
            {
                if (log2Ratio > 0)
                {
                    realReturnvalue = Math.Pow(2, log2Ratio);
                }
                else
                {
                    realReturnvalue = -1 / Math.Pow(2, log2Ratio);
                }
            }
            else
            {
                realReturnvalue = log2Ratio;
            }

            ComparisonToPrintAverage[comparison.ComparisonName] = realReturnvalue;

            Log2FoldChange = realReturnvalue;

            return pvalue;
        }
Esempio n. 2
0
        public double PerformSignificanceTest(Comparison comparison, string sigString, double sigThreshold, ValueType typeOfValue)
        {
            //Add to the Comparison p value dictionary!!!!!!!!!
            double pvalue = 0;
            double newSigThershold = sigThreshold;
            string numeratorGroupNumber = comparison.NumeratorGroupString;
            string denominatorGroupNumber = comparison.DenominatorGroupString;

            Dictionary<string, List<double>> testDictionary = null;
            if (typeOfValue == ValueType.IntensityFoldChange || typeOfValue == ValueType.IntensityLog2Change)
            {
                testDictionary = Log2IntValuesByGroup;
            }
            else
            {
                testDictionary = MeanNormValuesByGroup;
            }

            List<double> outList = null;
            if (testDictionary.TryGetValue(comparison.NumeratorGroupString, out outList))
            {
                bool usepvalue = true;
                if (sigString.Equals("T-Test (Unequal Var)"))
                {
                    pvalue = TTestUneuqalVariance(comparison, testDictionary, typeOfValue);
                }
                else if (sigString.Equals("T-Test (Equal Var)"))
                {
                    pvalue = TTestEqualVariance();
                }
                else if (sigString.Equals("Fold Change"))
                {
                    usepvalue = false;
                    if (typeOfValue == ValueType.IntensityLog2Change || typeOfValue == ValueType.MeanNormalizedLog2Change)
                    {
                        newSigThershold = Math.Log(sigThreshold, 2);
                    }
                }

                ComparisonToPValue[comparison.ComparisonName] = pvalue;

                double testRatio = ComparisonToPrintAverage[comparison.ComparisonName];

                ComparisonToSignificanceDict[comparison.ComparisonName] = false;
                if (usepvalue && pvalue <= sigThreshold && pvalue != 0)
                {
                    ComparisonToSignificanceDict[comparison.ComparisonName] = true;
                }
                else if (!usepvalue && Math.Abs(testRatio) >= newSigThershold)
                {
                    ComparisonToSignificanceDict[comparison.ComparisonName] = true;
                }
            }

            return pvalue;
        }
Esempio n. 3
0
        public double MakeComparison(Comparison comparison, ValueType typeOfValue)
        {
            double returnlog2ratio = 0;
            List<double> outList = null;

            if (typeOfValue == ValueType.MeanNormalizedFoldChange || typeOfValue == ValueType.MeanNormalizedLog2Change)
            {
                if (MeanNormValuesByGroup.TryGetValue(comparison.NumeratorGroupString, out outList))
                {
                    double numeratorValue = MeanNormValuesByGroup[comparison.NumeratorGroupString].Average();
                    double denominatorValue = MeanNormValuesByGroup[comparison.DenominatorGroupString].Average();

                    double log2ratio = numeratorValue - denominatorValue;
                    returnlog2ratio = log2ratio;
                }
            }
            else
            {
                outList = null;
                if (Log2IntValuesByGroup.TryGetValue(comparison.NumeratorGroupString, out outList))
                {
                    double numeratorValue = Log2IntValuesByGroup[comparison.NumeratorGroupString].Average();
                    double denominatorValue = Log2IntValuesByGroup[comparison.DenominatorGroupString].Average();

                    double log2ratio = numeratorValue - denominatorValue;
                    returnlog2ratio = log2ratio;
                }
            }

            double realReturnvalue = 0;
            if (typeOfValue == ValueType.IntensityFoldChange || typeOfValue == ValueType.MeanNormalizedFoldChange)
            {
                if (returnlog2ratio > 0)
                {
                    realReturnvalue = Math.Pow(2, returnlog2ratio);
                }
                else
                {
                    realReturnvalue = -1 / Math.Pow(2, returnlog2ratio);
                }
            }
            else
            {
                realReturnvalue = returnlog2ratio;
            }

            ComparisonToPrintAverage.Add(comparison.ComparisonName, realReturnvalue);

            return realReturnvalue;
        }
Esempio n. 4
0
        private Dictionary<AnnotationType, List<QuantEntry>> ListSignificantChangingQuantEntries(List<AnnotationType> annotationsToAdd, Comparison comparison, string sigType, List<QuantEntry> quantEntries)
        {
            Dictionary<AnnotationType, List<QuantEntry>> retDict = new Dictionary<AnnotationType, List<QuantEntry>>();

            foreach (AnnotationType annotationType in annotationsToAdd)
            {
                List<QuantEntry> addList = new List<QuantEntry>();
                retDict.Add(annotationType, addList);

                if (sigType.Equals("Sig"))
                {
                    foreach (QuantEntry quantEntry in quantEntries)
                    {
                        bool outBool = false;
                        if (quantEntry.ComparisonToSignificanceDict.TryGetValue(comparison.ComparisonName, out outBool))
                        {
                            if (outBool)
                            {
                                retDict[annotationType].Add(quantEntry);
                            }
                        }
                    }
                }
                else if (sigType.Equals("SigUp"))
                {
                    foreach (QuantEntry quantEntry in quantEntries)
                    {
                        bool outBool = false;
                        if (quantEntry.ComparisonToSignificanceDict.TryGetValue(comparison.ComparisonName, out outBool))
                        {
                            if (outBool && quantEntry.Log2FoldChange > 0)
                            {
                                retDict[annotationType].Add(quantEntry);
                            }
                        }
                    }
                }
                else if (sigType.Equals("SigDown"))
                {
                    foreach (QuantEntry quantEntry in quantEntries)
                    {
                        bool outBool = false;
                        if (quantEntry.ComparisonToSignificanceDict.TryGetValue(comparison.ComparisonName, out outBool))
                        {
                            if (outBool && quantEntry.Log2FoldChange < 0)
                            {
                                retDict[annotationType].Add(quantEntry);
                            }
                        }
                    }
                }
            }

            return retDict;
        }
Esempio n. 5
0
        public void AddComparison(Comparison comparison, ValueType typeOfValue)
        {
            Comparison comparisonOut = null;
            if (!Comparisons.TryGetValue(comparison.ComparisonName, out comparisonOut))
            {
                Comparisons.Add(comparison.ComparisonName, comparison);
            }

            foreach (QuantEntry quantEntry in CombinedQuantEntryDict.Values)
            {
                quantEntry.MakeComparison(comparison, typeOfValue);
            }
        }
Esempio n. 6
0
        private void LoadUserInputs()
        {
            //Get the Column that Contains Uniprot Header(s)
            string uniprotHeader = uniprotIDHeader.SelectedItem.ToString();
            if (uniprotHeader.Equals(""))
            {
                uniprotHeader = uniprotIDHeader.Items[0].ToString();
            }

            UniprotHeader = uniprotHeader;

            //Get or create the output file directory
            if (!Directory.Exists(outputFolderTextBox.Text))
            {
                Directory.CreateDirectory(outputFolderTextBox.Text);
            }
            OutputFolder = outputFolderTextBox.Text;

            //Get the value to use for the
            ValueForComparison = ValueType.MeanNormalizedLog2Change;
            if(intensityFoldChange.Checked) { ValueForComparison = ValueType.IntensityFoldChange; }
            else if (intensityLog2.Checked) { ValueForComparison = ValueType.IntensityLog2Change; }
            if (meanNormFoldChange.Checked) { ValueForComparison = ValueType.MeanNormalizedFoldChange; }
            else if (meanNormLog2.Checked) { ValueForComparison = ValueType.MeanNormalizedLog2Change; }

            foreach (DataGridViewRow row in comparisonDataGridView.Rows)
            {
                if (row.Cells[0].Value != null)
                {
                    string numeratorGroupString = row.Cells[0].Value.ToString();
                    string denominatorGroupString = row.Cells[1].Value.ToString();

                    bool testSignificance = true;
                    if (numeratorGroupString.Equals("All"))
                    {
                        foreach (string groupNumber in Numerators)
                        {
                            if (!groupNumber.Equals("All") && !groupNumber.Equals(denominatorGroupString))
                            {
                                numeratorGroupString = groupNumber;
                                Comparison comparison = new Comparison(numeratorGroupString, denominatorGroupString, testSignificance);

                                Comparisons.Add(comparison);
                            }
                        }

                    }
                    else
                    {
                        Comparison comparison = new Comparison(numeratorGroupString, denominatorGroupString, testSignificance);
                        Comparisons.Add(comparison);
                    }
                }
            }

            groupDataGrid.Update();
            foreach (AnalysisGroupLine analysisGroupLine in AnalysisGroups)
            {
                string filename = analysisGroupLine.FileName;
                string headername = analysisGroupLine.HeaderName;
                string filelocation = analysisGroupLine.FileLocation;
                string uniquegroupname = analysisGroupLine.UniqueName;
                string fileAndHeader = filelocation + headername;
                string groupString = analysisGroupLine.GroupString;

                FileNameAndHeadertoUniqueGroupName.Add(fileAndHeader, uniquegroupname);
                UniqueGroupNametoGroupString.Add(uniquegroupname, groupString);

                Dictionary<string, List<string>> outDictionary = null;
                if (FiletoGroupNametoListofHeaders.TryGetValue(filelocation, out outDictionary))
                {
                    List<string> outString = null;
                    if (outDictionary.TryGetValue(groupString, out outString))
                    {
                        outString.Add(headername);
                    }
                    else
                    {
                        List<string> addList = new List<string>();
                        addList.Add(headername);
                        outDictionary.Add(groupString, addList);
                    }
                }
                else
                {
                    List<string> addList = new List<string>();
                    addList.Add(headername);
                    Dictionary<string, List<string>> addDict = new Dictionary<string, List<string>>();
                    addDict.Add(groupString, addList);
                    FiletoGroupNametoListofHeaders.Add(filelocation, addDict);
                }

                //Build a dictionary with the File Location and the headers to Quantify
                List<string> outList = new List<string>();
                if (FileNametoHeadersToQuantify.TryGetValue(filelocation, out outList))
                {
                    outList.Add(headername);
                }
                else
                {
                    List<string> addList = new List<string>();
                    addList.Add(headername);
                    FileNametoHeadersToQuantify.Add(filelocation, addList);
                }
            }

            foreach (KeyValuePair<string, Dictionary<string, List<string>>> kvp in FiletoGroupNametoListofHeaders)
            {
                List<string> headersToAdd = new List<string>();
                HeadersToIncludeByFile.Add(kvp.Key, headersToAdd);

                foreach (Comparison comparison in Comparisons)
                {
                    //Add all the headers to limit to in HeadersToInclude
                    List<string> outList = new List<string>();
                    if (kvp.Value.TryGetValue(comparison.NumeratorGroupString, out outList))
                    {
                        foreach (string header in outList)
                        {
                            if (!HeadersToIncludeByFile[kvp.Key].Contains(header))
                            {
                                HeadersToIncludeByFile[kvp.Key].Add(header);
                            }
                        }
                    }

                    List<string> outList2 = new List<string>();
                    if (kvp.Value.TryGetValue(comparison.DenominatorGroupString, out outList2))
                    {
                        foreach (string header in outList2)
                        {
                            if (!HeadersToIncludeByFile[kvp.Key].Contains(header))
                            {
                                HeadersToIncludeByFile[kvp.Key].Add(header);
                            }
                        }
                    }
                }
            }
        }