public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
			ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            int[] colIndx = param.GetMultiChoiceParam("x").Value;
            int[] colIndy = param.GetMultiChoiceParam("y").Value;
            if (colIndx.Length == 0){
                processInfo.ErrString = "Please select some columns";
                return;
            }
            if (colIndx.Length != colIndy.Length){
                processInfo.ErrString = "Please select the same number of columns in the boxes for the first and second columns.";
                return;
            }
            int typeInd = param.GetSingleChoiceParam("Distribution type").Value;
            int points = param.GetIntParam("Number of points").Value;
            for (int k = 0; k < colIndx.Length; k++){
                float[] xvals = GetColumn(mdata, colIndx[k]);
                float[] yvals = GetColumn(mdata, colIndy[k]);
                float[] xvals1;
                float[] yvals1;
                NumUtils.GetValidPairs(xvals, yvals, out xvals1, out yvals1);
                double xmin;
                double xmax;
                double ymin;
                double ymax;
                DensityEstimation.CalcRanges(xvals1, yvals1, out xmin, out xmax, out ymin, out ymax);
                float[,] values = DensityEstimation.GetValuesOnGrid(xvals1, xmin, (xmax - xmin)/points, points, yvals1, ymin,
                    (ymax - ymin)/points, points);
                if (typeInd == 1 || typeInd == 3){
                    MakeConditional1(values);
                }
                if (typeInd == 2 || typeInd == 3){
                    MakeConditional2(values);
                }
                DensityEstimation.DivideByMaximum(values);
                double[] xmat = new double[points];
                for (int i = 0; i < points; i++){
                    xmat[i] = xmin + i*(xmax - xmin)/points;
                }
                double[] ymat = new double[points];
                for (int i = 0; i < points; i++){
                    ymat[i] = ymin + i*(ymax - ymin)/points;
                }
                float[,] percvalues = CalcExcludedPercentage(values);
                double[] dvals = new double[xvals.Length];
                double[] pvals = new double[xvals.Length];
                for (int i = 0; i < dvals.Length; i++){
                    double xx = xvals[i];
                    double yy = yvals[i];
                    if (!double.IsNaN(xx) && !double.IsNaN(yy)){
                        int xind = ArrayUtils.ClosestIndex(xmat, xx);
                        int yind = ArrayUtils.ClosestIndex(ymat, yy);
                        dvals[i] = values[xind, yind];
                        pvals[i] = percvalues[xind, yind];
                    } else{
                        dvals[i] = double.NaN;
                        pvals[i] = double.NaN;
                    }
                }
                string xname = GetColumnName(mdata, colIndx[k]);
                string yname = GetColumnName(mdata, colIndy[k]);
                mdata.AddNumericColumn("Density_" + xname + "_" + yname,
                    "Density of data points in the plane spanned by the columns " + xname + " and " + yname + ".", dvals);
                mdata.AddNumericColumn("Excluded fraction_" + xname + "_" + yname,
                    "Percentage of points with a point density smaller than at this point in the plane spanned by the columns " + xname +
                        " and " + yname + ".", pvals);
            }
        }
Esempio n. 2
0
 public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables, ProcessInfo processInfo)
 {
     int numQuantiles = param.GetIntParam("Number of quantiles").Value;
     int[] colInds = param.GetMultiChoiceParam("Columns").Value;
     foreach (int colInd in colInds){
         float[] vals = mdata.GetExpressionColumn(colInd);
         List<int> v = new List<int>();
         for (int i = 0; i < vals.Length; i++){
             if (!float.IsNaN(vals[i])){
                 v.Add(i);
             }
         }
         int[] o = v.ToArray();
         vals = ArrayUtils.SubArray(vals, o);
         int[] q = ArrayUtils.Order(vals);
         o = ArrayUtils.SubArray(o, q);
         string[][] catCol = new string[mdata.RowCount][];
         for (int i = 0; i < catCol.Length; i++){
             catCol[i] = new[]{"missing"};
         }
         for (int i = 0; i < o.Length; i++){
             int catVal = (i*numQuantiles)/o.Length + 1;
             catCol[o[i]] = new[]{"Q" + catVal};
         }
         string name = mdata.ExpressionColumnNames[colInd] + "_q";
         string desc = "The column " + mdata.ExpressionColumnNames[colInd] + " has been divided into " + numQuantiles +
             " quantiles.";
         mdata.AddCategoryColumn(name, desc, catCol);
     }
 }
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
			ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            const bool rows = false;
            int minValids = param.GetIntParam("Min. number of values").Value;
            SingleChoiceWithSubParams modeParam = param.GetSingleChoiceWithSubParams("Mode");
            int modeInd = modeParam.Value;
            if (modeInd != 0 && mdata.CategoryRowNames.Count == 0){
                processInfo.ErrString = "No grouping is defined.";
                return;
            }
            if (modeInd != 0){
                processInfo.ErrString = "Group-wise filtering can only be appled to rows.";
                return;
            }
            SingleChoiceWithSubParams x = param.GetSingleChoiceWithSubParams("Values should be");
            Parameters subParams = x.GetSubParameters();
            int shouldBeIndex = x.Value;
            FilteringMode filterMode;
            double threshold = double.NaN;
            double threshold2 = double.NaN;
            switch (shouldBeIndex){
                case 0:
                    filterMode = FilteringMode.Valid;
                    break;
                case 1:
                    filterMode = FilteringMode.GreaterThan;
                    threshold = subParams.GetDoubleParam("Minimum").Value;
                    break;
                case 2:
                    filterMode = FilteringMode.GreaterEqualThan;
                    threshold = subParams.GetDoubleParam("Minimum").Value;
                    break;
                case 3:
                    filterMode = FilteringMode.LessThan;
                    threshold = subParams.GetDoubleParam("Maximum").Value;
                    break;
                case 4:
                    filterMode = FilteringMode.LessEqualThan;
                    threshold = subParams.GetDoubleParam("Maximum").Value;
                    break;
                case 5:
                    filterMode = FilteringMode.Between;
                    threshold = subParams.GetDoubleParam("Minimum").Value;
                    threshold2 = subParams.GetDoubleParam("Maximum").Value;
                    break;
                case 6:
                    filterMode = FilteringMode.Outside;
                    threshold = subParams.GetDoubleParam("Minimum").Value;
                    threshold2 = subParams.GetDoubleParam("Maximum").Value;
                    break;
                default:
                    throw new Exception("Should not happen.");
            }
            if (modeInd != 0){
                int gind = modeParam.GetSubParameters().GetSingleChoiceParam("Grouping").Value;
                string[][] groupCol = mdata.GetCategoryRowAt(gind);
                NonzeroFilterGroup(minValids, mdata, param, modeInd == 2, threshold, threshold2, filterMode, groupCol);
            } else{
                NonzeroFilter1(rows, minValids, mdata, param, threshold, threshold2, filterMode);
            }
        }
 public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables, ProcessInfo processInfo)
 {
     bool rows = param.GetSingleChoiceParam("Matrix access").Value == 0;
     bool atLeast = param.GetSingleChoiceParam("Side").Value == 0;
     int numValids = param.GetIntParam("Number of valid values").Value;
     SingleChoiceWithSubParams modeParam = param.GetSingleChoiceWithSubParams("Mode");
     int modeInd = modeParam.Value;
     if (modeInd != 0 && mdata.CategoryRowNames.Count == 0){
         processInfo.ErrString = "No grouping is defined.";
         return;
     }
     if (modeInd != 0 && !rows){
         processInfo.ErrString = "Group-wise filtering can only be appled to rows.";
         return;
     }
     if (modeInd != 0){
         int gind = modeParam.GetSubParameters().GetSingleChoiceParam("Grouping").Value;
         string[][] groupCol = mdata.CategoryRows[gind];
         ValidValueFilterGroup(numValids, mdata, param, modeInd == 2, groupCol, atLeast);
     } else{
         ValidValueFilter1(rows, numValids, mdata, param, atLeast);
     }
 }
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
			ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            int minCount = param.GetIntParam("Min. count").Value;
            int selCol = param.GetSingleChoiceParam("Selection").Value;
            string value = param.GetStringParam("Value").Value;
            int[] catIndices = param.GetMultiChoiceParam("Categories").Value;
            bool[] selection = null;
            if (selCol < mdata.CategoryColumnCount){
                selection = new bool[mdata.RowCount];
                string[][] x = mdata.GetCategoryColumnAt(selCol);
                for (int i = 0; i < selection.Length; i++){
                    if (x[i] != null){
                        for (int j = 0; j < x[i].Length; j++){
                            if (x[i][j].Equals(value)){
                                selection[i] = true;
                                break;
                            }
                        }
                    }
                }
            }
            CountingResult result = CountCategories(mdata, selection, selCol, catIndices);
            CreateMatrixData(result, mdata, minCount, selection);
        }
Esempio n. 6
0
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
			ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            int avType = param.GetSingleChoiceParam("Average type").Value;
            if (mdata.CategoryRowCount == 0){
                processInfo.ErrString = "No category rows were loaded.";
                return;
            }
            int groupColInd = param.GetSingleChoiceParam("Grouping").Value;
            int validVals = param.GetIntParam("Min. valid values per group").Value;
            bool keep = param.GetBoolParam("Keep original data").Value;
            bool sdev = param.GetBoolParam("Add standard deviation").Value;
            Func<IList<double>, double> func;
            switch (avType){
                case 0:
                    func = ArrayUtils.Median;
                    break;
                case 1:
                    func = ArrayUtils.Mean;
                    break;
                case 2:
                    func = ArrayUtils.Sum;
                    break;
                case 3:
                    func = ArrayUtils.GeometricMean;
                    break;
                default:
                    throw new Exception("Never get here.");
            }
            if (sdev) {
                AddStandardDeviation(groupColInd, validVals, mdata);
            }
            if (keep) {
                FillMatrixKeep(groupColInd, validVals, mdata, func);
            } else{
                FillMatrixDontKeep(groupColInd, validVals, mdata, func);
            }
        }
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
			ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            int nrows = param.GetIntParam("Number of rows").Value;
            nrows = Math.Min(nrows, mdata.RowCount);
            Random2 rand = new Random2();
            int[] rows = ArrayUtils.SubArray(rand.NextPermutation(mdata.RowCount), nrows);
            PerseusPluginUtils.FilterRows(mdata, param, rows);
        }