public Result RunSimulations(int numRuns, int numCuts, double probabilityEvent, String modelDatabase = "", bool extendedOutput = false) { SimulationId = DateTime.Now.ToString("yyyyMMddhhmmss"); Result res = new Result(); res.SimulationId = SimulationId; res.ChromosomeName = Source.Name; res.Runs = numRuns; res.Cuts = numCuts; res.Probability = probabilityEvent; res.Hmm = modelDatabase; ExtendedOutput = extendedOutput; App.Log("<div id='chromoDiv" + SimulationId + "'><b>Chromothripsis Simulation ID " + SimulationId + " on Chromosome " + Source.Name + " - " + numRuns.ToString() + " runs " + "- Simulating " + numCuts.ToString() + " cuts, " + probabilityEvent.ToString() + " probability</b></div>"); App.LogScroll(); DateTime tStart = DateTime.Now; NumGenes = 0; NumOrf = 0; FusionSequences = new List <FusionSequence>(); Hmmer = new Hmmer(); Hmmer.Debug = false; if (modelDatabase != "") { Hmmer.SetDatabase(modelDatabase); } if (ExtendedOutput) { App.HideLog(); } for (int i = 0; i < numRuns; i++) { Simulate(numCuts, probabilityEvent); if ((i % 10) == 0) { int percent = (int)(((double)i / (double)numRuns) * 100); App.Status("Simulation Progress: " + percent.ToString() + "%"); } } App.Status(); if (ExtendedOutput) { App.ShowLog(); } if (ExtendedOutput) { App.Log(""); } App.Log("Found a total of " + NumGenes.ToString() + " fusion genes<"); if (ExtendedOutput) { App.Log("<b>Performing Hmmer Scan...</b>"); App.LogScroll(); } //App.HideLog(); double totalScore = Hmmer.DoScan(); App.Log("Total Hmmer Score: " + totalScore.ToString("#0.00") + ""); // App.ShowLog(); List <Hmmer.Result> results = Hmmer.GetResults(); int NumHitOrfs = 0; String resultTable = ""; if (ExtendedOutput) { resultTable = "<br/><div id='chromoResults" + SimulationId + "'><table>" + "<tr><th>Simulation Id</th><th>Sequence ID</th><th>Score</th><th>Target Name</th><th>Accession</th><th>Exon 1</th>" + "<th>Start 1</th><th>Length 1</th><th>Exon 2</th><th>Start 2</th><th>Length 2</th><th>ORF</th><th>Sequence</th></tr>"; } foreach (Hmmer.Result result in results) { int seqId = Convert.ToInt32(result.SequenceName); FusionSequence fs = FusionSequences[seqId]; if (!fs.IsHit) { fs.IsHit = true; FusionSequences[seqId] = fs; NumHitOrfs++; } if (ExtendedOutput) { resultTable += "<tr><td>" + SimulationId + "</td><td>" + fs.SequenceId + "</td><td>" + result.Score.ToString("#0.00") + "</td><td>" + result.Name + "</td><td>" + result.Accession + "</td><td>" + fs.Exon1.Name + "</td><td>" + fs.Range1.Start + "</td><td>" + fs.Range1.Length + "</td><td>" + fs.Exon2.Name + "</td><td>" + fs.Range2.Start + "</td><td>" + fs.Range2.Length + "</td><td>" + fs.OrfName + "</td><td>" + fs.Sequence + "</tr>"; } } if (ExtendedOutput) { resultTable += "</table></div>"; } App.Log("Number of fusion sequences that produced hits: " + NumHitOrfs + ""); if (ExtendedOutput) { App.Log(resultTable); } if (ExtendedOutput) { App.Log(""); } DateTime tEnd = DateTime.Now; TimeSpan tDiff = tEnd - tStart; double perSecond = ((double)numRuns / (tDiff.TotalMilliseconds / (double)1000)); res.NumHits = results.Count; res.NumGenes = NumGenes; res.NumHitOrfs = NumHitOrfs; res.NumOrfs = NumOrf; res.TotalScore = totalScore; res.RunsPerSecond = perSecond; App.Log("Finished. " + perSecond.ToString("#0") + " runs per second, time elapsed: " + tDiff.ToString(@"mm\:ss")); App.Log("<br/>"); App.LogScroll(); UpdateOverview(res); return(res); }
protected void OnFusionEvent(Range fragment1, Range fragment2) { Exon ex1 = Source.WithinExon(fragment1.End); Exon ex2 = Source.WithinExon(fragment2.Start); // 10371808 // 103718617 if ((ex1 != null) && (ex2 != null)) { // Both sides of the cut are within exons if (ex1.Strand == ex2.Strand) { // Both exons are on same strand int bpExon1 = (int)(fragment1.End - ex1.Start); int bpExon2 = (int)(ex2.End - fragment2.Start); int percentExon1 = (int)(((double)bpExon1 / ex1.Length) * 100); int percentExon2 = (int)(((double)bpExon2 / ex2.Length) * 100); if ((bpExon1 > 100) && (bpExon2 > 100)) { String seqFusion, seq1, seq2; Range rangeLeft = new Range(ex1.Start, fragment1.End); Range rangeRight = new Range(fragment2.Start, ex2.End); seq1 = Source.Read(rangeLeft.Start, (int)rangeLeft.Length); seq2 = Source.Read(rangeRight.Start, (int)rangeRight.Length); seqFusion = seq1 + seq2; Dictionary <String, String> orfs = new Dictionary <string, string>(); orfs.Add("Forward 0", Sequencer.GetORF(seqFusion, 0)); orfs.Add("Forward 1", Sequencer.GetORF(seqFusion, 1)); orfs.Add("Forward 2", Sequencer.GetORF(seqFusion, 2)); String seqInv = Sequencer.Invert(Sequencer.Complement(seqFusion)); orfs.Add("Reverse 0", Sequencer.GetORF(seqInv, 0)); orfs.Add("Reverse 1", Sequencer.GetORF(seqInv, 1)); orfs.Add("Reverse 2", Sequencer.GetORF(seqInv, 2)); Dictionary <String, String> peptides = new Dictionary <string, string>(); bool bSignificantPeptides = false; foreach (String key in orfs.Keys) { if (orfs[key].Length >= 120) { String pep = Sequencer.Translate(orfs[key]); peptides.Add(key, pep); bSignificantPeptides = true; } } if (bSignificantPeptides) { NumGenes++; String htmlEx1 = "<a href='http://www.ensembl.org/Homo_sapiens/Search/Details?species=Homo_sapiens;idx=Transcript;end=1;q=" + ex1.Name + "' target='_blank'>" + ex1.Name + "</a> " + bpExon1.ToString() + "bp (" + percentExon1.ToString() + "%)"; String htmlEx2 = "<a href='http://www.ensembl.org/Homo_sapiens/Search/Details?species=Homo_sapiens;idx=Transcript;end=1;q=" + ex2.Name + "' target='_blank'>" + ex2.Name + "</a> " + bpExon2.ToString() + "bp (" + percentExon2.ToString() + "%)"; if (ExtendedOutput) { App.Log("<b>Found Fusion Gene #" + NumGenes + ": </b>" + htmlEx1 + " <b>&</b> " + htmlEx2 + ""); } // App.Log("Fusion Sequence: " + seqFusion); foreach (String key in peptides.Keys) { String pep = peptides[key]; if (ExtendedOutput) { App.Log(key + ": " + pep); } FusionSequence fs = new FusionSequence(); fs.SequenceId = NumOrf.ToString(); fs.IsHit = false; fs.Exon1 = ex1; fs.Exon2 = ex2; fs.OrfName = key; fs.Range1 = rangeLeft; fs.Range2 = rangeRight; fs.Sequence = pep; FusionSequences.Insert(NumOrf, fs); Hmmer.AddSequence(pep, fs.SequenceId); //String sequenceName = "#" + NumGenes+" "+ex1.Name + " " + percentExon1.ToString() + "% & " + ex2.Name + " " + percentExon2.ToString() + "% ORF " + key; NumOrf++; } } // if (bSignificantPeptides) } // if ((bpExon1 > 100) && (bpExon2 > 100)) } // if (ex1.Strand == ex2.Strand) } // if ((ex1 != null) && (ex2 != null)) else { //App.Log("No Fusion Gene :("); } }