示例#1
0
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
                                ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            int           nameCol = param.GetParam <int>("New column names").Value;
            List <string> colNames;

            if (nameCol >= 0)
            {
                HashSet <string> taken = new HashSet <string>();
                colNames = new List <string>();
                foreach (string n in mdata.StringColumns[nameCol])
                {
                    string n1 = PerseusUtils.GetNextAvailableName(n, taken);
                    taken.Add(n1);
                    colNames.Add(n1);
                }
            }
            else
            {
                colNames = new List <string>();
                for (int i = 0; i < mdata.RowCount; i++)
                {
                    colNames.Add("Column" + (i + 1));
                }
            }
            List <string> rowNames = mdata.ColumnNames;

            mdata.Values = mdata.Values.Transpose();
            if (mdata.IsImputed != null)
            {
                mdata.IsImputed = mdata.IsImputed.Transpose();
            }
            if (mdata.Quality != null)
            {
                mdata.Quality = mdata.Quality.Transpose();
            }
            List <string>     stringColumnNames              = mdata.StringColumnNames;
            List <string>     categoryColumnNames            = mdata.CategoryColumnNames;
            List <string>     numericColumnNames             = mdata.NumericColumnNames;
            List <string>     multiNumericColumnNames        = mdata.MultiNumericColumnNames;
            List <string>     stringColumnDescriptions       = mdata.StringColumnDescriptions;
            List <string>     categoryColumnDescriptions     = mdata.CategoryColumnDescriptions;
            List <string>     numericColumnDescriptions      = mdata.NumericColumnDescriptions;
            List <string>     multiNumericColumnDescriptions = mdata.MultiNumericColumnDescriptions;
            List <string[]>   stringColumns       = mdata.StringColumns;
            List <string[][]> categoryColumns     = GetCategoryColumns(mdata);
            List <double[]>   numericColumns      = mdata.NumericColumns;
            List <double[][]> multiNumericColumns = mdata.MultiNumericColumns;

            mdata.SetAnnotationColumns(new List <string>(new[] { "Name" }), new List <string>(new[] { "Name" }),
                                       new List <string[]>(new[] { rowNames.ToArray() }), mdata.CategoryRowNames, mdata.CategoryRowDescriptions,
                                       GetCategoryRows(mdata), mdata.NumericRowNames, mdata.NumericRowDescriptions, mdata.NumericRows, new List <string>(),
                                       new List <string>(), new List <double[][]>());
            mdata.ColumnNames = colNames;
            mdata.SetAnnotationRows(stringColumnNames, stringColumnDescriptions, stringColumns, categoryColumnNames,
                                    categoryColumnDescriptions, categoryColumns, numericColumnNames, numericColumnDescriptions, numericColumns,
                                    multiNumericColumnNames, multiNumericColumnDescriptions, multiNumericColumns);
        }
 public void ProcessData(IMatrixData data, Parameters param, ref IMatrixData[] supplTables,
                         ref IDocumentData[] documents, ProcessInfo processInfo)
 {
     int[] exColInds       = param.GetParam <int[]>("Main columns").Value;
     int[] numColInds      = param.GetParam <int[]>("Numerical columns").Value;
     int[] multiNumColInds = param.GetParam <int[]>("Multi-numerical columns").Value;
     int[] catColInds      = param.GetParam <int[]>("Categorical columns").Value;
     int[] textColInds     = param.GetParam <int[]>("Text columns").Value;
     if (exColInds.Length > 0)
     {
         int ncol = data.ColumnCount;
         data.ExtractColumns(ArrayUtils.Concat(ArrayUtils.ConsecutiveInts(data.ColumnCount), exColInds));
         HashSet <string> taken = new HashSet <string>(data.ColumnNames);
         for (int i = 0; i < exColInds.Length; i++)
         {
             string s = PerseusUtils.GetNextAvailableName(data.ColumnNames[ncol + i], taken);
             data.ColumnNames[ncol + i] = s;
             taken.Add(s);
         }
     }
     foreach (int ind in numColInds)
     {
         HashSet <string> taken = new HashSet <string>(data.NumericColumnNames);
         string           s     = PerseusUtils.GetNextAvailableName(data.NumericColumnNames[ind], taken);
         data.AddNumericColumn(s, data.NumericColumnDescriptions[ind], (double[])data.NumericColumns[ind].Clone());
         taken.Add(s);
     }
     foreach (int ind in multiNumColInds)
     {
         HashSet <string> taken = new HashSet <string>(data.MultiNumericColumnNames);
         string           s     = PerseusUtils.GetNextAvailableName(data.MultiNumericColumnNames[ind], taken);
         data.AddMultiNumericColumn(s, data.MultiNumericColumnDescriptions[ind],
                                    (double[][])data.MultiNumericColumns[ind].Clone());
         taken.Add(s);
     }
     foreach (int ind in catColInds)
     {
         HashSet <string> taken = new HashSet <string>(data.CategoryColumnNames);
         string           s     = PerseusUtils.GetNextAvailableName(data.CategoryColumnNames[ind], taken);
         data.AddCategoryColumn(s, data.CategoryColumnDescriptions[ind], data.GetCategoryColumnAt(ind));
         taken.Add(s);
     }
     foreach (int ind in textColInds)
     {
         HashSet <string> taken = new HashSet <string>(data.StringColumnNames);
         string           s     = PerseusUtils.GetNextAvailableName(data.StringColumnNames[ind], taken);
         data.AddStringColumn(s, data.StringColumnDescriptions[ind], (string[])data.StringColumns[ind].Clone());
         taken.Add(s);
     }
 }
        private static void MakeNewNames(IList <string> newExColNames, IEnumerable <string> mainColumnNames)
        {
            HashSet <string> taken = new HashSet <string>(mainColumnNames);

            for (int i = 0; i < newExColNames.Count; i++)
            {
                if (taken.Contains(newExColNames[i]))
                {
                    string n1 = PerseusUtils.GetNextAvailableName(newExColNames[i], taken);
                    newExColNames[i] = n1;
                    taken.Add(n1);
                }
                else
                {
                    taken.Add(newExColNames[i]);
                }
            }
        }