//public static void FindAndReport(string selectionName, string directory, string caseName, RangeCollection nullIndexRange, double pValue)
        //{
        //    Debug.Fail("Need to expose leakProbabilityOrNull?");
        //    LrtForHla aLrtForHla = LrtForHla.GetInstance(selectionName, directory, caseName, "MixedWithB15AndA68", null, pValue);
        //    aLrtForHla.Run(RangeCollection.GetInstance(0,0), 1, nullIndexRange, directory);
        //}


        public static void Tabulate(string selectionName, string directory, string caseName, List <KeyValuePair <int, int> > firstNullAndLastNullList, double pValue)
        {
            Debug.Fail("Need to expose leakProbabilityOrNull?");
            LrtForHla aLrtForHla = LrtForHla.GetInstance(selectionName, directory, caseName, "MixedWithB15AndA68", null, pValue);

            aLrtForHla.Tabulate(directory, caseName, firstNullAndLastNullList);
        }
Ejemplo n.º 2
0
        //!!!!somehow combine with Tabulate
        static public void TabulateForTwo(LrtForHla lrtForHlaA, string directoryA, string caseNameA, List <KeyValuePair <int, int> > firstNullAndLastNullListA,
                                          LrtForHla lrtForHlaB, string directoryB, string caseNameB, List <KeyValuePair <int, int> > firstNullAndLastNullListB)
        {
            SpecialFunctions.CheckCondition(lrtForHlaA.SelectionName == lrtForHlaB.SelectionName);
            List <Dictionary <string, string> > realRowCollectionToSort = new List <Dictionary <string, string> >();
            List <double> nullDiffCollectionToBeSorted = new List <double>();

            //!!!move VirusCount.PhyloTree.RangeCollection to a more general place
            RangeCollection rangeCollection = RangeCollection.GetInstance();
            int             minFirstNullx   = int.MaxValue;
            int             maxLastNullx    = int.MinValue;

            foreach (char which in new char[] { 'A', 'B' })
            {
                List <KeyValuePair <int, int> > firstNullAndLastNullList;
                string    directory;
                LrtForHla lrtForHla;
                if (which == 'A')
                {
                    firstNullAndLastNullList = firstNullAndLastNullListA;
                    directory = directoryA;
                    lrtForHla = lrtForHlaA;
                }
                else
                {
                    Debug.Assert(which == 'B');
                    firstNullAndLastNullList = firstNullAndLastNullListB;
                    directory = directoryB;
                    lrtForHla = lrtForHlaB;
                }

                int minFirstNull = int.MaxValue;
                int maxLastNull  = int.MinValue;
                foreach (KeyValuePair <int, int> firstNullAndLastNull in firstNullAndLastNullList)
                {
                    int firstNull = firstNullAndLastNull.Key;
                    minFirstNull = Math.Min(minFirstNull, firstNull);
                    int lastNull = firstNullAndLastNull.Value;
                    maxLastNull = Math.Max(maxLastNull, lastNull);
                    //!!!string repeated elsewere
                    //!!!what "new" or not?

                    string inputFileName = string.Format(@"{0}\{1}.{2}.{3}-{4}.pValues.new.txt", directory, lrtForHla.SelectionName, lrtForHla.CaseName, firstNull, lastNull); //!!!const
                    int    maxNullSeen   = int.MinValue;

                    //foreach (Dictionary<string, string> row in SpecialFunctions.TabFileTable(inputFileName, true))
                    foreach (Dictionary <string, string> row in SpecialFunctions.TabFileTable(inputFileName, PValueDetails.Header, true))
                    {
                        int nullIndex = int.Parse(row["NullIndex"]);
                        rangeCollection.TryAdd(nullIndex);
                        if (nullIndex == -1)
                        {
                            realRowCollectionToSort.Add(row);
                        }
                        else
                        {
                            double value = AccessPValueFromRow(row);
                            nullDiffCollectionToBeSorted.Add(value);
                            maxNullSeen = Math.Max(maxNullSeen, nullIndex);
                        }
                    }
                }

                if (minFirstNullx == int.MaxValue)
                {
                    minFirstNullx = minFirstNull;
                    Debug.Assert(maxLastNullx == int.MinValue);
                    maxLastNullx = maxLastNull;
                }
                else
                {
                    SpecialFunctions.CheckCondition(minFirstNullx == minFirstNull);
                    SpecialFunctions.CheckCondition(maxLastNullx == maxLastNull);
                }
            }
            SpecialFunctions.CheckCondition(realRowCollectionToSort.Count != 0);
            SpecialFunctions.CheckCondition(rangeCollection.IsComplete(minFirstNullx, maxLastNullx));
            int nullCount = maxLastNullx - Math.Max(0, minFirstNullx) + 1;

            //Dictionary<string,string> realRowCollectionToSortNAAs0 = new List<double>();
            //foreach (Dictionary<string,string> row in realRowCollectionToSort)
            //{
            //    double r = AccessPValueFromRow(row);
            //    if (double.IsNaN(r))
            //    {
            //        Dictionary<string, string> row2 = new Dictionary<string, string>();
            //        foreach (KeyValuePair<string, string> keyAndValue in row)
            //        {
            //        }
            //        realRowCollectionToSortNAAs0.Add(0.0);
            //    }
            //    else
            //    {
            //        realRowCollectionToSortNAAs0.Add(row);
            //    }
            //}

            Dictionary <Dictionary <string, string>, double>
            qValueList = SpecialFunctions.ComputeQValues(ref realRowCollectionToSort, AccessPValueFromRow, ref nullDiffCollectionToBeSorted, nullCount);

            string outputFile = string.Format(@"{0}\{1}.{2}-{3}.{4}.qValues.new.txt", directoryB, lrtForHlaA.SelectionName, lrtForHlaA.CaseName, lrtForHlaB.CaseName, nullCount); //!!!const

            using (StreamWriter outputStream = File.CreateText(outputFile))
            {
                outputStream.WriteLine(SpecialFunctions.CreateTabString(PValueDetails.Header, "qValue"));
                foreach (Dictionary <string, string> row in realRowCollectionToSort)
                {
                    double qValue = qValueList[row];
                    outputStream.WriteLine(SpecialFunctions.CreateTabString(row[""], qValue));
                }
            }
        }