Exemplo n.º 1
0
        /// <summary>
        /// Returns a list of max scores, followed by the peptide in DB.
        /// </summary>
        /// <param name="peptide"></param>
        /// <param name="theDB"></param>
        /// <returns></returns>
        public KeyValuePair <List <int>, List <string> > GetClosestPeptideInDB(char[] peptide, List <FastaItem> theDB)
        {
            List <int>    Scores  = new List <int>();
            List <string> Closest = new List <string>();

            for (int i = 0; i < theDB.Count; i++)
            {
                FastaItem fi = theDB[i];

                List <int> res = Align(peptide, fi.Sequence.ToCharArray()).ToList();

                if (res.Count < peptide.Length)
                {
                    Scores.Add(-1);
                    Closest.Add("-1");
                    continue;
                }


                int maxScore    = res.Max();
                int MaxScorePos = res.ToList().IndexOf(maxScore);

                int correction = 0;
                if (fi.Sequence.Length - 1 < MaxScorePos + peptide.Length)
                {
                    correction = MaxScorePos + peptide.Length - fi.Sequence.Length;
                }
                string closestPeptideInProteinDB = new string(fi.Sequence.ToArray()).Substring(MaxScorePos, peptide.Length - correction);

                Scores.Add(maxScore);
                Closest.Add(closestPeptideInProteinDB);
            }

            return(new KeyValuePair <List <int>, List <string> >(Scores, Closest));
        }
Exemplo n.º 2
0
 public ProteinAnalysis(FastaItem fi, double coverage, List <PeptideAnalysis> myPepAnalysis)
 {
     MyFastaItem   = fi;
     Coverage      = coverage;
     MyPepAnalyses = myPepAnalysis;
     myPepAnalysis.Sort((a, b) => a.Sequence.Length.CompareTo(b.Sequence.Length));
 }
Exemplo n.º 3
0
 public ProtQuant(FastaItem fi, PepQuant pq)
 {
     MyFastaItem = fi;
     MyPepQuants = new List <PepQuant>()
     {
         pq
     };
 }
Exemplo n.º 4
0
        private void DisplayPeptides(List <AlignmentResult> alns, FastaItem thisProtein = null)
        {
            List <object> displayItems = new List <object>();

            foreach (AlignmentResult aln in alns)
            {
                string dbPep = "NA";

                if (thisProtein != null)
                {
                    dbPep = mAligner.GetClosestPeptideInASequence(PatternTools.pTools.CleanPeptide(aln.DeNovoRegistries[0].PtmSequence, true).ToCharArray(), thisProtein.Sequence.ToCharArray());
                }
                else if (thisProtein == null && aln.ProtIDs.Count > 0)
                {
                    List <string> pepsInDB = new List <string>();

                    foreach (string p in aln.ProtIDs)
                    {
                        FastaItem aProt = MyResultPackage.MyFasta.Find(a => a.SequenceIdentifier.Equals(p));
                        pepsInDB.Add(mAligner.GetClosestPeptideInASequence(PatternTools.pTools.CleanPeptide(aln.DeNovoRegistries[0].PtmSequence, true).ToCharArray(), aProt.Sequence.ToCharArray()));
                    }

                    pepsInDB = pepsInDB.Distinct().ToList();

                    dbPep = string.Join(", ", pepsInDB);
                }


                foreach (DeNovoR dnvr in aln.DeNovoRegistries)
                {
                    byte[] peptideBytes = Encoding.ASCII.GetBytes(PatternTools.pTools.CleanPeptide(dnvr.PtmSequence, true));
                    int    IDScore      = -1;

                    if (thisProtein != null)
                    {
                        IDScore = mAligner.IDScore(peptideBytes, thisProtein.SequenceInBytes);
                    }

                    displayItems.Add(new
                    {
                        FileName    = dnvr.FileName,
                        ScanNo      = dnvr.ScanNumber,
                        Z           = dnvr.Charge,
                        Redundancy  = aln.ProtIDs.Count,
                        DeNovoScore = dnvr.DeNovoScore,
                        DeNovoSeq   = dnvr.PtmSequence,
                        DBSeq       = dbPep,
                        Similarity  = aln.SimilarityScore,
                        //Identity = IDScore + " (" + Math.Round(((double)IDScore / (double)PatternTools.pTools.CleanPeptide(dnvr.PtmSequence, true).Length), 3) + ")"
                    });
                }
            }

            DataGridAln.ItemsSource = displayItems;
        }
Exemplo n.º 5
0
        private void DataGridProteins_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            object theSelection = DataGridProteins.SelectedItem;
            Dictionary <string, object> dict = theSelection.GetType().GetProperties().ToDictionary(x => x.Name, x => x.GetValue(theSelection, null));

            FastaItem thisProtein = MyResultPackage.MyFasta.Find(a => a.SequenceIdentifier.Equals(dict["ID"]));

            List <AlignmentResult> alns = MyResultPackage.Alignments.FindAll(a => a.ProtIDs.Contains(dict["ID"]));

            DisplayPeptides(alns, thisProtein);
        }
        /// <summary>
        /// Will perform a coverage plot
        /// </summary>
        /// <param name="theProtein">The PatternTools Fasta Item</param>
        /// <param name="peptides">A List of Tuples were the first item is a list of positions were this peptide aligns with the protein, the second item is the peptide sequence</param>
        public void Plot(FastaItem theProtein, List <Tuple <List <int>, string> > peptides)
        {
            peptides.Sort((a, b) => a.Item1[0].CompareTo(b.Item1[0]));

            PlotModel MyModel = new PlotModel();

            MyModel.Title = theProtein.SequenceIdentifier;

            MyModel.IsLegendVisible = false;


            IntervalBarSeries intervalBarSeriesProtein = new IntervalBarSeries();

            intervalBarSeriesProtein.Title = theProtein.SequenceIdentifier;
            intervalBarSeriesProtein.Items.Add(new IntervalBarItem(0, theProtein.Sequence.Length));


            var categoryAxis1 = new CategoryAxis();

            categoryAxis1.Position = AxisPosition.Left;
            categoryAxis1.Labels.Add(theProtein.SequenceIdentifier);

            MyModel.Series.Add(intervalBarSeriesProtein);

            IntervalBarSeries intervalBarSeriesPeptide = new IntervalBarSeries();

            //Lets insert a blank entry so that the first peptide appears in the first row
            intervalBarSeriesPeptide.FillColor = OxyColors.AliceBlue;
            intervalBarSeriesPeptide.Items.Add(new IntervalBarItem(0, 0));

            foreach (Tuple <List <int>, string> peptide in peptides)
            {
                foreach (int index in peptide.Item1)
                {
                    categoryAxis1.Labels.Add(peptide.Item2);
                    intervalBarSeriesPeptide.Title = peptide.Item2;
                    intervalBarSeriesPeptide.Items.Add(new IntervalBarItem(index, index + peptide.Item2.Length));

                    //And one series to show the coverage on the protein
                    IntervalBarSeries intervalBarSeriesPeptideProtein = new IntervalBarSeries();
                    intervalBarSeriesPeptideProtein.FillColor = OxyColors.AliceBlue;
                    intervalBarSeriesPeptideProtein.Items.Add(new IntervalBarItem(index, index + peptide.Item2.Length));
                    MyModel.Series.Add(intervalBarSeriesPeptideProtein);
                }
            }

            MyModel.Series.Add(intervalBarSeriesPeptide);

            MyModel.Axes.Add(categoryAxis1);

            MyPlot.Model = MyModel;
        }
Exemplo n.º 7
0
        private List <string> GetDBSequences(FastaItem fi)
        {
            List <AlignmentResult> alns = MyResultPackage.Alignments.FindAll(a => a.ProtIDs.Contains(fi.SequenceIdentifier));

            List <string> dnvPeptides = (from a in alns
                                         from d in a.DeNovoRegistries
                                         select PatternTools.pTools.CleanPeptide(d.PtmSequence, true)).Distinct().ToList();


            List <string> sequencePeptides = (from dnv in dnvPeptides
                                              select mAligner.GetClosestPeptideInASequence(dnv.ToArray(), fi.Sequence.ToCharArray())).Distinct().ToList();

            return(sequencePeptides);
        }
Exemplo n.º 8
0
 private void DataGridProteinView_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         int si = DataGridProteinView.SelectedIndex;
         Dictionary <string, object> ao = PatternTools.pTools.AnonymousToDictionary(DataGridProteinView.SelectedItems[0]);
         FastaItem theKey = MyFastaItems.Find(a => a.SequenceIdentifier.Equals(ao["ProtID"].ToString()));
         DataGridPeptideView.ItemsSource = protPepDictTMP[theKey].Select(a => new { Sequence = a.Sequence, Binomial_PValue = Math.Round(a.BinomialProbability, 4), Paired_TTest_Pvalue = Math.Round(a.TTest, 4), AVGLogFold = Math.Round(a.AVGLogFold, 4), Redundancy = a.MappableProteins.Count, SpecCount = a.MyQuants.Count, MissingValues = a.MissingValues });
         LabelSelectedProtein.Content    = "Selected protein: " + ao["ProtID"].ToString() + " " + ao["Description"].ToString();
     }
     catch (Exception e2)
     {
         Console.WriteLine(e2.Message);
     }
 }
Exemplo n.º 9
0
        private void buttonGo_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "Fasta Files | *.fasta";
            if (saveFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
            {
                //Extract IDs
                string[] lines = Regex.Split(richTextBoxFastaIDs.Text, "\n");

                List <FastaItem> fastaItems = new List <FastaItem>(lines.Length);

                foreach (string line in lines)
                {
                    string[] cols  = Regex.Split(line, "\t");
                    int      index = MyRP.MyProteins.MyProteinList.FindIndex(a => a.Locus.Equals(cols[0]));

                    if (index == -1)
                    {
                        Console.WriteLine("Locus " + cols[0] + "not found in the results");
                        continue;
                    }

                    MyProtein prot = MyRP.MyProteins.MyProteinList[index];


                    FastaItem fi = new FastaItem();
                    fi.Description        = prot.Description;
                    fi.Sequence           = prot.Sequence;
                    fi.SequenceIdentifier = prot.Locus;

                    fastaItems.Add(fi);
                }

                //And now save the fasta sequences

                StreamWriter sw = new StreamWriter(saveFileDialog1.FileName);
                foreach (FastaItem fi in fastaItems)
                {
                    sw.WriteLine(">" + fi.SequenceIdentifier + " " + fi.Description);
                    sw.WriteLine(fi.Sequence);
                }
                sw.Close();

                MessageBox.Show("Fasta sequences saved");
                this.Close();
            }
        }
Exemplo n.º 10
0
        private ResultPackage FusionSEPro(List <ResultPackage> myPackages)
        {
            List <SQTScan> allScans = new List <SQTScan>();

            SEPRPackage.Parameters theparams = new SEPRPackage.Parameters();


            List <string>    allProteinIDs = new List <string>();
            string           database      = "";
            List <FastaItem> fastaItems    = new List <FastaItem>();

            foreach (ResultPackage pkg in myPackages)
            {
                allScans.AddRange(pkg.MyProteins.AllSQTScans);
                theparams = pkg.MyParameters;
                allProteinIDs.AddRange(pkg.MyProteins.MyProteinList.Select(a => a.Locus).ToList());

                foreach (MyProtein p in pkg.MyProteins.MyProteinList)
                {
                    if (!fastaItems.Exists(a => a.SequenceIdentifier.Equals(p.Locus)))
                    {
                        FastaItem fasta = new FastaItem();
                        fasta.Description        = p.Description;
                        fasta.Sequence           = p.Sequence;
                        fasta.SequenceIdentifier = p.Locus;
                        fastaItems.Add(fasta);
                    }
                }

                database = pkg.Database;
            }



            Console.WriteLine("Generating SEPro Fusion");
            ProteinManager pm = new ProteinManager(allScans, theparams, allProteinIDs.Distinct().ToList());

            pm.CalculateProteinCoverage(fastaItems);
            pm.GroupProteinsHavingCommonPeptides(1);
            ResultPackage rp = new ResultPackage(pm, theparams, database, theparams.SeachResultDirectoy, false);

            rp.MyProteins.RebuildProteinsFromScans();
            Console.WriteLine("Done fusioning the SEPro files.");
            return(rp);
        }
Exemplo n.º 11
0
        private void MenuItemExportResult_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.DefaultExt = ".txt";

            sfd.Filter = "Text File (*.txt)|*.txt";

            Nullable <bool> result = sfd.ShowDialog();


            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                StreamWriter sw = new StreamWriter(sfd.FileName);
                sw.WriteLine("#PROT\tID\tAlignments\tSpecCounts\tUnique\tCoverage\tDescription");
                sw.WriteLine("#ALN\tFileName\tScanNo\tZ\tRedundancy\tDeNovoScore\tDeNovoSeq\tDBSeq\tSimilarityScore\tIdentity");
                foreach (var prot in DataGridProteins.ItemsSource)
                {
                    Dictionary <string, object> protDic = pTools.AnonymousToDictionary(prot);

                    sw.WriteLine("PROT\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}", protDic["ID"], protDic["Alignments"], protDic["SpecCounts"], protDic["Unique"], protDic["Coverage"], protDic["Description"]);

                    List <AlignmentResult> alns = MyResultPackage.Alignments.FindAll(a => a.ProtIDs.Contains(protDic["ID"]));
                    FastaItem thisProtein       = MyResultPackage.MyFasta.Find(a => a.SequenceIdentifier.Equals(protDic["ID"]));

                    foreach (AlignmentResult aln in alns)
                    {
                        string dbPep = mAligner.GetClosestPeptideInASequence(PatternTools.pTools.CleanPeptide(aln.DeNovoRegistries[0].PtmSequence, true).ToCharArray(), thisProtein.Sequence.ToCharArray());
                        foreach (DeNovoR dnvr in aln.DeNovoRegistries)
                        {
                            byte[] peptideBytes = Encoding.ASCII.GetBytes(PatternTools.pTools.CleanPeptide(dnvr.PtmSequence, true));
                            int    IDScore      = mAligner.IDScore(peptideBytes, thisProtein.SequenceInBytes);

                            string idScore = IDScore + " (" + Math.Round(((double)IDScore / (double)PatternTools.pTools.CleanPeptide(dnvr.PtmSequence, true).Length), 3) + ")";
                            sw.WriteLine("ALN\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", dnvr.FileName, dnvr.ScanNumber, dnvr.Charge, aln.ProtIDs.Count, dnvr.DeNovoScore, dnvr.PtmSequence, dbPep, aln.SimilarityScore, idScore);
                        }
                    }
                }

                sw.Close();
                Console.WriteLine("Results Exported.");
            }
        }
Exemplo n.º 12
0
        private void DataGridProteins_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            object theSelection = DataGridProteins.SelectedItem;
            Dictionary <string, object> dict = theSelection.GetType().GetProperties().ToDictionary(x => x.Name, x => x.GetValue(theSelection, null));

            FastaItem thisProtein = MyResultPackage.MyFasta.Find(a => a.SequenceIdentifier.Equals(dict["ID"]));

            List <AlignmentResult> alns = MyResultPackage.Alignments.FindAll(a => a.ProtIDs.Contains(dict["ID"]));

            //We need to find the alignment positions of each alignment with this protein
            List <Tuple <List <int>, string> > toPlot = new List <Tuple <List <int>, string> >();

            //We need to feed the alignment List
            KeyValuePair <int[, ], Dictionary <char, int> > m = MAligner.Utils.LoadSubstitutionMatrixFromString(PepExplorer2.Properties.Resources.PAM30MS);
            Aligner mAligner = new Aligner(m);

            foreach (AlignmentResult aln in alns)
            {
                string     cleanPeptideSequence = PatternTools.pTools.CleanPeptide(aln.DeNovoRegistries[0].PtmSequence, true);
                List <int> alnScores            = mAligner.Align(cleanPeptideSequence.ToCharArray(), thisProtein.Sequence.ToCharArray()).ToList();
                int        maxNo = alnScores.Max();
                List <int> pos   = new List <int>();

                for (int i = 0; i < alnScores.Count; i++)
                {
                    if (alnScores[i] == maxNo)
                    {
                        pos.Add(i);
                    }
                }

                toPlot.Add(new Tuple <List <int>, string>(pos, cleanPeptideSequence));
            }


            Forms.ProteinCoverageViewForm pcvf = new Forms.ProteinCoverageViewForm();
            pcvf.MyProteinCoverageView.Plot(thisProtein, toPlot);
            pcvf.ShowDialog();
        }
Exemplo n.º 13
0
        public void UpdateGUI()
        {
            //Lets take care of which peptides to consider in our analysis
            if ((bool)CheckBoxConsiderOnlyUniquePeptides.IsChecked)
            {
                myPeptidesTMP = MyPeptides.FindAll(a => a.MappableProteins.Count == 1);
            }
            else
            {
                myPeptidesTMP = MyPeptides.FindAll(a => a.MappableProteins.Count > 0);
            }

            int removedFold = myPeptidesTMP.RemoveAll(a => Math.Abs(a.AVGLogFold) < Math.Round((double)DoubleUpDownPeptideLogFold.Value, 2));

            ///Need to fix here....
            int removedProb1 = myPeptidesTMP.RemoveAll(a => (a.TTest > Math.Round((double)DoubleUpDownPeptidePValueCutoff.Value, 2)));

            List <PepQuant> survival = MyPeptides.FindAll(a => !myPeptidesTMP.Exists(b => b.Sequence.Equals(a.Sequence)));

            protPepDictTMP = new Dictionary <FastaItem, List <PepQuant> >();

            //New way
            foreach (FastaItem fi in MyFastaItems)
            {
                List <PepQuant> pepts = myPeptidesTMP.FindAll(a => a.MappableProteins.Contains(fi.SequenceIdentifier));
                if (pepts.Count > 0)
                {
                    protPepDictTMP.Add(fi, pepts);
                }
            }

            try
            {
                var protDisplay = from kvp in protPepDictTMP
                                  where kvp.Value.Count >= IntegerUpDown.Value
                                  select new
                {
                    ProtID             = kvp.Key.SequenceIdentifier,
                    Daltons            = Math.Round(kvp.Key.MonoisotopicMass, 2),
                    PeptideCount       = kvp.Value.Count,
                    UniquePeptideCount = kvp.Value.Count(a => a.MappableProteins.Count == 1),
                    SpecCount          = protPepDictTMP[kvp.Key].Sum(a => a.MyQuants.Count),
                    AvgLogFold         = Math.Round(kvp.Value.Average(a => a.AVGLogFold), 3),
                    StouffersPValue    = ProteinPValue(kvp.Value),
                    Coverage           = GenerateMicroChart(kvp),
                    Description        = kvp.Key.Description
                };

                int noProteins = protDisplay.Count();
                LabelNoProteins.Content = noProteins;

                if (noProteins == 0)
                {
                    MessageBox.Show("No protein satisfies current constraints.");
                    return;
                }

                //Find out how many peptides and spec counts are there

                List <PepQuant> validPepQuants = new List <PepQuant>();

                if ((bool)CHeckBoxShowPeptidesOfFilteredProteinsOnly.IsChecked)
                {
                    List <string> IDsProteinsDisplay = protDisplay.Select(a => a.ProtID).ToList();
                    foreach (string pID in IDsProteinsDisplay)
                    {
                        FastaItem fi = MyFastaItems.Find(a => a.SequenceIdentifier.Equals(pID));
                        validPepQuants.AddRange(protPepDictTMP[fi]);
                    }

                    validPepQuants = validPepQuants.Distinct().ToList();
                }
                else
                {
                    validPepQuants = MyPeptides;
                }

                DataGridAllPeptidesView.ItemsSource = validPepQuants.Select
                                                          (a => new
                {
                    Sequence            = a.Sequence,
                    Binomial_PValue     = Math.Round(a.BinomialProbability, 4),
                    Paired_TTest_Pvalue = Math.Round(a.TTest, 4),
                    AVGLogFold          = Math.Round(a.AVGLogFold, 4),
                    Redundancy          = a.MappableProteins.Count,
                    SpecCount           = a.MyQuants.Count,
                    MissingValues       = a.MissingValues,
                    MappableProts       = string.Join(" ", (
                                                          from prot in protDisplay
                                                          where a.MappableProteins.Contains(prot.ProtID)
                                                          select "(" + prot.ProtID + "::" + prot.Description + ")").ToList()
                                                      )
                }
                                                          );


                LabelNoPeptides.Content            = validPepQuants.Count();
                LabelSpecCount.Content             = validPepQuants.Sum(a => a.MyQuants.Count);
                LabelAvgFilteredPepLogFold.Content = Math.Round(validPepQuants.Average(a => a.AVGLogFold), 3);

                DataGridProteinView.ItemsSource = protDisplay;


                myPeptidesTMP = validPepQuants;

                double correctedP = PatternTools.pTools.BenjaminiHochbergFDR(0.01, protDisplay.Select(a => a.StouffersPValue).ToList(), false);
                LabelCorrectedP.Content = correctedP;

                LabelTotalPeptides.Content = MyPeptides.Count;
            }
            catch (Exception) { return; }
            //Update the graphs
            PlotQuants();
        }
Exemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="onlyUniquePeptides"></param>
        /// <param name="classLabels"></param>
        /// <param name="minQuantsPerPeptide"></param>
        /// <returns>the list ofchannels and the list of peptides</returns>
        ///
        public static KeyValuePair <List <FastaItem>, List <PepQuant> > ParsePeptideReport(string fileName)
        {
            List <PepQuant> pepsAll = new List <PepQuant>();

            bool             fastaData    = false;
            List <FastaItem> MyFastaItems = new List <FastaItem>();

            List <PepQuant> peps = new List <PepQuant>();
            StreamReader    sr   = new StreamReader(fileName);
            string          line;
            int             counter = 0;
            PepQuant        pq      = null;

            while ((line = sr.ReadLine()) != null)
            {
                counter++;
                //Console.WriteLine("Parsing line: " + counter);

                if (line.Equals("#Fasta Items"))
                {
                    fastaData = true;
                }
                else if (line.StartsWith("#Channels"))
                {
                    continue;
                }
                else if (fastaData)
                {
                    //Parse fasta data
                    if (line.StartsWith(">"))
                    {
                        string[] cols   = Regex.Split(line, " ");
                        string   protID = cols[0].ToString();
                        protID = protID.Remove(0, 1);

                        string protDesc = "";

                        for (int i = 0; i < cols.Length; i++)
                        {
                            if (i == 0)
                            {
                                continue;
                            }
                            if (i == 1)
                            {
                                protDesc += cols[1];
                            }
                            else
                            {
                                protDesc += " " + cols[i];
                            }
                        }

                        FastaItem fi = new FastaItem(protID, protDesc);
                        MyFastaItems.Add(fi);
                    }
                    else
                    {
                        MyFastaItems.Last().Sequence += line;
                    }
                }

                else
                {
                    if (line.StartsWith("Peptide:"))
                    {
                        peps.Add(pq);
                        string[] cols = Regex.Split(line, "\t");

                        //GetSequence
                        string[] colsSeq = Regex.Split(cols[0], ":");

                        pq = new PepQuant(colsSeq[1]);
                    }
                    else
                    {
                        //quant line
                        List <string> cols = Regex.Split(line, "\t").ToList();

                        List <string> cols2 = Regex.Split(cols[0], Regex.Escape(".")).ToList();


                        int    scanNumber = int.Parse(cols2[cols2.Count - 2]);
                        int    z          = int.Parse(cols2.Last());
                        string filename   = Regex.Replace(cols[0], Regex.Escape(".") + scanNumber + Regex.Escape(".") + scanNumber + Regex.Escape(".") + z, "");

                        //Get the signals
                        cols.RemoveAt(0);

                        try {
                            List <double> signals = cols.Select(a => double.Parse(a)).ToList();

                            //This fix is required because sometimes the purity correction may yield negative numbers.
                            for (int i = 0; i < signals.Count; i++)
                            {
                                if (signals[i] < 0)
                                {
                                    signals[i] = 0;
                                }
                            }

                            int qc = signals.Count(a => a > 0);

                            if (!signals.Contains(double.NaN))
                            {
                                pq.MyQuants.Add(new Quant(z, filename, scanNumber, signals));
                            }
                        } catch
                        {
                            Console.WriteLine("Failed parsing line: " + counter);
                        }
                    }
                }
            }

            peps.Add(pq);
            peps.RemoveAt(0);
            pepsAll.AddRange(peps);
            sr.Close();

            pepsAll.RemoveAll(a => a.MyQuants.Count == 0);

            return(new KeyValuePair <List <FastaItem>, List <PepQuant> >(MyFastaItems, pepsAll));
        }
Exemplo n.º 15
0
 public ProtQuant(FastaItem fi)
 {
     MyFastaItem = fi;
     MyPepQuants = new List <PepQuant>();
 }
Exemplo n.º 16
0
 public ProtQuant(FastaItem fi, List <PepQuant> pqs)
 {
     MyFastaItem = fi;
     MyPepQuants = pqs;
 }
Exemplo n.º 17
0
        private void MenuItemExporToPLP_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.DefaultExt = ".txt";
            sfd.Filter     = "PatternLab Project (*.plp)|*.plp";

            Nullable <bool> result = sfd.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                SparseMatrixIndexParserV2 smi = new SparseMatrixIndexParserV2();

                int counter = 0;
                List <FastaItem> orderedKeys = new List <FastaItem>();
                foreach (KeyValuePair <FastaItem, List <PepQuant> > kvp in protPepDict)
                {
                    if (kvp.Value.Count > IntegerUpDown.Value)
                    {
                        counter++;
                        SparseMatrixIndexParserV2.Index i = new SparseMatrixIndexParserV2.Index();
                        i.ID          = counter;
                        i.Name        = kvp.Key.SequenceIdentifier;
                        i.Description = kvp.Key.Description;

                        smi.Add(i);

                        orderedKeys.Add(kvp.Key);
                    }
                }

                SparseMatrix sm = new SparseMatrix();
                sm.ClassDescriptionDictionary = new Dictionary <int, string>();
                List <int> labels = Regex.Split(TextBoxClassLabel.Text, " ").Select(a => int.Parse(a)).ToList();


                //Generate the dictionary
                for (int i = 0; i < labels.Count; i++)
                {
                    if (labels[i] < 0)
                    {
                        continue;
                    }

                    //Create the dictionary for the class
                    sm.ClassDescriptionDictionary.Add(i, (i).ToString());


                    List <int>    dims   = new List <int>();
                    List <double> values = new List <double>();

                    for (int j = 0; j < orderedKeys.Count; j++)
                    {
                        FastaItem       fi           = orderedKeys[j];
                        List <PepQuant> thePepQuants = protPepDict[fi];

                        double theIntensitySum = 0;
                        foreach (PepQuant pq in thePepQuants)
                        {
                            theIntensitySum += pq.MyQuants.Sum(a => a.MarkerIntensities[i]);
                        }

                        if (theIntensitySum > 0)
                        {
                            dims.Add(j + 1);
                            values.Add(theIntensitySum);
                        }
                    }

                    sparseMatrixRow smr = new sparseMatrixRow(i, dims, values);
                    sm.theMatrixInRows.Add(smr);
                }

                PatternLabProject plp = new PatternLabProject(sm, smi, "Isobaric Quant Project");
                plp.Save(sfd.FileName);

                MessageBox.Show("PLP file was saved");
                Console.WriteLine("PLP file was saved.");
            }
        }
Exemplo n.º 18
0
        private void buttonGo_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(textBoxInputDirectory.Text))
            {
                richTextBoxLog.AppendText("Directory " + textBoxInputDirectory.Text + " does not exist");
                return;
            }

            DirectoryInfo di = new DirectoryInfo(textBoxInputDirectory.Text);

            List <FileInfo> SEProFiles = di.GetFiles("*.sepr", SearchOption.AllDirectories).ToList();

            if (SEProFiles.Count == 0)
            {
                MessageBox.Show("No SEPro files found in the provided directory.");
                return;
            }

            List <SQTScan>   allScans      = new List <SQTScan>();
            Parameters       theparams     = new Parameters();
            List <string>    allProteinIDs = new List <string>();
            string           database      = "";
            List <FastaItem> fastaItems    = new List <FastaItem>();

            foreach (FileInfo fi in SEProFiles)
            {
                richTextBoxLog.AppendText("Loading " + fi.Name + "\n");
                this.Update();
                ResultPackage rp = ResultPackage.Load(fi.FullName);
                allScans.AddRange(rp.MyProteins.AllSQTScans);
                theparams = rp.MyParameters;
                allProteinIDs.AddRange(rp.MyProteins.MyProteinList.Select(a => a.Locus).ToList());

                foreach (MyProtein p in rp.MyProteins.MyProteinList)
                {
                    if (!fastaItems.Exists(a => a.SequenceIdentifier.Equals(p.Locus)))
                    {
                        FastaItem fasta = new FastaItem();
                        fasta.Description        = p.Description;
                        fasta.Sequence           = p.Sequence;
                        fasta.SequenceIdentifier = p.Locus;
                        fastaItems.Add(fasta);
                    }
                }

                database = rp.Database;
            }

            richTextBoxLog.AppendText("Generating new SEPro file\n");
            this.Update();

            theparams.SeachResultDirectoy = "Fusion SEPro file of" + string.Join(",", SEProFiles.Select(a => a.FullName).ToList());
            ProteinManager pm = new ProteinManager(allScans, theparams, allProteinIDs.Distinct().ToList());

            pm.CalculateProteinCoverage(fastaItems);
            pm.GroupProteinsHavingCommonPeptides(1);

            saveFileDialog1.Filter = "SEPro files (*.sepr)|*.sepr";

            saveFileDialog1.InitialDirectory = textBoxInputDirectory.Text;
            saveFileDialog1.FileName         = "Fusion_";
            if (saveFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
            {
                ResultPackage rp = new ResultPackage(pm, theparams, database, theparams.SeachResultDirectoy, false);
                rp.MyProteins.RebuildProteinsFromScans();
                rp.Save(saveFileDialog1.FileName);
            }

            MessageBox.Show("Done.");
        }