public void SetSymbolCharMatrix(string name, string[,] value)
        {
            clsRCmdLog.LogRComment(string.Format("RdnConnectorClass.SetSymbolCharMatrix:{0}", name));
            var sym = _engine.CreateCharacterMatrix(value);

            _engine.SetSymbol(name, sym);
        }
Exemple #2
0
        private void SetupDotNetToRConverters()
        {
            SetupDotNetToRConverter(typeof(void), p => null);

            SetupDotNetToRConverter(typeof(string), p => engine.CreateCharacter((string)p));
            SetupDotNetToRConverter(typeof(string[]), p => engine.CreateCharacterVector((string[])p));
            SetupDotNetToRConverter(typeof(List <string>), p => engine.CreateCharacterVector((IEnumerable <string>)p));
            SetupDotNetToRConverter(typeof(IList <string>), p => engine.CreateCharacterVector((IEnumerable <string>)p));
            SetupDotNetToRConverter(typeof(ICollection <string>), p => engine.CreateCharacterVector((IEnumerable <string>)p));
            SetupDotNetToRConverter(typeof(IEnumerable <string>), p => engine.CreateCharacterVector((IEnumerable <string>)p));
            SetupDotNetToRConverter(typeof(string[, ]), p => engine.CreateCharacterMatrix((string[, ])p));

            SetupDotNetToRConverter(typeof(int), p => engine.CreateInteger((int)p));
            SetupDotNetToRConverter(typeof(int[]), p => engine.CreateIntegerVector((int[])p));
            SetupDotNetToRConverter(typeof(List <int>), p => engine.CreateIntegerVector((IEnumerable <int>)p));
            SetupDotNetToRConverter(typeof(IList <int>), p => engine.CreateIntegerVector((IEnumerable <int>)p));
            SetupDotNetToRConverter(typeof(ICollection <int>), p => engine.CreateIntegerVector((IEnumerable <int>)p));
            SetupDotNetToRConverter(typeof(IEnumerable <int>), p => engine.CreateIntegerVector((IEnumerable <int>)p));
            SetupDotNetToRConverter(typeof(int[, ]), p => engine.CreateIntegerMatrix((int[, ])p));

            SetupDotNetToRConverter(typeof(bool), p => engine.CreateLogical((bool)p));
            SetupDotNetToRConverter(typeof(bool[]), p => engine.CreateLogicalVector((bool[])p));
            SetupDotNetToRConverter(typeof(List <bool>), p => engine.CreateLogicalVector((IEnumerable <bool>)p));
            SetupDotNetToRConverter(typeof(IList <bool>), p => engine.CreateLogicalVector((IEnumerable <bool>)p));
            SetupDotNetToRConverter(typeof(ICollection <bool>), p => engine.CreateLogicalVector((IEnumerable <bool>)p));
            SetupDotNetToRConverter(typeof(IEnumerable <bool>), p => engine.CreateLogicalVector((IEnumerable <bool>)p));
            SetupDotNetToRConverter(typeof(bool[, ]), p => engine.CreateLogicalMatrix((bool[, ])p));

            SetupDotNetToRConverter(typeof(double), p => engine.CreateNumeric((double)p));
            SetupDotNetToRConverter(typeof(double[]), p => engine.CreateNumericVector((double[])p));
            SetupDotNetToRConverter(typeof(List <double>), p => engine.CreateNumericVector((IEnumerable <double>)p));
            SetupDotNetToRConverter(typeof(IList <double>), p => engine.CreateNumericVector((IEnumerable <double>)p));
            SetupDotNetToRConverter(typeof(ICollection <double>), p => engine.CreateNumericVector((IEnumerable <double>)p));
            SetupDotNetToRConverter(typeof(IEnumerable <double>), p => engine.CreateNumericVector((IEnumerable <double>)p));
            SetupDotNetToRConverter(typeof(double[, ]), p => engine.CreateNumericMatrix((double[, ])p));

            SetupDotNetToRConverter(typeof(DateTime), p => engine.CreatePosixct((DateTime)p));
            SetupDotNetToRConverter(typeof(DateTime[]), p => engine.CreatePosixctVector((DateTime[])p));
            SetupDotNetToRConverter(typeof(List <DateTime>), p => engine.CreatePosixctVector((IEnumerable <DateTime>)p));
            SetupDotNetToRConverter(typeof(IList <DateTime>), p => engine.CreatePosixctVector((IEnumerable <DateTime>)p));
            SetupDotNetToRConverter(typeof(ICollection <DateTime>), p => engine.CreatePosixctVector((IEnumerable <DateTime>)p));
            SetupDotNetToRConverter(typeof(IEnumerable <DateTime>), p => engine.CreatePosixctVector((IEnumerable <DateTime>)p));
            SetupDotNetToRConverter(typeof(DateTime[, ]), p => engine.CreatePosixctMatrix((DateTime[, ])p));

            SetupDotNetToRConverter(typeof(TimeSpan), p => engine.CreateDiffTime((TimeSpan)p));
            SetupDotNetToRConverter(typeof(TimeSpan[]), p => engine.CreateDiffTimeVector((TimeSpan[])p));
            SetupDotNetToRConverter(typeof(List <TimeSpan>), p => engine.CreateDiffTimeVector((IEnumerable <TimeSpan>)p));
            SetupDotNetToRConverter(typeof(IList <TimeSpan>), p => engine.CreateDiffTimeVector((IEnumerable <TimeSpan>)p));
            SetupDotNetToRConverter(typeof(ICollection <TimeSpan>), p => engine.CreateDiffTimeVector((IEnumerable <TimeSpan>)p));
            SetupDotNetToRConverter(typeof(IEnumerable <TimeSpan>), p => engine.CreateDiffTimeVector((IEnumerable <TimeSpan>)p));
            SetupDotNetToRConverter(typeof(TimeSpan[, ]), p => engine.CreateDiffTimeMatrix((TimeSpan[, ])p));
        }
        private void runTask()
        {
            string basedir = AppDomain.CurrentDomain.BaseDirectory;
            string mapPath = basedir + "/tmp/";
//            string mapPath = HttpContext.Current.Server.MapPath("~/tmp/");
            REngine engine          = Utils.getREngineInstance();
            string  primer3path     = System.Web.Configuration.WebConfigurationManager.AppSettings["primer3Home"];
            string  processNum      = System.Web.Configuration.WebConfigurationManager.AppSettings["processNum"];
            string  isDeleteTempDir = System.Web.Configuration.WebConfigurationManager.AppSettings["deleteTempDir"];

            while (true)
            {
                if (task_queue.Count != 0)
                {
                    Application.Lock();
                    CustomTask customTask = (CustomTask)task_queue.Dequeue();
                    Application.UnLock();
                    customTask.waitQueue = 0;
                    Object[] task_queue_array = task_queue.ToArray();
                    for (int i = 0; i < task_queue_array.Length; i++)
                    {
                        CustomTask tmpTask = (CustomTask)task_queue_array[i];
                        tmpTask.waitQueue = i + 1;
                    }
                    Application["running_task"] = customTask;
                    string fileName = customTask.url;
                    fileName = basedir + "/" + customTask.url;
                    DataTable dt = read_primer_sequence(fileName);
                    string[,] primerMat = getPrimerMat(dt);
                    customTask.status   = "preparing ...";
                    WriteLog(customTask.key, customTask);
                    CharacterMatrix primer    = engine.CreateCharacterMatrix(primerMat);
                    string          rand_file = System.IO.Path.GetRandomFileName();
                    string          tmp_path  = mapPath + rand_file;
                    //string primer3path = "D:/Install/primer3-win-bin-2.3.6";

                    if (Directory.Exists(tmp_path))
                    {
                        DirectoryInfo di = new DirectoryInfo(tmp_path);
                        di.Delete(true);
                    }
                    else if (File.Exists(tmp_path))
                    {
                        FileInfo fi = new FileInfo(tmp_path);
                        fi.Delete();
                    }
                    Directory.CreateDirectory(tmp_path);
                    engine.Evaluate("library(xlsx)");
                    customTask.percent = 8;
                    string script_path = basedir + "/primer_dimer_check.R";
                    script_path = script_path.Replace(@"\", @"/");
                    engine.Evaluate("source(\"" + script_path + "\")");
                    customTask.percent = 10;
                    engine.SetSymbol("primer", primer);
                    engine.SetSymbol("tmp_dir", engine.CreateCharacter(tmp_path));
                    engine.SetSymbol("primer", primer);
                    engine.SetSymbol("primer3dir", engine.CreateCharacter(primer3path));
                    int?nProcess = Convert.ToInt32(processNum);
                    if (nProcess != null)
                    {
                        engine.SetSymbol("nprocess", engine.CreateInteger(Convert.ToInt32(nProcess)));
                    }
                    else
                    {
                        engine.SetSymbol("nprocess", engine.CreateInteger(4));
                    }
                    engine.SetSymbol("outputfile", engine.CreateCharacter(fileName));
                    string[] bat_cmds = engine.Evaluate("prepare_bat(tmp_dir,primer,primer3dir,nprocess)").AsCharacter().ToArray();
                    customTask.status  = "dimer calculating ...";
                    customTask.percent = 20;
                    WriteLog(customTask.key, customTask);
                    AutoResetEvent[] resets = new AutoResetEvent[bat_cmds.Length];

                    for (int i = 0; i < bat_cmds.Length; i++)
                    {
                        resets[i] = new AutoResetEvent(false);
                        Global.ThreadTransfer transfer = new Global.ThreadTransfer(bat_cmds[i], resets[i]);
                        Thread thread = new Thread(new ParameterizedThreadStart(run_cmd));
                        thread.Start(transfer);
                    }
                    foreach (var v in resets)
                    {
                        v.WaitOne();
                        customTask.percent += 60 / resets.Length;
                    }
                    customTask.status  = "result generating ...";
                    customTask.percent = 80;
                    WriteLog(customTask.key, customTask);
                    engine.Evaluate("output_result(tmp_dir,primer,outputfile)");
                    if (isDeleteTempDir == "true")
                    {
                        DirectoryInfo di = new DirectoryInfo(tmp_path);
                        di.Delete(true);
                    }
                    customTask.status  = "complete";
                    customTask.percent = 100;
                    WriteLog(customTask.key, customTask);


                    Application["running_task"] = null;
                }
            }
        }