Beispiel #1
0
        static public int CreateHmmModelFile(String[] models, String filename)
        {
            // Generate list of unique accession IDs
            List <string> IDs = new List <string>();

            foreach (String line in models)
            {
                String s = line.Trim();
                if (s == "")
                {
                    continue;
                }
                if (s[0] == '>')
                {
                    continue;
                }

                String id = s.Substring(0, s.IndexOf(':'));
                if (!IDs.Contains(id))
                {
                    IDs.Add(id);
                }
            }


            // Parse PFAM-A.HMM and write new HMM file
            String       fnSource = Hmmer.ModelPath;
            StreamReader source   = new StreamReader(fnSource);

            String       fnDest = Hmmer.ModelFolder + filename + ".hmm";
            StreamWriter dest   = new StreamWriter(fnDest);

            int i        = 0;
            int iWritten = 0;

            while (source.Peek() >= 0)
            {
                String model = Hmmer.ReadNextModel(source);
                String acc   = Hmmer.GetModelAcc(model);
                if (IDs.Contains(acc))
                {
                    dest.Write(model);
                    iWritten++;
                }
                i++;
            }

            if (iWritten != IDs.Count)
            {
                throw new Exception("Model Count Mismatch");
            }

            source.Close();
            dest.Close();

            return(iWritten);
        }
Beispiel #2
0
        static public String FusionHmmScan(String title, String seq1, String seq2)
        {
            String ret = "";

            seq1 = FastaConverter.ConvertString(seq1);
            seq2 = FastaConverter.ConvertString(seq2);

            List <String> seqs = new List <string>();

            for (int i = 0; i < 5; i++)
            {
                seqs.Add(seq1 + seq2);                       // + +
                seqs.Add(seq1 + Sequencer.InvCompl(seq2));   // + -
                seqs.Add(Sequencer.InvCompl(seq1) + seq2);   // - +

                // 20% deletieren
                int cut1 = (int)Math.Round(seq1.Length * 0.2);
                int cut2 = (int)Math.Round(seq2.Length * 0.2);
                seq1 = seq1.Substring(0, seq1.Length - cut1);
                seq2 = seq2.Substring(cut2);
            }


            List <String> orfs = new List <string>();

            foreach (String seq in seqs) // 6-frame ORFs
            {
                orfs.Add(seq.Substring(0));
                orfs.Add(seq.Substring(1));
                orfs.Add(seq.Substring(2));

                String seqInv = Sequencer.InvCompl(seq);
                orfs.Add(seqInv.Substring(0));
                orfs.Add(seqInv.Substring(1));
                orfs.Add(seqInv.Substring(2));
            }


            Hmmer hmmer = new Hmmer();

            Hmmer.SetDatabase("PFam-A");
            Hmmer.Debug = true;

            int c = 0;

            foreach (String orf in orfs)
            {
                String peptide = Sequencer.Translate(orf, true); // Translatieren ohne Stop-Codon
                hmmer.AddSequence(peptide, title + " #" + c.ToString());
                c++;
            }

            hmmer.DoScan();

            List <Hmmer.Result> results       = hmmer.GetResults();
            List <string>       resultsUnique = new List <string>();

            ret += "> " + title + Environment.NewLine;

            foreach (Hmmer.Result result in results)
            {
                if (result.Evalue >= 1)
                {
                    continue;
                }

                string res = result.Accession + ": " + result.Name;
                if (!resultsUnique.Contains(res))
                {
                    resultsUnique.Add(res);
                    ret += res + Environment.NewLine;
                }
            }
            ret += Environment.NewLine;


            return(ret);
        }
Beispiel #3
0
        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);
        }