/// <summary> /// Given a multistate matrix, returns a mapping of multistateKeys to lists of binary keys. Keys are assumed to be sequences of the form /// pos@aa1#aa2#...#aaN.. Each item is the multistateKey of the format pos@aa1#aa2#...#aaN. Each value is /// an enumeration of binary keys that map to that multistate key. /// </summary> /// <param name="binaryMatrix"></param> /// <returns></returns> public static IEnumerable <KeyValuePair <string, IEnumerable <string> > > MultistateToBinaryMapping(Matrix <string, string, SufficientStatistics> multistateMatrix) { var multToBinaryPositions = from multKey in multistateMatrix.RowKeys where multKey.Contains('@') let merAndPos = Tabulate.GetMerAndPos(multKey) let binaryKeys = merAndPos.Key.Split('#').Select(aa => (int)merAndPos.Value + "@" + aa) select new KeyValuePair <string, IEnumerable <string> >(multKey, binaryKeys); var nonAaKeys = from key in multistateMatrix.RowKeys where !key.Contains('@') select new KeyValuePair <string, IEnumerable <string> >(key, new List <string>() { key }); var allKeys = nonAaKeys.Concat(multToBinaryPositions); return(allKeys); //var temp = multistateMatrix.RowKeys.Select(key => // Tabulate.GetMerAndPos(key)).Select(merAndPos => // new KeyValuePair<string, IEnumerable<string>>(merAndPos.Value + "@" + merAndPos.Key, // merAndPos.Key.Split('#').Select(aa => (int)merAndPos.Value + "@" + aa))); }
/// <summary> /// Merges all the files in dirinfo matching inputFilePattern and places them in mergedFileName. If MergedFileName exists, will append to the end. Then attempts to /// tabulate with the given parameters. If it fails, then it will places the workitems that it found in completedRowsFileName in the form a range, which can be used as a skipfile. /// If successful, then it deletes completedRowsFileName, if it exists. This is useful for deleting previous skip files. /// </summary> /// <param name="dirinfo">location where all the files can be found.</param> /// <returns>True if tabulate was successful, false otherwise.</returns> public static bool MergeThenTabulateOrCreateSkipFile(DirectoryInfo dirinfo, string inputFilePattern, string mergedFileName, string tabulateResultFileName, string skipFileName, KeepTest <Dictionary <string, string> > keepTest, List <KeepTest <Dictionary <string, string> > > splitKeepTestList, double maxPForTabulate, bool useStoreyMethod) { Console.Write("Merging files..."); Tabulate.MergeFilesUsedToTabulate(dirinfo, inputFilePattern, mergedFileName, true); Console.WriteLine("done merging."); bool tabulated = Tabulate.CreateTabulateReport( dirinfo, mergedFileName, tabulateResultFileName, keepTest, splitKeepTestList, maxPForTabulate, true /* audit */, useStoreyMethod); if (tabulated) { //string skipFileName = completedRowsFileName.Replace("completedRows", "skipFile"); //File.Delete(completedRowsFileName); // at this point we know everything's done, so delete it. if (File.Exists(skipFileName)) { File.Delete(skipFileName); } return(true); } else { Console.WriteLine("Tabulation failed. Missing rows placed in {0}.", skipFileName); SpecialFunctions.MoveAndReplace(tabulateResultFileName, skipFileName); return(false); } }
/// <summary> /// Given a binary matrix, returns a mapping of multistateKeys to lists of binary keys. Keys are assumed to be sequences of the form /// pos@AA or AA@pos. All other keys will be left as binary. Each item is the multistateKey of the format pos@aa1#aa2#...#aaN. Each value is /// an enumeration of binary keys that map to that multistate key. /// </summary> /// <param name="binaryMatrix"></param> /// <returns></returns> public static IEnumerable <KeyValuePair <string, IEnumerable <string> > > BinaryToMultistateMapping(Matrix <string, string, SufficientStatistics> binaryMatrix) { var multToBinaryPositions = from binaryKey in binaryMatrix.RowKeys where binaryKey.Contains('@') let merAndPos = Tabulate.GetMerAndPos(binaryKey) let pos = (int)merAndPos.Value group binaryKey by pos into g select new KeyValuePair <string, IEnumerable <string> > ( g.Key + "@" + g.OrderBy(bk => bk).StringJoin("#").Replace(g.Key + "@", ""), g.ToList() ); var nonAaKeys = from key in binaryMatrix.RowKeys where !key.Contains('@') select new KeyValuePair <string, IEnumerable <string> >(key, new List <string>() { key }); var allKeys = nonAaKeys.Concat(multToBinaryPositions); return(allKeys); }