Exemple #1
0
 public ProtQuant(FastaItem fi, PepQuant pq)
 {
     MyFastaItem = fi;
     MyPepQuants = new List <PepQuant>()
     {
         pq
     };
 }
Exemple #2
0
        private void ShowPeptideWindow(Dictionary <string, object> ao)
        {
            PlotModel MyModel = new PlotModel();

            PepQuant sc = MyPeptides.Find(a => a.Sequence.Equals(ao["Sequence"]));

            //ObservableCollection<MyDataPoint> BarChartData = new ObservableCollection<MyDataPoint>();

            SignalViewer ws = new SignalViewer();

            ws.Title      = "Peptide: " + sc.Sequence;
            MyModel.Title = sc.Sequence;

            // --------------------------------------------------------------------------------------------------------

            MyModel.Title = sc.Sequence;

            MyModel.LegendOrientation = LegendOrientation.Horizontal;
            MyModel.LegendPlacement   = LegendPlacement.Outside;
            MyModel.LegendPosition    = LegendPosition.BottomCenter;


            DataTable dtDataGridView = new DataTable("PepScans");

            DataSet   dataSetBarChart = new DataSet();
            DataTable dtBarChart      = new DataTable("PepScans");

            dataSetBarChart.Tables.Add(dtBarChart);

            dtBarChart.Columns.Add("channel", typeof(string));

            dtDataGridView.Columns.Add("File Name", typeof(string));
            dtDataGridView.Columns.Add("Precursor Charge", typeof(int));
            dtDataGridView.Columns.Add("Scan Number", typeof(int));

            List <DataRow> dataRowBarChartList = new List <DataRow>();


            var categoryAxis = new CategoryAxis();
            var valueAxis    = new LinearAxis();

            valueAxis.Title    = "Intensity";
            valueAxis.Position = AxisPosition.Left;

            MyModel.Axes.Add(valueAxis);

            for (int i = 0; i < sc.MyQuants[0].MarkerIntensities.Count; i++)
            {
                if (classLabels[i] >= 0)
                {
                    DataRow newRowBarChart = dtBarChart.NewRow();
                    newRowBarChart["channel"] = "Channel " + (i + 1);
                    dataRowBarChartList.Add(newRowBarChart);
                    dtBarChart.Rows.Add(newRowBarChart);

                    dtDataGridView.Columns.Add(new DataColumn("Channel " + (i + 1).ToString(), typeof(double)));

                    categoryAxis.Labels.Add(new DataColumn("Channel " + (i + 1).ToString(), typeof(double)).ToString());
                }
            }

            MyModel.Axes.Add(categoryAxis);

            bool          insertYaxisBarChart = true;
            int           counter             = 0;
            List <int>    categoryIndex       = new List <int>();
            List <double> value = new List <double>();


            foreach (Quant q in sc.MyQuants)
            {
                if (insertYaxisBarChart)
                {
                    // Set the Y-Axis value
                    for (int i = 0; i < sc.MyQuants.Count; i++)
                    {
                        dtBarChart.Columns.Add("spec" + i, typeof(double));
                        //ws.BarChart1.ValueField.Add("spec" + i);
                        categoryIndex.Add(i);
                    }

                    insertYaxisBarChart = false;
                }

                DataRow newRow_datagridview = dtDataGridView.NewRow();
                newRow_datagridview["File Name"]        = q.FileName;
                newRow_datagridview["Scan Number"]      = q.ScanNumber;
                newRow_datagridview["Precursor Charge"] = q.Z;

                var columnSeries = new ColumnSeries();
                columnSeries.Title = q.FileName;

                int negativeClass = 0;

                var solution = classLabels.GroupBy(i => i > 0).SelectMany(g => g).ToArray();
                //classLabels.Sort((a, b) => b.CompareTo(a));

                for (int i = 0; i < q.MarkerIntensities.Count; i++)
                {
                    if (classLabels[i] >= 0)
                    {
                        DataRow newRow_barChart = dataRowBarChartList[i - negativeClass];
                        newRow_barChart["spec" + counter] = q.MarkerIntensities[i];

                        newRow_datagridview[i + 3 - negativeClass] = q.MarkerIntensities[i];
                        //BarChartData.Add(new MyDataPoint(i, q.MarkerIntensities[i], "Row" + " " + counter));
                        columnSeries.Items.Add(new ColumnItem(q.MarkerIntensities[i], (i - negativeClass)));
                    }
                    else
                    {
                        negativeClass++;
                    }
                }

                counter++;

                MyModel.Series.Add(columnSeries);
                dtDataGridView.Rows.Add(newRow_datagridview);
            }


            // Set the chart tooltip.  {field} will be replaced by current bar value.
            // Need to improve in this little templating.
            //ws.BarChart1.ToolTipText = "Signal Intensity: {field}";
            // Set the x-axis data field
            //ws.BarChart1.XAxisField = "channel";


            //--------------------------------------------------------------------------------------------------------

            //ws.MyBarChart.HorizontalPropertyName = "X";
            //ws.BarChart1.DataSource = dataSetBarChart;



            //ws.MyBarChart.Items = BarChartData;

            //ws.BarChart1.Generate();
            //ws.MyBarChart.Draw();
            //ws.MyBarChart.Refresh();

            ws.MyDataGridSpec.ItemsSource = dtDataGridView.DefaultView;
            ws.Show();

            ws.MyBarChart.Model = MyModel;
        }
Exemple #3
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));
        }