コード例 #1
0
        private void Score()
        {
            Peptides = ePeptides.Text
                       .Split('\n')
                       .Select(p => p.Trim())
                       .Where(p => !string.IsNullOrEmpty(p))
                       .ToList();
            if (Peptides.Count == 0)
            {
                MessageBox.Show("Please load a peptide list to score.");
                return;
            }
            if (Motif == null)
            {
                MessageBox.Show("Please load a motif.");
                return;
            }
            Scorer             = new Scorer();
            Scorer.Motif       = Motif;
            Scorer.PeptideList = Peptides;
            if (double.TryParse(eScorerPosThreshold.Text, out double posthres))
            {
                Scorer.UserEnteredPosThreshold = posthres;
            }
            else
            {
                Scorer.UserEnteredPosThreshold = null;
            }
            if (double.TryParse(eScorerNegThreshold.Text, out double negthres))
            {
                Scorer.UserEnteredNegThreshold = negthres;
            }
            else
            {
                Scorer.UserEnteredNegThreshold = null;
            }
            if (int.TryParse(ePosCutoff.Text, out int poscutoff))
            {
                Scorer.PosMatchCutoff = poscutoff;
            }
            if (int.TryParse(eNegCutoff.Text, out int negcutoff))
            {
                Scorer.NegMatchCutoff = negcutoff;
            }

            if (!Int32.TryParse(eTarget.Text, out int keyPosition))
            {
                keyPosition = 0;
            }
            Scorer.KeyPosition = keyPosition - 1;
            if (Scorer.KeyPosition < 0)
            {
                if (MessageBox.Show("It is recommended to have a key position. Do you want to continue?",
                                    "Warning", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    eTarget.Focus();
                    return;
                }
            }
            dgScores.Rows.Clear();
            Scorer.StopScoringRequested = false;
            frmProgressDialog prdlg = new frmProgressDialog
            {
                ProgressMax = Peptides.Count
            };

            Task maintask = Task.Run(() =>
            {
                Scorer.ScorePeptideList(() => Invoke(new Action(() => prdlg.ProgressValue++)));
                Thread.Sleep(200);
                Invoke(new Action(() => prdlg.Close()));
            });

            if (prdlg.ShowDialog() == DialogResult.Cancel)
            {
                Scorer.StopScoringRequested = true;
            }
            maintask.Wait();
            AddScoresToGrid(Scorer.ScoreList);
        }
コード例 #2
0
        protected override void Score()
        {
            if (Proteins.Count == 0)
            {
                MessageBox.Show("Please load a protein sequence to score.");
                return;
            }
            if (Motif == null)
            {
                MessageBox.Show("Please load a motif.");
                return;
            }
            Scorer             = new Scorer();
            Scorer.Motif       = Motif;
            Scorer.ProteinList = Proteins;
            if (double.TryParse(eScorerPosThreshold.Text, out double posthres))
            {
                Scorer.UserEnteredPosThreshold = posthres;
            }
            else
            {
                Scorer.UserEnteredPosThreshold = null;
            }
            if (double.TryParse(eScorerNegThreshold.Text, out double negthres))
            {
                Scorer.UserEnteredNegThreshold = negthres;
            }
            else
            {
                Scorer.UserEnteredNegThreshold = null;
            }
            if (int.TryParse(ePosCutoff.Text, out int poscutoff))
            {
                Scorer.PosMatchCutoff = poscutoff;
            }
            if (int.TryParse(eNegCutoff.Text, out int negcutoff))
            {
                Scorer.NegMatchCutoff = negcutoff;
            }

            if (!Int32.TryParse(eTargetPosition.Text, out int keyPosition))
            {
                keyPosition = 0;
            }
            Scorer.KeyPosition = keyPosition - 1;
            if (Scorer.KeyPosition < 0)
            {
                if (MessageBox.Show("It is recommended to have a key position. Do you want to continue?",
                                    "Warning", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    eTargetPosition.Focus();
                    return;
                }
            }
            ClearResults();

            Scorer.StopScoringRequested = false;
            frmProgressDialog prdlg = new frmProgressDialog
            {
                ProgressMax = (int)Proteins.Sum(p => Math.Ceiling((double)(p.AASequence.Length - Motif.PeptideLength + 1)))
            };

            Task maintask = Task.Run(() =>
            {
                Scorer.ScoreProteinList(progress => Invoke(new Action(() => prdlg.ProgressValue = progress)));
                Thread.Sleep(200);
                Invoke(new Action(() => prdlg.Close()));
            });

            if (prdlg.ShowDialog() == DialogResult.Cancel)
            {
                Scorer.StopScoringRequested = true;
            }
            maintask.Wait();
            AddScoresToGrid(Scorer.ScoreList);
        }