private double CalcSimOnDAG_Max(string rna1, string rna2, GOSimHelper goSimHelper) { double sim = 0; var goSet1 = _miRNAs[rna1].GOs; var goSet2 = _miRNAs[rna2].GOs; var filteredGOSet1 = goSimHelper.FilterGOs(goSet1); var filteredGOSet2 = goSimHelper.FilterGOs(goSet2); if (filteredGOSet1.Count == 0 || filteredGOSet2.Count == 0) { return(0.0); } foreach (var go in filteredGOSet1) { foreach (var go2 in filteredGOSet2) { var sim2 = _useGSESAME ? goSimHelper.CalcGOSim_GSESAME(go, go2) : goSimHelper.CalcGOSim(go, go2); if (sim < sim2) { sim = (float)sim2; } } } return(sim); }
private float CalcGoGeneSim(int go, List <int> geneGOSet, GOSimHelper goSimHelper) { var maxSim = float.MinValue; foreach (var geneGO in geneGOSet) { var sim = _useGSESAME ? goSimHelper.CalcGOSim_GSESAME(go, geneGO) : goSimHelper.CalcGOSim(go, geneGO); //6355,8150 = Infinity? if (maxSim < sim) { maxSim = (float)sim; } } return(maxSim); }
private double GetOrSetWeightCache(string rna, int go, GOSimHelper goSimHelper) { double wx = 0; if (_miRNAs[rna].WeightCache.ContainsKey(go)) { wx = _miRNAs[rna].WeightCache[go]; } else { wx = HyperWeight.CalculateWeight(goSimHelper.TotalGenes, goSimHelper.Dag[go].P_an, _miRNAs[rna].nTargetGeneCount, _miRNAs[rna].kGOAnnotatedCount[go]); _miRNAs[rna].WeightCache[go] = wx; } return(wx); }
private double CalcSimOnDAG_Euclidean(string rna1, string rna2, GOSimHelper goSimHelper) { double sim = 0; var goSet1 = _miRNAs[rna1].GOs; var goSet2 = _miRNAs[rna2].GOs; var filteredGOSet1 = goSimHelper.FilterGOs(goSet1); var filteredGOSet2 = goSimHelper.FilterGOs(goSet2); foreach (var go in filteredGOSet1) { double wx = GetOrSetWeightCache(rna1, go, goSimHelper); double cSim = CalcGoGeneSim(go, filteredGOSet2, goSimHelper); sim += (wx * cSim * wx * cSim); } return(Math.Sqrt(sim)); }
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(); }
private double CalcSimOnDAG_HyperOrCount(string rna1, string rna2, GOSimHelper goSimHelper) { double sim = 0; int count = 0; var goSet1 = _miRNAs[rna1].GOs; var goSet2 = _miRNAs[rna2].GOs; var filteredGOSet1 = goSimHelper.FilterGOs(goSet1); var filteredGOSet2 = goSimHelper.FilterGOs(goSet2); if (filteredGOSet1.Count == 0 || filteredGOSet2.Count == 0) { return(0.0); } Dictionary <int, double> maxSimReverse = new Dictionary <int, double>(); foreach (var go in filteredGOSet2) { maxSimReverse[go] = double.MinValue; } foreach (var go in filteredGOSet1) { double wx = 0; if (_mode == Mode.Hyper) { wx = GetOrSetWeightCache(rna1, go, goSimHelper); } else { wx = _miRNAs[rna1].kGOAnnotatedCount[go]; count += _miRNAs[rna1].kGOAnnotatedCount[go]; } var maxSim = float.MinValue; foreach (var go2 in filteredGOSet2) { var sim2 = _useGSESAME ? goSimHelper.CalcGOSim_GSESAME(go, go2) : goSimHelper.CalcGOSim(go, go2); if (maxSim < sim2) { maxSim = (float)sim2; } if (maxSimReverse[go2] < sim2) { maxSimReverse[go2] = sim2; } } sim += wx * maxSim; } foreach (var go in filteredGOSet2) { double wx = 0; if (_mode == Mode.Hyper) { wx = GetOrSetWeightCache(rna2, go, goSimHelper); } else { wx = _miRNAs[rna2].kGOAnnotatedCount[go]; count += _miRNAs[rna2].kGOAnnotatedCount[go]; } sim += wx * maxSimReverse[go]; } return(sim / (_mode == Mode.Hyper ? (filteredGOSet1.Count + filteredGOSet2.Count) : count)); }