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)); } } }
internal void SetUp(Matrix <TRowKey, TColKey, TValue> parentMatrix, IEnumerable <int> colIndexSequence) { ParentMatrix = parentMatrix; //Check that there are not any missing or extra column indexes IndexOfParentCol = colIndexSequence.ToList(); Helper.CheckCondition(IndexOfParentCol.Count == ParentMatrix.ColCount, Properties.Resource.ExpectedEveryColumnToBeAMemberOfThePermutation); RangeCollection rangeCollection = new RangeCollection(colIndexSequence); Helper.CheckCondition(rangeCollection.IsComplete(0, ParentMatrix.ColCount - 1), Properties.Resource.ExpectedEveryColumnToBeUsedOnceInThePermuation); }
internal void SetUp(Matrix <TRowKey, TColKey, TValue> parentMatrix, IEnumerable <int> colIndexSequence) { ParentMatrix = parentMatrix; //Check that not missing any column indexes or have extra IndexOfParentCol = colIndexSequence.ToList(); Helper.CheckCondition(IndexOfParentCol.Count == ParentMatrix.ColCount, "Every column must be mentioned in the permutation."); RangeCollection rangeCollection = new RangeCollection(colIndexSequence); Helper.CheckCondition(rangeCollection.IsComplete(0, ParentMatrix.ColCount - 1), "Every column must be mentioned exactly once"); }
/// <summary> /// Only call this in a lock... /// </summary> private bool AsynchronousAddRangeToStream(RangeCollection itemsToAdd, int itemCount) { string completedRanges = null; RangeCollection completedRangeCollection = null; //StreamReader reader = null; //StreamWriter writer = null; try { //reader = new StreamReader(rangeFileStream); //completedRanges = reader.ReadToEnd(); completedRanges = _sharedRangeFile.ReadAll().Trim(); completedRangeCollection = completedRanges.Length == 0 ? new RangeCollection() : RangeCollection.Parse(completedRanges); Console.WriteLine("Range read from file: {0}", completedRangeCollection); completedRangeCollection.AddRangeCollection(itemsToAdd); //rangeFileStream.SetLength(0); //writer = new StreamWriter(rangeFileStream); //writer.Write(completedRangeCollection); //writer.Flush(); _sharedRangeFile.Clear(); _sharedRangeFile.Write(completedRangeCollection); Console.WriteLine("Range {0} complete to {1} items? {2}", completedRangeCollection, itemCount, completedRangeCollection.IsComplete(itemCount)); return(completedRangeCollection.IsComplete(itemCount)); } catch (Exception) { Console.WriteLine("ERROR: Trouble adding range."); Console.WriteLine("read from file: {0}", completedRanges); Console.WriteLine("new range: {0}", itemsToAdd); Console.WriteLine("combined: {0}", completedRangeCollection); throw; } }
//!!!!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)); } } }
public override bool IsComplete() { return(RowIndexRangeCollection.IsComplete(RowCountSoFar)); }