Esempio n. 1
0
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
                                ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            ParameterWithSubParams <int> access = param.GetParamWithSubParams <int>("Matrix access");
            bool rows    = access.Value == 0;
            int  meanInd = access.GetSubParameters().GetParam <int>("Mean").Value;
            int  devInd  = access.GetSubParameters().GetParam <int>("Std. dev.").Value;

            double[] means   = rows ? mdata.NumericColumns[meanInd] : mdata.NumericRows[meanInd];
            double[] stddevs = rows ? mdata.NumericColumns[devInd] : mdata.NumericRows[devInd];
            UnZscore(rows, mdata, processInfo.NumThreads, means, stddevs);
        }
Esempio n. 2
0
 public bool CheckGroup(ParameterWithSubParams <int> p, ProcessInfo processInfo)
 {
     if (p.Value < 0)
     {
         processInfo.ErrString = "No categorical rows available.";
         return(false);
     }
     else
     {
         return(true);
     }
 }
Esempio n. 3
0
        public RegressionModel Train(BaseVector[] x, float[] y, Parameters param, int nthreads)
        {
            ParameterWithSubParams <int> kernelParam = param.GetParamWithSubParams <int>("Kernel");
            SvmParameter sp = new SvmParameter {
                kernelFunction = KernelFunctions.GetKernelFunction(kernelParam.Value, kernelParam.GetSubParameters()),
                svmType        = SvmType.EpsilonSvr,
                c = param.GetParam <double>("C").Value
            };
            SvmModel model = SvmMain.SvmTrain(new SvmProblem(x, y), sp);

            return(new SvmRegressionModel(model));
        }
Esempio n. 4
0
 public void CheckSignificant(string[][] sigCol, string[] info, ParameterWithSubParams <bool> fdrValid,
                              ParameterWithSubParams <bool> pValid, ParameterWithSubParams <bool> lfcValid, int lineNum)
 {
     if (fdrValid.Value)
     {
         double maxFDR = fdrValid.Value ? fdrValid.GetSubParameters().GetParam <double>("Max. FDR").Value : 0;
         double.TryParse(info[6], out double fdr);
         double.TryParse(info[2], out double lfc);
         if (fdr <= maxFDR)
         {
             if (lfc > 0)
             {
                 sigCol[lineNum - 1][0] = "Up-regulated";
             }
             else if (lfc < 0)
             {
                 sigCol[lineNum - 1][0] = "Down-regulated";
             }
             else
             {
                 sigCol[lineNum - 1][0] = "Equal";
             }
         }
         else
         {
             sigCol[lineNum - 1][0] = "Insignificant";
         }
     }
     if (lfcValid.Value)
     {
         double ulfc = lfcValid.Value ? lfcValid.GetSubParameters().GetParam <double>("Up-regluation").Value : 0;
         double dlfc = lfcValid.Value ? lfcValid.GetSubParameters().GetParam <double>("Down-regluation").Value : 0;
         double.TryParse(info[2], out double lfc);
         if (lfc > 0 && lfc < ulfc)
         {
             sigCol[lineNum - 1][0] = "Insignificant";
         }
         else if (lfc < 0 && lfc > dlfc)
         {
             sigCol[lineNum - 1][0] = "Insignificant";
         }
     }
     if (pValid.Value)
     {
         double maxP = pValid.Value ? pValid.GetSubParameters().GetParam <double>("Max. p-value").Value : 0;
         double.TryParse(info[5], out double p);
         if (p > maxP)
         {
             sigCol[lineNum - 1][0] = "Insignificant";
         }
     }
 }
        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;
            }
        }
Esempio n. 6
0
        public override RegressionModel Train(BaseVector[] x, int[] nominal, double[] y, Parameters param, int nthreads, Action <double> reportProgress)
        {
            x = ClassificationMethod.ToOneHotEncoding(x, nominal);
            ParameterWithSubParams <int> kernelParam = param.GetParamWithSubParams <int>("Kernel");
            SvmParameter sp = new SvmParameter {
                kernelFunction = KernelFunctions.GetKernelFunction(kernelParam.Value, kernelParam.GetSubParameters()),
                svmType        = SvmType.EpsilonSvr,
                c = param.GetParam <double>("C").Value
            };
            SvmModel model = SvmMain.SvmTrain(new SvmProblem(x, y), sp);

            return(new SvmRegressionModel(model));
        }
        internal static void ReadValuesShouldBeParams(Parameters param, out FilteringMode filterMode, out double threshold,
                                                      out double threshold2)
        {
            ParameterWithSubParams <int> x = param.GetParamWithSubParams <int>("Values should be");
            Parameters subParams           = x.GetSubParameters();
            int        shouldBeIndex       = x.Value;

            threshold  = double.NaN;
            threshold2 = double.NaN;
            switch (shouldBeIndex)
            {
            case 0:
                filterMode = FilteringMode.Valid;
                break;

            case 1:
                filterMode = FilteringMode.GreaterThan;
                threshold  = subParams.GetParam <double>("Minimum").Value;
                break;

            case 2:
                filterMode = FilteringMode.GreaterEqualThan;
                threshold  = subParams.GetParam <double>("Minimum").Value;
                break;

            case 3:
                filterMode = FilteringMode.LessThan;
                threshold  = subParams.GetParam <double>("Maximum").Value;
                break;

            case 4:
                filterMode = FilteringMode.LessEqualThan;
                threshold  = subParams.GetParam <double>("Maximum").Value;
                break;

            case 5:
                filterMode = FilteringMode.Between;
                threshold  = subParams.GetParam <double>("Minimum").Value;
                threshold2 = subParams.GetParam <double>("Maximum").Value;
                break;

            case 6:
                filterMode = FilteringMode.Outside;
                threshold  = subParams.GetParam <double>("Minimum").Value;
                threshold2 = subParams.GetParam <double>("Maximum").Value;
                break;

            default:
                throw new Exception("Should not happen.");
            }
        }
Esempio n. 8
0
 public void StoreResult(Dictionary <string, string[]> results, string[][] sigCol,
                         int lineNum, ParameterWithSubParams <bool> fdrValid, ParameterWithSubParams <bool> pValid,
                         ParameterWithSubParams <int> lfcValid, string logFC, string logCPM, string pV,
                         string FDR, string LR, double[] fcs)
 {
     sigCol[lineNum - 1] = new string[] { "" };
     CheckSignificant(sigCol, FDR, logFC, pV, fdrValid,
                      pValid, lfcValid, lineNum, fcs);
     results["log2FoldChange"][lineNum - 1] = logFC;
     results["logCPM"][lineNum - 1]         = logCPM;
     results["LR"][lineNum - 1]             = LR;
     results["p-value"][lineNum - 1]        = pV;
     results["FDR"][lineNum - 1]            = FDR;
 }
        private static string[] GetBaseIds(Parameters para, IDataWithAnnotationColumns mdata)
        {
            string[]      baseNames;
            AnnotType[][] types;
            string[]      files;
            PerseusUtils.GetAvailableAnnots(out baseNames, out types, out files);
            ParameterWithSubParams <int> spd = para.GetParamWithSubParams <int>("Source");
            int        ind     = spd.Value;
            Parameters param   = spd.GetSubParameters();
            int        baseCol = param.GetParam <int>(baseNames[ind] + " column").Value;

            string[] baseIds = mdata.StringColumns[baseCol];
            return(baseIds);
        }
Esempio n. 10
0
        //returns the CORE input parameter lines
        public static string[] GetInputParamLines(Parameters param, Parameters dataParam, bool isRNAOnly = false)
        {
            int seriesLen = isRNAOnly ? dataParam.GetParam <int[]>(PECAParameters.RNAexp).Value.Length : dataParam.GetParam <int[]>(PECAParameters.series1).Value.Length;

            string tp = string.Join(" ", Enumerable.Range(0, seriesLen / param.GetParam <int>("Number of Replicates").Value));

            string lineX, lineY;

            if (isRNAOnly)
            {
                string needLoggedString = PluginPECA.Utils.GetBase(dataParam.GetParamWithSubParams <int>(PECAParameters.dataFormGeneric)) == 0 ? "0" : "1";
                lineX = "FILE_X = ";
                lineY = "FILE_Y = fileY.txt " + needLoggedString;
            }
            else
            {
                //isLN check
                //if yes then false - does not need to be logged
                //if not true - needs to be logged
                string needLoggedString1 = PluginPECA.Utils.GetBase(dataParam.GetParamWithSubParams <int>(PECAParameters.dataForm1)) == 0 ? "0" : "1";
                string needLoggedString2 = PluginPECA.Utils.GetBase(dataParam.GetParamWithSubParams <int>(PECAParameters.dataForm2)) == 0 ? "0" : "1";
                //string isLoggedString = param.GetParam<bool>("Is log2(x)?").Value ? "false" : "true";
                lineX = "FILE_X = fileX.txt " + needLoggedString1;
                lineY = "FILE_Y = fileY.txt " + needLoggedString2;
            }

            string[] lines =
            {
                lineX,
                lineY,
                string.Format("N_REP = {0}",   param.GetParam <int>("Number of Replicates").Value),
                "TIME = " + tp,
                string.Format("N_BURN = {0}",  param.GetParam <int>("MCMC Burn-In").Value),
                string.Format("N_THIN = {0}",  param.GetParam <int>("MCMC Thinning").Value),
                string.Format("N_SAMPLE = {0}",param.GetParam <int>("MCMC Samples").Value),
                //string.Format("N_BURN = {0}", getMCMCParam(param.GetParamWithSubParams<int>("MCMC Burn-In"), 0)),
                //string.Format("N_THIN = {0}", getMCMCParam(param.GetParamWithSubParams<int>("MCMC Thinning"), 1)),
                //string.Format("N_SAMPLE = {0}", getMCMCParam(param.GetParamWithSubParams<int>("MCMC Samples"), 2)),
                ""
            };
            //success if 0

            //replace with smoothing

            ParameterWithSubParams <bool> getSmoothing = param.GetParamWithSubParams <bool>("Smoothing");

            lines[lines.Length - 1] = getSmoothing.Value ? string.Format("SMOOTHING= {0} {1}", getSmoothing.GetSubParameters().GetParam <double>(PECAParameters.smoothingPar1).Value, getSmoothing.GetSubParameters().GetParam <double>(PECAParameters.smoothingPar2).Value) : "";

            return(lines);
        }
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
                                ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            ParameterWithSubParams <int> p = param.GetParamWithSubParams <int>("Row");
            int colInd = p.Value;

            if (colInd < 0)
            {
                processInfo.ErrString = "No categorical rows available.";
                return;
            }
            Parameter <int[]> mcp = p.GetSubParameters().GetParam <int[]>("Values");

            int[] inds = mcp.Value;
            if (inds.Length == 0)
            {
                processInfo.ErrString = "Please select at least one term for filtering.";
                return;
            }
            string[] values = new string[inds.Length];
            string[] v      = mdata.GetCategoryRowValuesAt(colInd);
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = v[inds[i]];
            }
            HashSet <string> value  = new HashSet <string>(values);
            bool             remove = param.GetParam <int>("Mode").Value == 0;

            string[][] cats   = mdata.GetCategoryRowAt(colInd);
            List <int> valids = new List <int>();

            for (int i = 0; i < cats.Length; i++)
            {
                bool valid = true;
                foreach (string w in cats[i])
                {
                    if (value.Contains(w))
                    {
                        valid = false;
                        break;
                    }
                }
                if (valid && remove || !valid && !remove)
                {
                    valids.Add(i);
                }
            }
            PerseusPluginUtils.FilterColumns(mdata, param, valids.ToArray());
        }
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
                                ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            double          minValid       = Convert.ToDouble(param.GetParam <string>("Min. expression value").Value);
            Parameter <int> m              = param.GetParam <int>("Mode");
            ParameterWithSubParams <int> p = param.GetParamWithSubParams <int>("Group");
            int colInd = p.Value;

            if (colInd < 0)
            {
                processInfo.ErrString = "No categorical rows available.";
                return;
            }
            string[] groupids = ExtractGroup(mdata, p, processInfo, colInd);
            bool     Unvalid  = CheckGroupIDsValid(groupids, processInfo, m.Value);

            if (Unvalid)
            {
                return;
            }
            HashSet <string> value = new HashSet <string>(groupids);

            string[][] cats = mdata.GetCategoryRowAt(colInd);
            Dictionary <string, List <string> > samples = new Dictionary <string, List <string> >();

            for (int i = 0; i < cats.Length; i++)
            {
                for (int j = 0; j < cats[i].Length; j++)
                {
                    if (value.Contains(cats[i][j]))
                    {
                        if (!samples.ContainsKey(cats[i][j]))
                        {
                            samples.Add(cats[i][j], new List <string>());
                        }
                        samples[cats[i][j]].Add(mdata.ColumnNames[i]);
                        int len = i * cats[i].Length + j;
                    }
                }
            }
            if (m.Value == 0)
            {
                ModeAtLeastOneGroup(mdata, samples, minValid);
            }
            else if (m.Value == 1)
            {
                ModeAllGroup(mdata, samples, minValid);
            }
        }
        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());
        }
        public void ProcessData(IMatrixData mdata, Parameters para, ref IMatrixData[] supplTables,
                                ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            var annotationProvider = _annotationProvider;
            ParameterWithSubParams <int> sourceParam = para.GetParamWithSubParams <int>("Source");
            int        sourceIndex = sourceParam.Value;
            Parameters param       = sourceParam.GetSubParameters();
            int        baseCol     = param.GetParam <int>("Identifiers").Value;
            int        selection   = param.GetParam <int>("Identifier type").Value;

            var(_, id, _) = annotationProvider.TextSources()[sourceIndex];
            var newColumn = annotationProvider.MapToBaseIdentifiers(mdata.StringColumns[baseCol], sourceIndex, selection);

            mdata.AddStringColumn(id, id, newColumn);
        }
        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);
        }
        public static ((int m1, int m2) first, (int m1, int m2)? second) ParseMatchingColumns(Parameters parameters)
        {
            int Value(Parameters param, string name) => param.GetParam <int>(name).Value;

            (int, int)first = (Value(parameters, "Matching column in table 1"), Value(parameters, "Matching column in table 2"));
            ParameterWithSubParams <bool> p = parameters.GetParamWithSubParams <bool>("Use additional column pair");
            Parameters subPar = p.GetSubParameters();

            (int m1, int m2)? second = null;
            if (p.Value)
            {
                second = (Value(subPar, "Additional column in table 1"), Value(subPar, "Additional column in table 2"));
            }
            return(first, second);
        }
Esempio n. 17
0
        public static string CheckCoreParameters(IMatrixData mdata, Parameters param, Parameters dataParam, string expSeries1 = "Expression Series 1", string expSeries2 = "Expression Series 2", string dataForm1 = "Data Input Form 1", string dataForm2 = "Data Input Form 2")
        {
            string commonErr = CheckCommonParameters(mdata, param, dataParam, expSeries1, expSeries2, dataForm1, dataForm2);

            if (commonErr != null)
            {
                return(commonErr);
            }
            ParameterWithSubParams <bool> getAnalysis = param.GetParamWithSubParams <bool>(PECAParameters.gsa);

            if (getAnalysis.Value)
            {
                return(CheckEnrichmentCommon(getAnalysis.GetSubParameters()));
            }
            return(null);
        }
Esempio n. 18
0
        private static int[] GetColIndsNumFilter(Parameters parameters, out string[] realVariableNames)
        {
            ParameterWithSubParams <int> sp = parameters.GetParamWithSubParams <int>("Number of columns");
            int ncols = sp.Value + 1;

            int[] result = new int[ncols];
            realVariableNames = new string[ncols];
            Parameters param = sp.GetSubParameters();

            for (int j = 0; j < ncols; j++)
            {
                realVariableNames[j] = GetVariableName(j);
                result[j]            = param.GetParam <int>(realVariableNames[j]).Value;
            }
            return(result);
        }
Esempio n. 19
0
        public void IsobaricLabeling(ParameterWithSubParams <int> parmInd, IMatrixData mdata,
                                     string[] newNames)
        {
            int  expInd     = parmInd.GetSubParameters().GetParam <int>("Experiment row").Value;
            int  channelInd = parmInd.GetSubParameters().GetParam <int>("Channel row").Value;
            bool detect     = false;

            for (int i = 0; i < mdata.ColumnCount; i++)
            {
                string[] expCols  = mdata.GetCategoryRowEntryAt(expInd, i)[0].Split(' ');
                string[] mainCols = mdata.ColumnNames[i].Split(' ');
                if (mainCols.Length > expCols.Length)
                {
                    string[] checkExpName = new string[expCols.Length];
                    Array.Copy(mainCols, (mainCols.Length - expCols.Length), checkExpName, 0, expCols.Length);
                    if ((String.Join(" ", expCols) == String.Join(" ", checkExpName)) &&
                        (mainCols[mainCols.Length - expCols.Length - 1] == mdata.GetCategoryRowEntryAt(channelInd, i)[0]))
                    {
                        string mainString = "";
                        for (int j = 0; j < (mainCols.Length - expCols.Length - 1); j++)
                        {
                            mainString = mainString + " " + mainCols[j];
                        }
                        detect      = true;
                        newNames[i] = mainString.Trim() + " " + newNames[i];
                    }
                }
            }
            if (detect)
            {
                CheckRepeat(newNames);
                for (int i = 0; i < mdata.ColumnCount; i++)
                {
                    mdata.ColumnNames[i] = newNames[i];
                }
            }
            else
            {
                for (int i = 0; i < mdata.ColumnCount; i++)
                {
                    if (newNames[i] != mdata.ColumnNames[i])
                    {
                        mdata.ColumnNames[i] = mdata.ColumnNames[i] + " " + newNames[i];
                    }
                }
            }
        }
Esempio n. 20
0
        public void LoadData(IMatrixData mdata, Parameters parameters, ref IMatrixData[] supplTables,
                             ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            string filename = parameters.GetParam <string>("File").Value;
            ParameterWithSubParams <bool> bsp = parameters.GetParamWithSubParams <bool>("Split into columns");
            bool split = bsp.Value;

            if (split)
            {
                bool csv = bsp.GetSubParameters().GetParam <int>("Separator").Value == 1;
                LoadSplit(mdata, filename, csv);
            }
            else
            {
                LoadNoSplit(mdata, filename);
            }
        }
Esempio n. 21
0
 public double[] GetCutoffLogFC(ParameterWithSubParams <int> lfcValid, string resultName, string method)
 {
     double[] fcs = new double[] { 0, 0 };
     if (lfcValid.Value == 0)
     {
         fcs[0] = lfcValid.GetSubParameters().GetParam <double>("Up-regluation").Value;
         fcs[1] = lfcValid.GetSubParameters().GetParam <double>("Down-regluation").Value;
     }
     else if (lfcValid.Value == 1)
     {
         double        ufc     = lfcValid.GetSubParameters().GetParam <double>("Up-regluation").Value;
         double        dfc     = lfcValid.GetSubParameters().GetParam <double>("Down-regluation").Value;
         List <double> fcList  = new List <double>();
         StreamReader  reader  = new StreamReader(File.OpenRead(resultName));
         int           lineNum = 0;
         double        fcValue = 0;
         while (!reader.EndOfStream)
         {
             string line = reader.ReadLine();
             if (!String.IsNullOrWhiteSpace(line))
             {
                 line = line.Replace("\"", "");
                 string[] info = line.Split(',');
                 if (lineNum != 0)
                 {
                     if (method == "DESeq2")
                     {
                         double.TryParse(info[2], out fcValue);
                     }
                     else
                     {
                         double.TryParse(info[1], out fcValue);
                     }
                     fcList.Add(fcValue);
                 }
             }
             lineNum++;
         }
         reader.Close();
         fcList.Sort();
         fcs[0] = fcList[(int)Math.Round(((double)fcList.Count / (double)100) * ufc)];
         fcs[1] = fcList[(int)Math.Round(((double)fcList.Count / (double)100) * dfc)];
     }
     return(fcs);
 }
Esempio n. 22
0
 public void RunEdgeRWithoutReplicates(REngine engine, Dictionary <string, List <string> > samples,
                                       List <string> pairs1, List <string> pairs2, IMatrixData mdata, ParameterWithSubParams <bool> fdrValid,
                                       ParameterWithSubParams <bool> pValid, ParameterWithSubParams <int> lfcValid, double dispersion)
 {
     foreach (string pair1 in pairs1)
     {
         foreach (string pair2 in pairs2)
         {
             if (pair1 != pair2)
             {
                 Dictionary <string, string> counts = new Dictionary <string, string>();
                 List <string> cats     = new List <string>();
                 string        fileName = "Count_table_" + pair1 + "_" + pair2 + ".txt";
                 TextWriter    tw       = new StreamWriter(fileName);
                 WritePairCount(pair1, samples, mdata, counts, cats);
                 WritePairCount(pair2, samples, mdata, counts, cats);
                 tw.WriteLine(String.Join("\t", cats));
                 foreach (KeyValuePair <string, string> entry in counts)
                 {
                     tw.WriteLine(entry.Key + "\t" + entry.Value);
                 }
                 tw.Close();
                 string fileLine = String.Format("data_raw <- read.table('{0}', header = TRUE)", fileName);
                 engine.Evaluate(fileLine);
                 string repString = String.Format("rep('{0}', {1}), rep('{2}', {3})",
                                                  pair1, samples[pair1].Count.ToString(), pair2, samples[pair2].Count.ToString());
                 string commandLine = String.Format("mobDataGroups <- c({0})", repString);
                 engine.Evaluate(commandLine);
                 engine.Evaluate("d <- DGEList(counts = data_raw, group = factor(mobDataGroups))");
                 engine.Evaluate("d <- calcNormFactors(d)");
                 string dispersionLine = String.Format("d$common.dispersion <- {0}", dispersion.ToString());
                 engine.Evaluate(dispersionLine);
                 engine.Evaluate("de <- exactTest(d)");
                 engine.Evaluate("result <- topTags(de, n = Inf)");
                 engine.Evaluate("result_table <- as.data.frame(result)");
                 engine.Evaluate("sort_result <- result_table[order(as.numeric(row.names(result_table))), ]");
                 string resultName   = "results_" + pair1 + "_" + pair2 + ".csv";
                 string resultString = String.Format("write.csv(sort_result, file = '{0}')", resultName);
                 engine.Evaluate(resultString);
                 ExtractEdgeRResults(mdata, pair1, pair2, fdrValid, pValid, lfcValid, false, resultName);
             }
         }
     }
 }
Esempio n. 23
0
        public static string[] GetInputParamLines(Parameters param)
        {
            //actual time points in this case
            string tp = param.GetParam <string>("Time Points").Value;
            //gpTime is # of time points
            string gpTime = string.Join(" ", Enumerable.Range(0, param.GetParam <int[]>(PECAParameters.pecaRSeries1).Value.Length / param.GetParam <int>("Number of Replicates").Value));


            //isLN check
            //if yes then false - does not need to be logged
            //if not true - needs to be logged
            string needLoggedString1 = PluginPECA.Utils.GetBase(param.GetParamWithSubParams <int>(PECAParameters.dataForm1)) == 0 ? "0" : "1";
            string needLoggedString2 = PluginPECA.Utils.GetBase(param.GetParamWithSubParams <int>(PECAParameters.dataForm2)) == 0 ? "0" : "1";
            string needLoggedString3 = PluginPECA.Utils.GetBase(param.GetParamWithSubParams <int>(PECAParameters.dataForm3)) == 0 ? "0" : "1";

            //string isLoggedString = param.GetParam<bool>("Is log2(x)?").Value ? "false" : "true";


            string[] lines =
            {
                "FILE_X = fileX.txt " + needLoggedString1,
                //need to add this back
                "FILE_M = fileM.txt " + needLoggedString2,
                "FILE_Y = fileY.txt " + needLoggedString3,
                string.Format("N_REP = {0}",              param.GetParam <int>("Number of Replicates").Value),
                "TIME = " + tp,
                "GP_TIME = " + gpTime,
                string.Format("N_BURN = {0}",             param.GetParam <int>("MCMC Burn-In").Value),
                string.Format("N_THIN = {0}",             param.GetParam <int>("MCMC Thinning").Value),
                string.Format("N_SAMPLE = {0}",           param.GetParam <int>("MCMC Samples").Value),
                ""
            };
            //success if 0

            //replace with smoothing

            ParameterWithSubParams <bool> getSmoothing = param.GetParamWithSubParams <bool>("Smoothing");

            lines[lines.Length - 1] = getSmoothing.Value ? string.Format("SMOOTHING= {0} {1}", getSmoothing.GetSubParameters().GetParam <double>(PECAParameters.smoothingPar1).Value, getSmoothing.GetSubParameters().GetParam <double>(PECAParameters.smoothingPar2).Value) : "";

            return(lines);
        }
Esempio n. 24
0
        private static Relation[] GetRelations(Parameters parameters, string[] realVariableNames)
        {
            ParameterWithSubParams <int> sp = parameters.GetParamWithSubParams <int>("Number of relations");
            int             nrel            = sp.Value + 1;
            List <Relation> result          = new List <Relation>();
            Parameters      param           = sp.GetSubParameters();

            for (int j = 0; j < nrel; j++)
            {
                string rel = param.GetParam <string>("Relation " + (j + 1)).Value;
                if (rel.StartsWith(">") || rel.StartsWith("<") || rel.StartsWith("="))
                {
                    rel = "x" + rel;
                }
                string   err1;
                Relation r = Relation.CreateFromString(rel, realVariableNames, new string[0], out err1);
                result.Add(r);
            }
            return(result.ToArray());
        }
Esempio n. 25
0
        public string[] ExtractGroup(IMatrixData mdata, ParameterWithSubParams <int> p, ProcessInfo processInfo,
                                     string value, int colInd)
        {
            string[]          errors = new string[0];
            Parameter <int[]> mcp    = p.GetSubParameters().GetParam <int[]>(value);

            int[] inds = mcp.Value;
            if (inds.Length == 0)
            {
                return(errors);
            }
            string[] values   = new string[inds.Length];
            string[] groupids = new string[inds.Length];
            string[] v        = mdata.GetCategoryRowValuesAt(colInd);
            for (int i = 0; i < values.Length; i++)
            {
                groupids[i] = v[inds[i]];
            }
            return(groupids);
        }
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
                                ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            ParameterWithSubParams <int> scwsp = param.GetParamWithSubParams <int>("Action");
            Parameters spar = scwsp.GetSubParameters();

            switch (scwsp.Value)
            {
            case 0:
                ProcessDataCreate(mdata, spar);
                break;

            case 1:
                ProcessDataCreateFromGoupNames(mdata, spar, processInfo);
                break;

            case 2:
                ProcessDataEdit(mdata, spar);
                break;

            case 3:
                ProcessDataRename(mdata, spar);
                break;

            case 4:
                ProcessDataDelete(mdata, spar);
                break;

            case 5:
                ProcessDataWriteTemplateFile(mdata, spar);
                break;

            case 6:
                string err = ProcessDataReadFromFile(mdata, spar);
                if (err != null)
                {
                    processInfo.ErrString = err;
                }
                break;
            }
        }
Esempio n. 27
0
        public void RunDESeq2(Dictionary <string, int> samples, List <string> pairs1, List <string> pairs2,
                              IMatrixData mdata, REngine engine, ParameterWithSubParams <bool> fdrValid,
                              ParameterWithSubParams <bool> pValid, ParameterWithSubParams <bool> lfcValid)
        {
            engine.Evaluate("library(DESeq2)");
            engine.Evaluate("counts <- read.delim('Count_table.txt')");
            string keys = "", values = "";

            foreach (KeyValuePair <string, int> entry in samples)
            {
                if (keys.Length == 0)
                {
                    keys   = "'" + entry.Key + "'";
                    values = entry.Value.ToString();
                }
                else
                {
                    keys   = keys + ", " + "'" + entry.Key + "'";
                    values = values + ", " + entry.Value.ToString();
                }
            }
            string commandLine = String.Format("sample<-data.frame(groups = rep(c({0}), time = c({1})))", keys, values);

            engine.Evaluate(commandLine);
            engine.Evaluate("ds<-DESeqDataSetFromMatrix(countData = counts, colData = sample, design = ~groups)");
            engine.Evaluate("colnames(ds)<-colnames(counts)");
            engine.Evaluate("ds<-DESeq(ds)");
            foreach (string pair1 in pairs1)
            {
                foreach (string pair2 in pairs2)
                {
                    if (pair1 != pair2)
                    {
                        commandLine = String.Format("res<-results(ds, c('groups', '{0}', '{1}'))", pair1, pair2);
                        engine.Evaluate(commandLine);
                        engine.Evaluate("write.csv(res, file = 'results.csv')");
                        ExtractDESeq2Results(mdata, pair1, pair2, fdrValid, pValid, lfcValid);
                    }
                }
            }
        }
Esempio n. 28
0
        public static double GetBase(ParameterWithSubParams <int> form)
        {
            int RAW    = 0;
            int LN     = 1;
            int LOG10  = 2;
            int LOG2   = 3;
            int CUSTOM = 4;


            int formType = form.Value;

            if (formType == RAW)
            {
                return(-1);
            }

            if (formType == LN)
            {
                return(0);
            }

            if (formType == LOG10)
            {
                return(10);
            }
            else if (formType == LOG2)
            {
                return(2);
            }
            else if (formType == CUSTOM)
            {
                Parameters subParams = form.GetSubParameters();
                return(subParams.GetParam <double>("Base").Value);
            }
            else
            {
                return(-2);
            }
        }
Esempio n. 29
0
        public static string CheckNonDataParameters(IMatrixData mdata, Parameters param)
        {
            string workingDirectory = param.GetParam <string>("Working Directory").Value;

            int[] nameInd = new[] { param.GetParam <int>("Gene Name Column").Value };
            int   n_rep   = param.GetParam <int>("Number of Replicates").Value;
            ParameterWithSubParams <bool> getSmoothing = param.GetParamWithSubParams <bool>("Smoothing");

            //working directory checking
            if (!Directory.Exists(workingDirectory))
            {
                return("Select a valid working directory");
            }

            //smoothing checking
            if (getSmoothing.Value)
            {
                if (getSmoothing.GetSubParameters().GetParam <double>(PECAParameters.smoothingPar1).Value <= 0 || getSmoothing.GetSubParameters().GetParam <double>(PECAParameters.smoothingPar2).Value <= 0)
                {
                    return("Smoothing parameters should be positive real numbers");
                }
            }

            //select data checking
            if (nameInd.Length == 0)
            {
                return("Select a gene name column");
            }

            //MCMC parameters checking

            if (param.GetParam <int>("MCMC Burn-In").Value <= 0 || param.GetParam <int>("MCMC Thinning").Value <= 0 || param.GetParam <int>("MCMC Samples").Value <= 0)
            {
                return("MCMC parameters should be positive integers");
            }

            return(null);
        }
Esempio n. 30
0
        public void ExtractEdgeRResults(IMatrixData mdata, string pair1, string pair2,
                                        ParameterWithSubParams <bool> fdrValid, ParameterWithSubParams <bool> pValid,
                                        ParameterWithSubParams <int> lfcValid, bool replicate, string resultName)
        {
            double[]     fcs    = GetCutoffLogFC(lfcValid, resultName, "EdgeR");
            StreamReader reader = new StreamReader(File.OpenRead(resultName));
            Dictionary <string, string[]> results = SetInitDict(mdata, "EdgeR");
            int lineNum = 0;

            string[][] sigCol   = new string[mdata.Values.RowCount][];
            string[][] validCol = new string[mdata.Values.RowCount][];
            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                if (!String.IsNullOrWhiteSpace(line))
                {
                    line = line.Replace("\"", "");
                    string[] info = line.Split(',');
                    if (lineNum != 0)
                    {
                        if (replicate)
                        {
                            StoreResult(results, sigCol, lineNum, fdrValid, pValid, lfcValid,
                                        info[1], info[2], info[4], info[5], info[3], fcs);
                        }
                        else
                        {
                            StoreResult(results, sigCol, lineNum, fdrValid, pValid, lfcValid,
                                        info[1], info[2], info[3], info[4], "NA", fcs);
                        }
                    }
                }
                lineNum++;
            }
            reader.Close();
            ImportResult(results, mdata, pair1, pair2, validCol, sigCol, "EdgeR", replicate);
        }