public void ValidateMatrixFactoryParse() { _denseMatObj = GetDenseMatrix(); MatrixFactory <String, String, Double> mfObj = MatrixFactory <String, String, Double> .GetInstance(); ParallelOptions poObj = new ParallelOptions(); TryParseMatrixDelegate <string, string, double> a = new TryParseMatrixDelegate <string, string, double>(this.TryParseMatrix); mfObj.RegisterMatrixParser(a); // Writes the text file _denseMatObj.WritePaddedDouble(Constants.FastQTempTxtFileName, poObj); Matrix <string, string, double> newMatObj = mfObj.Parse(Constants.FastQTempTxtFileName, double.NaN, poObj); Assert.AreEqual(_denseMatObj.RowCount, newMatObj.RowCount); Assert.AreEqual(_denseMatObj.RowKeys.Count, newMatObj.RowKeys.Count); Assert.AreEqual(_denseMatObj.ColCount, newMatObj.ColCount); Assert.AreEqual(_denseMatObj.ColKeys.Count, newMatObj.ColKeys.Count); Assert.AreEqual(_denseMatObj.Values.Count(), newMatObj.Values.Count()); Console.WriteLine( "MatrixFactory BVT : Successfully validated Parse() method"); ApplicationLog.WriteLine( "MatrixFactory BVT : Successfully validated Parse() method"); }
//public void ParseArgs(ArgumentCollection argumentCollection) //{ // KeepOneValueVariables = argumentCollection.ExtractOptionalFlag("keepOneValueVariables"); // //MissingChar = argumentCollection.ExtractOptional<char>("missingChar", '?'); // //int? merLengthOrNull = argumentCollection.ExtractOptional<int?>("Mer", null); // we don't seem to actually use this... // CurrentMixtureSemantics = argumentCollection.ExtractOptional<MixtureSemantics>("MixtureSemantics", MixtureSemantics.Uncertainty); // //Helper.CheckCondition(null == merLengthOrNull || mixtureSemantics == MixtureSemantics.Uncertainty, "The 'Mer' option cannot be used with '-MixtureSemantics pure' or '-MixtureSemantics any'"); //} //public override void ParseReadArgs(ArgumentCollection argumentCollection) //{ // base.ParseReadArgs(argumentCollection); // ParseArgs(argumentCollection); //} //public override void ParseWriteArgs(ArgumentCollection argumentCollection) //{ // base.ParseWriteArgs(argumentCollection); // ParseArgs(argumentCollection); // Format = argumentCollection.ExtractNext<SequenceMatrix.WriteFormat>("WriteFormat"); // Type = argumentCollection.ExtractNext<SequenceMatrix.WriteType>("WriteFormat"); //} public override List <NamedSequence> Parse(TextReader reader) { MatrixFactory <string, string, SufficientStatistics> mf = MatrixFactory <string, string, SufficientStatistics> .GetInstance(); string filename = MBT.Escience.FileUtils.WriteTextReaderToTempFile(reader); var matrix = mf.Parse(filename, MissingStatistics.GetInstance(), new ParallelOptions()); return(ConvertToSequences(matrix)); }
public void ValidateMatrixFactoryRegisterMatrixParser() { MatrixFactory <String, String, Double> mfactObj = MatrixFactory <String, String, Double> .GetInstance(); TryParseMatrixDelegate <string, string, double> tryParseDelObj = new TryParseMatrixDelegate <string, string, double>(TryParseMatrix); mfactObj.RegisterMatrixParser(tryParseDelObj); Assert.IsTrue(true, "No exceptions were thrown on running RegisterMatrixParser() method"); }
public void ValidateMatrixFactoryAllMethods() { denseMatObj = GetDenseMatrix(); MatrixFactory <String, String, Double> mfObj = MatrixFactory <String, String, Double> .GetInstance(); Assert.IsTrue(string.IsNullOrEmpty(mfObj.ErrorMessages)); ApplicationLog.WriteLine( "MatrixFactory BVT : Successfully validated All methods"); }
/// <summary> /// Loads a single mergeView matrix from the list of files. /// </summary> /// <typeparam name="TRowKey"></typeparam> /// <typeparam name="TColKey"></typeparam> /// <typeparam name="TVal"></typeparam> /// <param name="files"></param> /// <param name="missingVal"></param> /// <param name="colsMustMatch"></param> /// <returns></returns> public static Matrix <TRowKey, TColKey, TVal> LoadAsSingleMatrix <TRowKey, TColKey, TVal>(this IEnumerable <FileInfo> files, TVal missingVal, bool colsMustMatch = false) { MatrixFactory <TRowKey, TColKey, TVal> mf = MatrixFactory <TRowKey, TColKey, TVal> .GetInstance(); //var matrices = files.Select(dataFile => mf.Parse(dataFile.FullName, missingVal, ParallelOptionsScope.Current)).ToArray(); var matrices = (from f in files let name = f.Name == "-" ? MBT.Escience.FileUtils.WriteStdInToTempFile() : f.FullName select mf.Parse(name, missingVal, ParallelOptionsScope.Current)).ToArray(); var result = new MergeRowsView <TRowKey, TColKey, TVal>(colsMustMatch, matrices); return(result); }
public static IEnumerable <TwoByTwo> GetCollectionFromMatrices(bool unsorted, string inputMatrixFileName1, string inputMatrixFileName2, ParallelOptions parallelOptions) { MatrixFactory <string, string, SufficientStatistics> mf = MatrixFactory <string, string, SufficientStatistics> .GetInstance(); var m1 = mf.Parse(inputMatrixFileName1, MissingStatistics.GetInstance(), parallelOptions); var m2 = mf.Parse(inputMatrixFileName2, MissingStatistics.GetInstance(), parallelOptions); List <TwoByTwo> tableList = new List <TwoByTwo>(); foreach (string key in m1.RowKeys) { if (m2.ContainsRowKey(key)) { TwoByTwo table = TwoByTwo.GetInstance(inputMatrixFileName1, key, false); var m1NonMissing = m1.RowView(key).Select(kvp => kvp); var m2NonMissing = m2.RowView(key).Select(kvp => kvp); // m1 is T for first col, m2 is F for first Col. table.TT = m1NonMissing.Select(kvp => (int)kvp.Value.AsDiscreteStatistics()).Sum(); table.TF = m1NonMissing.Count() - table.TT; table.FT = m2NonMissing.Select(kvp => (int)kvp.Value.AsDiscreteStatistics()).Sum(); table.FF = m2NonMissing.Count() - table.FT; if (unsorted) { yield return(table); } else { tableList.Add(table); } } } if (!unsorted) { tableList.Sort((t1, t2) => t1.FisherExactTest.CompareTo(t2.FisherExactTest)); foreach (var table in tableList) { yield return(table); } } }