Beispiel #1
0
 internal static IMatrixData NonzeroFilter1Split(bool rows, int minValids, bool percentage, IMatrixData mdata,
                                                 Parameters param, double threshold, double threshold2, FilteringMode filterMode)
 {
     if (rows)
     {
         IMatrixData supplTab  = (IMatrixData)mdata.Clone();
         List <int>  valids    = new List <int>();
         List <int>  notvalids = new List <int>();
         for (int i = 0; i < mdata.RowCount; i++)
         {
             int count = 0;
             for (int j = 0; j < mdata.ColumnCount; j++)
             {
                 if ((IsValid(mdata.Values.Get(i, j), threshold, threshold2, filterMode)))
                 {
                     count++;
                 }
             }
             if ((Valid(count, minValids, percentage, mdata.ColumnCount)))
             {
                 valids.Add(i);
             }
             else
             {
                 notvalids.Add(i);
             }
         }
         //  FilterRowsNew(mdata, param, valids.ToArray());
         supplTab.ExtractRows(notvalids.ToArray());
         return(supplTab);
     }
     else
     {
         IMatrixData supplTab  = (IMatrixData)mdata.Clone();
         List <int>  valids    = new List <int>();
         List <int>  notvalids = new List <int>();
         for (int j = 0; j < mdata.ColumnCount; j++)
         {
             int count = 0;
             for (int i = 0; i < mdata.RowCount; i++)
             {
                 if (IsValid(mdata.Values.Get(i, j), threshold, threshold2, filterMode))
                 {
                     count++;
                 }
             }
             if (Valid(count, minValids, percentage, mdata.RowCount))
             {
                 valids.Add(j);
             }
             else
             {
                 notvalids.Add(j);
             }
         }
         supplTab.ExtractColumns(notvalids.ToArray());
         // FilterColumnsNew(mdata, param, valids.ToArray());
         return(supplTab);
     }
 }
        private void RemoveSelectedRowsButton_OnClick(object sender, RoutedEventArgs e)
        {
            int[] sel = TableView.GetSelectedRows();
            if (sel.Length == 0)
            {
                MessageBox.Show("Please select some rows.");
            }
            IMatrixData mx = (IMatrixData)mdata.Clone();

            mx.ExtractRows(ArrayUtils.Complement(sel, TableView.RowCount));
            createNewMatrix(mx);
        }
Beispiel #3
0
        private void RemoveSelectedRowsButton_OnClick(object sender, EventArgs e)
        {
            int[] sel = tableView1.GetSelectedRows();
            if (sel.Length == 0)
            {
                MessageBox.Show(Loc.PleaseSelectSomeRows);
            }
            IMatrixData mx = (IMatrixData)mdata.Clone();

            mx.ExtractRows(ArrayUtils.Complement(sel, tableView1.RowCount));
            createNewMatrix(mx);
        }
        public IMatrixData ProcessData(IMatrixData[] inputData, Parameters parameters, ref IMatrixData[] supplTables,
                                       ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            IMatrixData mdata1   = inputData[0];
            IMatrixData mdata2   = inputData[1];
            var         matching = ParseMatchingColumns(parameters);

            int[][] indexMap = GetIndexMap(mdata1, mdata2, matching.first, matching.second);

            var result = (IMatrixData)mdata1.Clone();

            result.Origin = "Combination";
            var addIndicator = parameters.GetParam <bool>("Add indicator").Value;

            if (addIndicator)
            {
                AddIndicator(result, mdata2, indexMap);
            }

            var(main, text, numeric, category) = ParseCopyParameters(parameters);
            SetAnnotationRows(result, mdata1, mdata2, main.copy);
            AddMainColumns(result, mdata2, indexMap, main.copy, GetAveraging(main.combine));
            AddAnnotationColumns(result, mdata2, indexMap, text, numeric, category);
            return(result);
        }
Beispiel #5
0
        public static int WriteRNAFiles(IMatrixData mdata, Parameters param, Parameters dataParam, string workingDirectory, out string errString, string RNAexp)
        {
            //need to write a general version
            //accepts text only data for now

            string fileTempY = System.IO.Path.Combine(workingDirectory, @".\tempY.txt");
            string fileY     = System.IO.Path.Combine(workingDirectory, @".\fileY.txt");


            IMatrixData mCopyY = (IMatrixData)mdata.Clone();

            int[] nameInd = new[] { param.GetParam <int>("Gene Name Column").Value };

            int[] yInd = dataParam.GetParam <int[]>(RNAexp).Value;

            double baseVal = GetBase(dataParam.GetParamWithSubParams <int>(PECAParameters.dataFormGeneric));

            SetupMDataForInput(mCopyY, yInd, nameInd, baseVal);

            try
            {
                //hacky way of removing comments
                PerseusUtils.WriteMatrixToFile(mCopyY, fileTempY, false);
                RemoveCommentsFromFile(fileTempY, fileY);
            }
            catch (Exception e)
            {
                //need to reorganize this
                errString = e.ToString();
                return(-1);
            }

            errString = null;
            return(0);
        }
Beispiel #6
0
        public static IMatrixData CreateSupplTabSplitValids(IMatrixData mdata, int[] rows)
        {
            IMatrixData supplTab = (IMatrixData)mdata.Clone();

            supplTab.ExtractRows(rows);
            return(supplTab);
        }
Beispiel #7
0
        public IMatrixData ProcessData(IMatrixData[] inputData, Parameters parameters, ref IMatrixData[] supplTables,
                                       ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            IMatrixData mdata1 = inputData[0];
            Dictionary <string, string> map = GetMap(inputData[1], parameters);
            IMatrixData result = (IMatrixData)mdata1.Clone();
            int         ind    = parameters.GetParam <int>("Column in matrix 1 to be edited").Value;

            string[] x = mdata1.StringColumns[ind];
            for (int i = 0; i < x.Length; i++)
            {
                x[i] = Process(x[i], map);
            }
            return(result);
        }
Beispiel #8
0
        public IMatrixData ProcessData(IMatrixData[] inputData, Parameters parameters, ref IMatrixData[] supplTables,
                                       ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            IMatrixData mdata1 = inputData[0];
            IMatrixData mdata2 = inputData[1];

            ((int, int)first, (int, int)? second, bool outer, bool ignoreCase)matching =
                ParseMatchingColumns(parameters);
            (int[][] indexMap, int[] unmappedRightIndices) =
                GetIndexMap(mdata1, mdata2, matching.first, matching.second, matching.ignoreCase);
            IMatrixData result = (IMatrixData)mdata1.Clone();

            result.Origin = "Combination";
            if (matching.outer)
            {
                int[][] extendedIndexMap = new int[indexMap.Length + unmappedRightIndices.Length][];
                Array.Copy(indexMap, extendedIndexMap, indexMap.Length);
                for (int i = 0; i < unmappedRightIndices.Length; i++)
                {
                    int idx = indexMap.Length + i;
                    extendedIndexMap[idx] = new[] { unmappedRightIndices[i] };
                }
                result.AddEmptyRows(unmappedRightIndices.Length);
                UpdateIdColumns(result, mdata2, indexMap.Length, unmappedRightIndices, matching.first, matching.second);
                indexMap = extendedIndexMap;
            }
            bool addIndicator = parameters.GetParam <bool>("Add indicator").Value;

            if (addIndicator)
            {
                AddIndicator(result, mdata2, indexMap);
            }
            bool addRowIndex = parameters.GetParam <bool>("Add original row numbers").Value;

            if (addRowIndex)
            {
                result.AddMultiNumericColumn("Original row numbers", "",
                                             indexMap.Select(rows => rows.Select(Convert.ToDouble).ToArray()).ToArray());
            }
            ((int[] copy, int combine)main, int[] text, (int[] copy, int combine)numeric, int[] category) =
                ParseCopyParameters(parameters);
            SetAnnotationRows(result, mdata1, mdata2, main.copy);
            AddMainColumns(result, mdata2, indexMap, main.copy, GetAveraging(main.combine));
            AddAnnotationColumns(result, mdata2, indexMap, text, numeric, category);
            return(result);
        }
        private static IMatrixData GetResult(IMatrixData mdata1, IMatrixData 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);
        }
Beispiel #10
0
        public static int WriteInputFiles(IMatrixData mdata, Parameters param, string workingDirectory, out string errString, string expSeries1 = "Expression Series 1", string expSeries2 = "Expression Series 2", string expSeries3 = "Expression Series 3")
        {
            //need to write a general version
            //accepts text only data for now



            //set as global
            string fileTempX = System.IO.Path.Combine(workingDirectory, @".\tempX.txt");
            string fileX     = System.IO.Path.Combine(workingDirectory, @".\fileX.txt");
            string fileTempM = System.IO.Path.Combine(workingDirectory, @".\tempM.txt");
            string fileM     = System.IO.Path.Combine(workingDirectory, @".\fileM.txt");
            string fileTempY = System.IO.Path.Combine(workingDirectory, @".\tempY.txt");
            string fileY     = System.IO.Path.Combine(workingDirectory, @".\fileY.txt");


            IMatrixData mCopyX = (IMatrixData)mdata.Clone();
            IMatrixData mCopyM = (IMatrixData)mdata.Clone();
            IMatrixData mCopyY = (IMatrixData)mdata.Clone();


            int[] nameInd = new[] { param.GetParam <int>("Gene Name Column").Value };

            int[] xInd = param.GetParam <int[]>(expSeries1).Value;
            int[] mInd = param.GetParam <int[]>(expSeries2).Value;
            int[] yInd = param.GetParam <int[]>(expSeries3).Value;

            //int n_tp = param.GetParam<int>("Number of Time Points").Value;
            int n_rep = param.GetParam <int>("Number of Replicates").Value;

            if (nameInd.Length == 0)
            {
                errString = "Please select a gene name column";
                return(-1);
            }
            if (xInd.Length == 0)
            {
                errString = "Please select some columns for Expression Series";
                return(-1);
            }

            if (xInd.Length != yInd.Length || xInd.Length != mInd.Length)
            {
                errString = "Expression Series need to have matching number of columns";
                return(-1);
            }

            if ((xInd.Length % n_rep) != 0)
            {
                errString = "number of columns not multiple of Number of Replicates";
                return(-1);
            }
            //check also timepoints here

            //if ((xInd.Length % n_tp)!=0)
            //{
            //    errString = "number of columns not multiple of Number of Time Points";
            //    return -1;
            //}

            double baseVal1 = PluginPECA.Utils.GetBase(param.GetParamWithSubParams <int>(PECAParameters.dataForm1));
            double baseVal2 = PluginPECA.Utils.GetBase(param.GetParamWithSubParams <int>(PECAParameters.dataForm2));
            double baseVal3 = PluginPECA.Utils.GetBase(param.GetParamWithSubParams <int>(PECAParameters.dataForm3));

            PluginPECA.Utils.SetupMDataForInput(mCopyX, xInd, nameInd, baseVal1);
            PluginPECA.Utils.SetupMDataForInput(mCopyM, mInd, nameInd, baseVal2);
            PluginPECA.Utils.SetupMDataForInput(mCopyY, yInd, nameInd, baseVal3);

            try
            {
                //hacky way of removing comments
                //better to just ask GS to ignore comments from his code
                PerseusUtils.WriteMatrixToFile(mCopyX, fileTempX, false);
                PluginPECA.Utils.RemoveCommentsFromFile(fileTempX, fileX);
                PerseusUtils.WriteMatrixToFile(mCopyM, fileTempM, false);
                PluginPECA.Utils.RemoveCommentsFromFile(fileTempM, fileM);
                PerseusUtils.WriteMatrixToFile(mCopyY, fileTempY, false);
                PluginPECA.Utils.RemoveCommentsFromFile(fileTempY, fileY);
            }
            catch (Exception e)
            {
                //need to reorganize this
                errString = e.ToString();
                return(-1);
            }

            errString = null;
            return(0);
        }
Beispiel #11
0
        public static IMatrixData CreateSupplTab(IMatrixData mdata)
        {
            IMatrixData supplTab = (IMatrixData)mdata.Clone();

            return(supplTab);
        }