Exemple #1
0
        public void Tabulate(string directory, string caseName, List <KeyValuePair <int, int> > firstNullAndLastNullList)
        {
            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             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, SelectionName, 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);
                    }
                }
            }
            SpecialFunctions.CheckCondition(realRowCollectionToSort.Count != 0);
            SpecialFunctions.CheckCondition(rangeCollection.IsComplete(minFirstNull, maxLastNull));
            int nullCount = maxLastNull - Math.Max(0, minFirstNull) + 1;


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

            string outputFile = string.Format(@"{0}\{1}.{2}.{3}.qValues.new.txt", directory, SelectionName, 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));
                }
            }
        }
Exemple #2
0
        static HlaAssignMain CreateProgramFromArguments(string[] args)
        {
            ArgCollection argCollection = ArgCollection.GetInstance(args);

            if (argCollection.ExtractOptionalFlag("help"))
            {
                Console.WriteLine();
                Console.WriteLine(UsageMessage);
                Console.WriteLine(HelpMessage);
                return(null);
            }

            bool bExcel = argCollection.ExtractOptionalFlag("EXCEL");

            argCollection.CheckNoMoreOptions();

            double?leakProbabilityOrNull = argCollection.ExtractNext <double?>("leakProbabilityOrNull");
            double pValue = argCollection.ExtractNext <double>("pValue");

            string directoryName = argCollection.ExtractNext <string>("directory");
            string caseName      = argCollection.ExtractNext <string>("caseName");

            string          hlaFactoryName  = argCollection.ExtractNext <string>("hlaFactory");
            RangeCollection pieceIndexRange = argCollection.ExtractNext <RangeCollection>("pieceIndexRange");
            int             pieceCount      = argCollection.ExtractNext <int>("pieceCount");

            SpecialFunctions.CheckCondition(0 <= pieceIndexRange.FirstElement && pieceIndexRange.LastElement < pieceCount, "The pieceIndexRange must be a subrange of " + RangeCollection.GetInstance(0, pieceCount - 1).ToString());
            RangeCollection nullIndexRange = argCollection.ExtractNext <RangeCollection>("nullIndexRange");

            argCollection.CheckThatEmpty();

            return(new HlaAssignMain(bExcel, leakProbabilityOrNull, pValue, directoryName, caseName, hlaFactoryName, pieceIndexRange, pieceCount, nullIndexRange));
        }
Exemple #3
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));
                }
            }
        }