Example #1
0
        /// <summary>
        /// Create bar graph showing peak areas.
        /// </summary>
        private void CreateGraph()
        {
            if (_toolClient == null)
            {
                return;
            }

            // Retrieve the current report.
            IReport report = _toolClient.GetReport("Peak Area"); // Not L10N

            // Get the same report, more dynamically.
            var reportStream = typeof(MainForm).Assembly.GetManifestResourceStream("ExampleInteractiveTool.tool_inf.ExampleTool_report.skyr"); // Not L10N

            if (reportStream == null)
            {
                return;
            }
            var     reader  = new StreamReader(reportStream);
            IReport report2 = _toolClient.GetReportFromDefinition(reader.ReadToEnd());

            AssertReportsEquals(report, report2);

            _peptides       = new List <string>();
            _peptideLinks   = new List <string>();
            _replicateLinks = new List <string>();
            var replicates   = new List <string>();
            var peptideAreas = new Dictionary <string, double>();

            foreach (var row in report.Cells)
            {
                // Get report fields.
                var peptideName       = row[0];
                var peakArea          = row[1];
                var peptideLocation   = row[2];
                var replicateName     = row[3];
                var replicateLocation = row[4];

                // Get the name of this peptide.
                double area;
                if (string.IsNullOrWhiteSpace(peptideName) || !double.TryParse(peakArea, out area))
                {
                    continue;
                }

                if (_selectedReplicate == replicateName || _selectedReplicate == "All") // Not L10N
                {
                    // Add area to sum that was previously created.
                    if (peptideAreas.ContainsKey(peptideName))
                    {
                        peptideAreas[peptideName] += area;
                    }

                    // Create a sum for a new peptide.
                    else
                    {
                        _peptides.Add(peptideName);
                        _peptideLinks.Add(peptideLocation);
                        _replicateLinks.Add(replicateLocation);
                        peptideAreas[peptideName] = area;
                    }
                }

                // Record unique replicate names.
                if (!replicates.Contains(replicateName))
                {
                    replicates.Add(replicateName);
                }
            }

            // Rebuild Replicates menu.
            var items = replicatesToolStripMenuItem.DropDownItems;

            items.Clear();
            items.Add("All"); // Not L10N
            items.Add("-");   // Not L10N
            replicates.Sort();
            foreach (var replicate in replicates)
            {
                items.Add(replicate);
            }

            // Put a check on the selected replicate.
            if (!replicates.Contains(_selectedReplicate))
            {
                _selectedReplicate = "All"; // Not L10N
            }
            SelectReplicate(_selectedReplicate);

            // Create array of peak areas in same order as peptide names.
            var areas = new double[_peptides.Count];

            for (int i = 0; i < areas.Length; i++)
            {
                areas[i] = peptideAreas[_peptides[i]];
            }

            // Generate unique prefixes for each peptide name.
            var prefixGenerator = new UniquePrefixGenerator(_peptides, 3);

            // Create bar graph showing summed peak area for each peptide.
            _graph.CreateBars(_peptides.Select(prefixGenerator.GetUniquePrefix).ToArray(), areas);
        }
Example #2
0
        /// <summary>
        /// Create bar graph showing peak areas.
        /// </summary>
        private void CreateGraph()
        {
            if (_toolClient == null)
                return;

            // Retrieve the current report.
            IReport report = _toolClient.GetReport("Peak Area"); // Not L10N

            // Get the same report, more dynamically.
            var reportStream = typeof(MainForm).Assembly.GetManifestResourceStream("ExampleInteractiveTool.tool_inf.ExampleTool_report.skyr"); // Not L10N
            if (reportStream == null)
                return;
            var reader = new StreamReader(reportStream);
            IReport report2 = _toolClient.GetReportFromDefinition(reader.ReadToEnd());
            AssertReportsEquals(report, report2);

            _peptides = new List<string>();
            _peptideLinks = new List<string>();
            _replicateLinks = new List<string>();
            var replicates = new List<string>();
            var peptideAreas = new Dictionary<string, double>();

            foreach (var row in report.Cells)
            {
                // Get report fields.
                var peptideName = row[0];
                var peakArea = row[1];
                var peptideLocation = row[2];
                var replicateName = row[3];
                var replicateLocation = row[4];

                // Get the name of this peptide.
                double area;
                if (string.IsNullOrWhiteSpace(peptideName) || !double.TryParse(peakArea, out area))
                    continue;

                if (_selectedReplicate == replicateName || _selectedReplicate == "All") // Not L10N
                {
                    // Add area to sum that was previously created.
                    if (peptideAreas.ContainsKey(peptideName))
                        peptideAreas[peptideName] += area;

                    // Create a sum for a new peptide.
                    else
                    {
                        _peptides.Add(peptideName);
                        _peptideLinks.Add(peptideLocation);
                        _replicateLinks.Add(replicateLocation);
                        peptideAreas[peptideName] = area;
                    }
                }

                // Record unique replicate names.
                if (!replicates.Contains(replicateName))
                    replicates.Add(replicateName);
            }

            // Rebuild Replicates menu.
            var items = replicatesToolStripMenuItem.DropDownItems;
            items.Clear();
            items.Add("All"); // Not L10N
            items.Add("-"); // Not L10N
            replicates.Sort();
            foreach (var replicate in replicates)
                items.Add(replicate);

            // Put a check on the selected replicate.
            if (!replicates.Contains(_selectedReplicate))
                _selectedReplicate = "All"; // Not L10N
            SelectReplicate(_selectedReplicate);

            // Create array of peak areas in same order as peptide names.
            var areas = new double[_peptides.Count];
            for (int i = 0; i < areas.Length; i++)
                areas[i] = peptideAreas[_peptides[i]];

            // Generate unique prefixes for each peptide name.
            var prefixGenerator = new UniquePrefixGenerator(_peptides, 3);

            // Create bar graph showing summed peak area for each peptide.
            _graph.CreateBars(_peptides.Select(prefixGenerator.GetUniquePrefix).ToArray(), areas);
        }