public MicroRNASimHelper(IReadOnlyDictionary <string, MiRNA> miRNAs = null, bool useGSESAME = false, Mode mode = Mode.Count) { _miRNAs = miRNAs ?? DAGLoader.LoadMicroRNA2(Config.MiRNAPath); _miRNASimCache = new Dictionary <string, Dictionary <string, double> >(); _goSimHelpers = Enumerable.Range(1, Config.DAGCount).Select(i => new GOSimHelper(i)).ToArray(); _jobs = new List <MiRNASim>(); _useGSESAME = useGSESAME; _mode = mode; }
public static void RunAllRNA(bool useGSESAME, MicroRNASimHelper.Mode mode, int start = 0, int end = 10000) { string simFileName = string.Format("sim_{0}_{1}", useGSESAME ? "GSESAME" : "Ours", mode.ToString()); Config.DAGPathPattern = @"DAG_new{0}.txt"; Config.MiRNAPath = "miranda"; Config.GeneralTablePath = "Go_annotated_times.txt"; Config.RNASimCacheFile = simFileName + "Cache.json"; RNASimCache.Read(Config.RNASimCacheFile); var stateTimer = new Timer(obj => RNASimCache.Save(Config.RNASimCacheFile), null, 600000, 60000); int maxConcurrency = Math.Min(20, Environment.ProcessorCount); Console.WriteLine("Using {0} threads.", maxConcurrency); var miRNAs = DAGLoader.LoadMicroRNA2(Config.MiRNAPath); GOSimHelper.InitGOSimCache(miRNAs.SelectMany(m => m.Value.GOs).Distinct().ToArray()); List <MicroRNASimHelper> helpers = new List <MicroRNASimHelper>(); for (int i = 0; i < maxConcurrency; i++) { helpers.Add(new MicroRNASimHelper(miRNAs, useGSESAME, mode)); Console.WriteLine("Helper {0} initialized.", i); } var allRNAs = helpers.First().AllRNAs; end = Math.Min(end, allRNAs.Length); for (int i = start; i < end; i++) { for (int j = mode == MicroRNASimHelper.Mode.Euclidean ? start : i; j < allRNAs.Length; j++) { helpers[i % maxConcurrency].AddJob(allRNAs[i], allRNAs[j]); } } var tasks = helpers.Select(h => h.CalcAllJobsAsync()).ToArray(); Task.WaitAll(tasks); var sims = tasks.SelectMany(t => t.Result).ToList(); stateTimer.Dispose(); File.WriteAllText(simFileName + ".json", JsonConvert.SerializeObject(sims)); }
public static void TestSingle() { Config.DAGPathPattern = @"DAG_new{0}.txt"; Config.MiRNAPath = "miranda"; var miRNAs = DAGLoader.LoadMicroRNA2(Config.MiRNAPath); GOSimHelper.InitGOSimCache(miRNAs.SelectMany(m => m.Value.GOs).Distinct().ToArray()); MicroRNASimHelper rnaSim = new MicroRNASimHelper(miRNAs, false, MicroRNASimHelper.Mode.Euclidean); Stopwatch watch = new Stopwatch(); watch.Start(); //hsa-let-7c,hsa-let-7d-star Console.WriteLine(string.Join(", ", rnaSim.CalcSim("hsa-let-7c", "hsa-let-7d-star"))); Console.WriteLine("used seconds: " + watch.ElapsedMilliseconds / 1000.0); Console.ReadKey(); }
public GOSimHelper(int dagId) { string dagFileName = string.Format(Config.DAGPathPattern, dagId); var dag = DAGLoader.LoadPreprocessedDAG(dagFileName); _totalGenes = dag.TotalGenes; _base = Math.Log(dag.TotalAnotedTimes); _allGO = dag.nodes.Keys.ToArray(); _dag = new DAGNode[dag.nodes.Keys.Max() + 1]; _aliasMapping = dag.AliasMapping; if (GOSimCache == null) { InitGOSimCache(_allGO); } foreach (var p in _aliasMapping) { var truncatedGO = p.Value.TruncateGO(); if (GOSimCache[p.Value.TruncateGO()] == null) { GOSimCache[truncatedGO] = new float[MaxGOTruncated + 1];//new Dictionary<int, double>(); Array.Clear(GOSimCache[truncatedGO], 0, MaxGOTruncated + 1); } } foreach (var p in dag.nodes) { _dag[p.Key] = p.Value; } if (_aliasMapping != null) { foreach (var pair in _aliasMapping) { _dag[pair.Key] = _dag[pair.Value]; } } //_goSimCache = new Dictionary<int, Dictionary<int, double>>(); _bitmap = new byte[_allGO.Max() + 1]; Array.Clear(_bitmap, 0, _bitmap.Length); }