private static string ProcessDataReadFromFile(IDataWithAnnotationRows mdata, Parameters param)
        {
            Parameter <string> fp       = param.GetParam <string>("Input file");
            string             filename = fp.Value;

            string[] colNames;
            try {
                colNames = TabSep.GetColumnNames(filename, '\t');
            } catch (Exception) {
                return("Could not open file " + filename + ". It maybe open in another program.");
            }
            int nameIndex = GetNameIndex(colNames);

            if (nameIndex < 0)
            {
                return("Error: the file has to contain a column called 'Name'.");
            }
            if (colNames.Length < 2)
            {
                return("Error: the file does not contain a numerical column.");
            }
            string[] nameCol             = TabSep.GetColumn(colNames[nameIndex], filename, '\t');
            Dictionary <string, int> map = ArrayUtils.InverseMap(nameCol);

            for (int i = 0; i < colNames.Length; i++)
            {
                if (i == nameIndex)
                {
                    continue;
                }
                string   groupName = colNames[i];
                string[] groupCol  = TabSep.GetColumn(groupName, filename, '\t');
                double[] newCol    = new double[mdata.ColumnCount];
                for (int j = 0; j < newCol.Length; j++)
                {
                    string colName = mdata.ColumnNames[j];
                    if (!map.ContainsKey(colName))
                    {
                        newCol[j] = double.NaN;
                        continue;
                    }
                    int    ind   = map[colName];
                    string group = groupCol[ind] ?? "";
                    group = group.Trim();
                    if (string.IsNullOrEmpty(group))
                    {
                        newCol[j] = double.NaN;
                    }
                    else
                    {
                        if (!Parser.TryDouble(group, out newCol[j]))
                        {
                            newCol[j] = double.NaN;
                        }
                    }
                }
                mdata.AddNumericRow(groupName, groupName, newCol);
            }
            return(null);
        }
        private static string ProcessDataReadFromFile(IDataWithAnnotationRows mdata, Parameters param)
        {
            Parameter <string> fp       = param.GetParam <string>("Input file");
            string             filename = fp.Value;

            string[] colNames;
            try
            {
                colNames = TabSep.GetColumnNames(filename, '\t');
            }
            catch (Exception)
            {
                return("Could not open file " + filename + ". It maybe open in another program.");
            }
            int nameIndex = GetNameIndex(colNames);

            if (nameIndex < 0)
            {
                return("Error: the file has to contain a column called 'Name'.");
            }
            if (colNames.Length < 2)
            {
                return("Error: the file does not contain a grouping column.");
            }
            string[] nameCol = TabSep.GetColumn(colNames[nameIndex], filename, '\t');
            for (int i = 0; i < nameCol.Length; i++)
            {
                MessageBox.Show(nameCol[i].ToString());
            }
            return(null);
        }
        private static void ProcessDataDelete(IDataWithAnnotationRows mdata, Parameters param)
        {
            int groupColInd = param.GetParam <int>("Numerical row").Value;

            mdata.NumericRows.RemoveAt(groupColInd);
            mdata.NumericRowNames.RemoveAt(groupColInd);
            mdata.NumericRowDescriptions.RemoveAt(groupColInd);
        }
        private static void ProcessDataRename(IDataWithAnnotationRows mdata, Parameters param)
        {
            int    groupColInd    = param.GetParam <int>("Category row").Value;
            string newName        = param.GetParam <string>("New name").Value;
            string newDescription = param.GetParam <string>("New description").Value;

            mdata.CategoryRowNames[groupColInd]        = newName;
            mdata.CategoryRowDescriptions[groupColInd] = newDescription;
        }
Пример #5
0
        private static List <string[][]> GetCategoryRows(IDataWithAnnotationRows mdata)
        {
            List <string[][]> result = new List <string[][]>();

            for (int i = 0; i < mdata.CategoryRowCount; i++)
            {
                result.Add(mdata.GetCategoryRowAt(i));
            }
            return(result);
        }
Пример #6
0
 private static SingleChoiceWithSubParams GetGroupingParam(IDataWithAnnotationRows mdata)
 {
     return(new SingleChoiceWithSubParams("Grouping")
     {
         Values = mdata.CategoryRowNames,
         SubParams = GetFirstGroupParameters(mdata),
         Help = "The grouping(s) of columns to be used in the test. Each test takes two groups as input. " +
                "Multiple tests can be performed simultaneously by specifying more than one pair of groups.",
         ParamNameWidth = 120,
         TotalWidth = totWidth
     });
 }
        private static void ProcessDataCreate(IDataWithAnnotationRows mdata, Parameters param)
        {
            string name = param.GetParam <string>("Row name").Value;

            string[][] groupCol = new string[mdata.ColumnCount][];
            for (int i = 0; i < mdata.ColumnCount; i++)
            {
                string ename = mdata.ColumnNames[i];
                string value = param.GetParam <string>(ename).Value;
                groupCol[i] = value.Length > 0 ? value.Split(';') : new string[0];
            }
            mdata.AddCategoryRow(name, name, groupCol);
        }
        private static void ProcessDataWriteTemplateFile(IDataWithAnnotationRows mdata, Parameters param)
        {
            Parameter <string> fp     = param.GetParam <string>("Output file");
            StreamWriter       writer = new StreamWriter(fp.Value);

            writer.WriteLine("Name\tNew grouping");
            for (int i = 0; i < mdata.ColumnCount; i++)
            {
                string colName = mdata.ColumnNames[i];
                writer.WriteLine(colName + "\t" + colName);
            }
            writer.Close();
        }
        private static void ProcessDataCreate(IDataWithAnnotationRows mdata, Parameters param)
        {
            string name = param.GetParam <string>("Row name").Value;

            double[] groupCol = new double[mdata.ColumnCount];
            for (int i = 0; i < mdata.ColumnCount; i++)
            {
                string ename = mdata.ColumnNames[i];
                double value = param.GetParam <double>(ename).Value;
                groupCol[i] = value;
            }
            mdata.AddNumericRow(name, name, groupCol);
        }
        private static void ProcessDataEdit(IDataWithAnnotationRows mdata, Parameters param)
        {
            ParameterWithSubParams <int> s = param.GetParamWithSubParams <int>("Numerical row");
            int        groupColInd         = s.Value;
            Parameters sp = s.GetSubParameters();

            for (int i = 0; i < mdata.ColumnCount; i++)
            {
                string t = mdata.ColumnNames[i];
                double x = sp.GetParam <double>(t).Value;
                mdata.NumericRows[groupColInd][i] = x;
            }
        }
        private static void ProcessDataCreateFromGoupNames(IDataWithAnnotationRows mdata, Parameters param,
                                                           ProcessInfo processInfo)
        {
            var name = param.GetParam <string>("Name").Value;
            ParameterWithSubParams <int> scwsp = param.GetParamWithSubParams <int>("Pattern");
            Parameters spar        = scwsp.GetSubParameters();
            string     regexString = "";
            string     replacement = "";

            switch (scwsp.Value)
            {
            case 0:
            case 1:
            case 2:
                regexString = GetSelectableRegexes()[scwsp.Value][1];
                break;

            case 3:
                regexString = spar.GetParam <string>("Regex").Value;
                break;

            case 4:
                regexString = spar.GetParam <string>("Regex").Value;
                replacement = spar.GetParam <string>("Replace with").Value;
                break;
            }
            Regex regex;

            try {
                regex = new Regex(regexString);
            } catch (ArgumentException) {
                processInfo.ErrString = "The regular expression you provided has invalid syntax.";
                return;
            }
            List <string[]> groupNames = new List <string[]>();

            foreach (string sampleName in mdata.ColumnNames)
            {
                string groupName = scwsp.Value < 4
                                        ? regex.Match(sampleName).Groups[1].Value
                                        : regex.Replace(sampleName, replacement);
                if (string.IsNullOrEmpty(groupName))
                {
                    groupName = sampleName;
                }
                groupNames.Add(new[] { groupName });
            }
            mdata.AddCategoryRow(name, "", groupNames.ToArray());
        }
        private static void ProcessDataEdit(IDataWithAnnotationRows mdata, Parameters param)
        {
            ParameterWithSubParams <int> s = param.GetParamWithSubParams <int>("Category row");
            int        groupColInd         = s.Value;
            Parameters sp = s.GetSubParameters();

            string[][] newRow = new string[mdata.ColumnCount][];
            for (int i = 0; i < mdata.ColumnCount; i++)
            {
                string t = mdata.ColumnNames[i];
                string x = sp.GetParam <string>(t).Value;
                newRow[i] = x.Length > 0 ? x.Split(';') : new string[0];
            }
            mdata.SetCategoryRowAt(newRow, groupColInd);
        }
Пример #13
0
 private static Parameters[] GetFirstGroupParameters(IDataWithAnnotationRows mdata)
 {
     Parameters[] q = new Parameters[mdata.CategoryRowCount];
     for (int i = 0; i < q.Length; i++)
     {
         string[] vals = ArrayUtils.UniqueValuesPreserveOrder(ArrayUtils.Concat(mdata.GetCategoryRowAt(i)));
         q[i] = new Parameters(
             new MultiChoiceParam("First group (right)")
         {
             Values  = vals,
             Value   = new[] { 0 },
             Repeats = true,
             Help    = "All 'right' groups of the two sample tests are defined here. The number " +
                       "of groups selected here equals the number of different tests performed."
         }, GetSecondGroupParameter(vals));
     }
     return(q);
 }
        private static IMatrixData GetResult(IDataWithAnnotationRows mdata1, IDataWithAnnotationRows mdata2,
                                             Parameters parameters, IList <int[]> indexMap)
        {
            IMatrixData result = (IMatrixData)mdata1.Clone();

            SetAnnotationRows(result, mdata1, mdata2);
            bool indicator = parameters.GetParam <bool>("Indicator").Value;

            if (indicator)
            {
                string[][] indicatorCol = new string[indexMap.Count][];
                for (int i = 0; i < indexMap.Count; i++)
                {
                    indicatorCol[i] = indexMap[i].Length > 0 ? new[] { "+" } : new string[0];
                }
                result.AddCategoryColumn(mdata2.Name, "", indicatorCol);
            }
            result.Origin = "Combination";
            return(result);
        }
 private static void ProcessDataCreate(IDataWithAnnotationRows mdata, Parameters param)
 {
     string name = param.GetParam<string>("Row name").Value;
     double[] groupCol = new double[mdata.ColumnCount];
     for (int i = 0; i < mdata.ColumnCount; i++){
         string ename = mdata.ColumnNames[i];
         double value = param.GetParam<double>(ename).Value;
         groupCol[i] = value;
     }
     mdata.AddNumericRow(name, name, groupCol);
 }
        private static void ProcessDataDelete(IDataWithAnnotationRows mdata, Parameters param)
        {
            int groupColInd = param.GetParam <int>("Category row").Value;

            mdata.RemoveCategoryRowAt(groupColInd);
        }
 private static void ProcessDataEdit(IDataWithAnnotationRows mdata, Parameters param)
 {
     ParameterWithSubParams<int> s = param.GetParamWithSubParams<int>("Numerical row");
     int groupColInd = s.Value;
     Parameters sp = s.GetSubParameters();
     for (int i = 0; i < mdata.ColumnCount; i++){
         string t = mdata.ColumnNames[i];
         double x = sp.GetParam<double>(t).Value;
         mdata.NumericRows[groupColInd][i] = x;
     }
 }
 private static void ProcessDataRename(IDataWithAnnotationRows mdata, Parameters param)
 {
     int groupColInd = param.GetParam<int>("Numerical row").Value;
     string newName = param.GetParam<string>("New name").Value;
     string newDescription = param.GetParam<string>("New description").Value;
     mdata.NumericRowNames[groupColInd] = newName;
     mdata.NumericRowDescriptions[groupColInd] = newDescription;
 }
 private static void ProcessDataDelete(IDataWithAnnotationRows mdata, Parameters param)
 {
     int groupColInd = param.GetParam<int>("Numerical row").Value;
     mdata.NumericRows.RemoveAt(groupColInd);
     mdata.NumericRowNames.RemoveAt(groupColInd);
     mdata.NumericRowDescriptions.RemoveAt(groupColInd);
 }
Пример #20
0
 private static List<string[][]> GetCategoryRows(IDataWithAnnotationRows mdata)
 {
     List<string[][]> result = new List<string[][]>();
     for (int i = 0; i < mdata.CategoryRowCount; i++){
         result.Add(mdata.GetCategoryRowAt(i));
     }
     return result;
 }
Пример #21
0
 private static void SetAnnotationRows(IDataWithAnnotationRows result, IDataWithAnnotationRows mdata1,
                                       IDataWithAnnotationRows mdata2)
 {
     result.CategoryRowNames.Clear();
     result.CategoryRowDescriptions.Clear();
     result.ClearCategoryRows();
     result.NumericRowNames.Clear();
     result.NumericRowDescriptions.Clear();
     result.NumericRows.Clear();
     string[] allCatNames = ArrayUtils.Concat(mdata1.CategoryRowNames, mdata2.CategoryRowNames);
     allCatNames             = ArrayUtils.UniqueValues(allCatNames);
     result.CategoryRowNames = new List <string>();
     string[] allCatDescriptions = new string[allCatNames.Length];
     for (int i = 0; i < allCatNames.Length; i++)
     {
         allCatDescriptions[i] = GetDescription(allCatNames[i], mdata1.CategoryRowNames, mdata2.CategoryRowNames,
                                                mdata1.CategoryRowDescriptions, mdata2.CategoryRowDescriptions);
     }
     result.CategoryRowDescriptions = new List <string>();
     for (int index = 0; index < allCatNames.Length; index++)
     {
         string     t           = allCatNames[index];
         string[][] categoryRow = new string[mdata1.ColumnCount + mdata2.ColumnCount][];
         for (int j = 0; j < categoryRow.Length; j++)
         {
             categoryRow[j] = new string[0];
         }
         int ind1 = mdata1.CategoryRowNames.IndexOf(t);
         if (ind1 >= 0)
         {
             string[][] c1 = mdata1.GetCategoryRowAt(ind1);
             for (int j = 0; j < c1.Length; j++)
             {
                 categoryRow[j] = c1[j];
             }
         }
         int ind2 = mdata2.CategoryRowNames.IndexOf(t);
         if (ind2 >= 0)
         {
             string[][] c2 = mdata2.GetCategoryRowAt(ind2);
             for (int j = 0; j < c2.Length; j++)
             {
                 categoryRow[mdata1.ColumnCount + j] = c2[j];
             }
         }
         result.AddCategoryRow(allCatNames[index], allCatDescriptions[index], categoryRow);
     }
     string[] allNumNames = ArrayUtils.Concat(mdata1.NumericRowNames, mdata2.NumericRowNames);
     allNumNames            = ArrayUtils.UniqueValues(allNumNames);
     result.NumericRowNames = new List <string>(allNumNames);
     string[] allNumDescriptions = new string[allNumNames.Length];
     for (int i = 0; i < allNumNames.Length; i++)
     {
         allNumDescriptions[i] = GetDescription(allNumNames[i], mdata1.NumericRowNames, mdata2.NumericRowNames,
                                                mdata1.NumericRowDescriptions, mdata2.NumericRowDescriptions);
     }
     result.NumericRowDescriptions = new List <string>(allNumDescriptions);
     foreach (string t in allNumNames)
     {
         double[] numericRow = new double[mdata1.ColumnCount + mdata2.ColumnCount];
         for (int j = 0; j < numericRow.Length; j++)
         {
             numericRow[j] = double.NaN;
         }
         int ind1 = mdata1.NumericRowNames.IndexOf(t);
         if (ind1 >= 0)
         {
             double[] c1 = mdata1.NumericRows[ind1];
             for (int j = 0; j < c1.Length; j++)
             {
                 numericRow[j] = c1[j];
             }
         }
         int ind2 = mdata2.NumericRowNames.IndexOf(t);
         if (ind2 >= 0)
         {
             double[] c2 = mdata2.NumericRows[ind2];
             for (int j = 0; j < c2.Length; j++)
             {
                 numericRow[mdata1.ColumnCount + j] = c2[j];
             }
         }
         result.NumericRows.Add(numericRow);
     }
 }