示例#1
0
 public OriginalData(string name, string fileName, IntensityMatrix intentisyMatrix)
 {
     this.OverrideDisplayName = name;
     this._fileName           = fileName;
     this._intentisyMatrix    = intentisyMatrix;
 }
示例#2
0
 public VectorCollection(IntensityMatrix intensityMatrix)
 {
     this._owner = intensityMatrix;
 }
示例#3
0
        /// <summary>
        /// Creates a StylisedCluster for plotting from this cluster.
        /// </summary>
        /// <param name="core">Core</param>
        /// <param name="highlight">What to highlight in the result</param>
        /// <returns>A StylisedCluster</returns>
        internal StylisedCluster CreateStylisedCluster(Core core, IntensityMatrix source, Associational highlight)
        {
            Cluster fakeCluster = new Cluster(this.DefaultDisplayName, null);
            Dictionary <Peak, LineInfo> colourInfo = new Dictionary <Peak, LineInfo>();
            string caption = "Plot of peaks potentially representing {0}.";

            // Compound --> Peaks in compound
            // Adduct: NA
            // Peak: Peak
            // Cluster: Peaks in cluster
            // Pathway: None

            StylisedCluster.HighlightElement[] toHighlight = null;

            if (highlight != null)
            {
                switch (highlight.AssociationalClass)
                {
                case EVisualClass.Peak:
                    toHighlight = new StylisedCluster.HighlightElement[] { new StylisedCluster.HighlightElement((Peak)highlight, null) };
                    caption    += " {1} is shown in red.";
                    break;

                case EVisualClass.Cluster:
                    Cluster highlightCluster = (Cluster)highlight;
                    toHighlight = highlightCluster.Assignments.Vectors.Select(StylisedCluster.HighlightElement.FromVector).ToArray();
                    caption    += " Peaks in {1} are shown in red.";
                    break;
                }
            }

            HashSet <Peak> peaks = this.Annotations.Select(z => z.Peak).Unique();

            IntensityMatrix vm = source.Subset(z => peaks.Contains(z), null, ESubsetFlags.None);

            for (int index = 0; index < vm.NumVectors; index++)
            {
                Vector vec  = vm.Vectors[index];
                Peak   peak = vec.Peak;

                fakeCluster.Assignments.Add(new Assignment(vec, fakeCluster, double.NaN));

                StringBuilder sb = new StringBuilder();

                if (peak.Annotations.Count > 5)
                {
                    sb.Append(this.DefaultDisplayName + " OR " + (peak.Annotations.Count - 1) + " others");
                }
                else
                {
                    sb.Append(this.DefaultDisplayName);

                    foreach (Annotation c2 in peak.Annotations)
                    {
                        if (c2.Compound != this)
                        {
                            sb.Append(" OR ");
                            sb.Append(c2.Compound.DefaultDisplayName + " (" + c2.Adduct.DefaultDisplayName + ")");
                        }
                    }
                }

                colourInfo.Add(peak, new LineInfo(peak.DisplayName + ": " + sb.ToString(), Color.Black, DashStyle.Solid));
            }

            StylisedCluster r = new StylisedCluster(fakeCluster, this, colourInfo);

            r.IsFake            = true;
            r.CaptionFormat     = caption;
            r.WhatIsHighlighted = highlight;
            r.Highlight         = toHighlight;
            return(r);
        }
示例#4
0
        /// <summary>
        /// Creates a StylisedCluster for plotting from this pathway.
        /// </summary>
        /// <param name="core">Core</param>
        /// <param name="highlightContents">What to highlight in the plot</param>
        /// <returns>A StylisedCluster</returns>
        internal StylisedCluster CreateStylisedCluster(Core core, IntensityMatrix source, Associational highlightContents)
        {
            var colours = new Dictionary <Peak, LineInfo>();

            // Adduct: NA
            // Peak: Pathways for peak -> Peaks (THIS PEAK)
            // Cluster: Pathways for cluster -> Peaks (PEAKS IN CLUSTER)
            // Compound: Pathway for compound -> Peaks (PEAKS IN COMPOUND)
            // Pathway: NA
            const string caption1 = "Plot of peaks potentially representing compounds implicated in {0}.";
            string       caption2 = " Colours represent peaks that share the same cluster(s).";
            string       caption3;

            // Find out the peaks that we are supposed to highlight
            StylisedCluster.HighlightElement[] toHighlight = null;

            if (highlightContents != null)
            {
                switch (highlightContents.AssociationalClass)
                {
                case EVisualClass.Compound:
                    Compound highlightCompound = (Compound)highlightContents;
                    toHighlight = highlightCompound.Annotations.Select(z => new StylisedCluster.HighlightElement(z, null)).ToArray();
                    caption3    = " Peaks potentially representing {1} are {HIGHLIGHTED}.";
                    break;

                case EVisualClass.Cluster:
                    Cluster highlightCluster = (Cluster)highlightContents;
                    toHighlight = highlightCluster.Assignments.Vectors.Select(StylisedCluster.HighlightElement.FromVector).ToArray();
                    caption3    = " Peaks potentially representing compounds in {1} are {HIGHLIGHTED}.";

                    break;

                case EVisualClass.Peak:
                    toHighlight = new StylisedCluster.HighlightElement[] { new StylisedCluster.HighlightElement((Peak)highlightContents, null) };
                    caption3    = " {1} is {HIGHLIGHTED}.";
                    break;

                default:
                    caption3 = "";
                    break;
                }
            }
            else
            {
                caption3 = "";
            }


            bool highlightByCompound = false;

            // Make a list of the peaks in this pathway
            Dictionary <Peak, List <Compound> > peaks = new Dictionary <Peak, List <Compound> >();

            foreach (Compound compound in this.Compounds)
            {
                foreach (Annotation annotation in compound.Annotations)
                {
                    Peak peak = annotation.Peak;

                    if (peaks.ContainsKey(peak))
                    {
                        peaks[peak].Add(compound);
                    }
                    else
                    {
                        peaks[peak] = new List <Compound>();
                        peaks[peak].Add(compound);
                    }
                }
            }

            // Depending on the mode assign either each combination of compounds OR clusters a unique colour
            Cluster fakeCluster = new Cluster(this.DisplayName, null);
            List <List <Compound> > uniqueCompoundCombinations = new List <List <Compound> >();
            List <List <Cluster> >  uniqueClusterCombinations  = new List <List <Cluster> >();

            int cindex = -1;

            IntensityMatrix vm = source.Subset(z => peaks.ContainsKey(z), null, ESubsetFlags.None);

            for (int vIndex = 0; vIndex < vm.NumVectors; vIndex++)
            {
                var             vec       = vm.Vectors[vIndex];
                Peak            peak      = vec.Peak;
                var             asses     = vec.Peak.FindAssignments(core).ToArray();
                List <Compound> compounds = peaks[peak];
                Color           col;

                // Find or create peak in list
                if (highlightByCompound)
                {
                    int uniqueIndex = Maths.FindMatch(uniqueCompoundCombinations, compounds);

                    if (uniqueIndex == -1)
                    {
                        uniqueIndex = uniqueCompoundCombinations.Count;
                        uniqueCompoundCombinations.Add(compounds); // add list of peaks for this peak
                    }

                    if (uniqueCompoundCombinations[uniqueIndex].Count == 1)
                    {
                        col = Color.Black;
                    }
                    else
                    {
                        cindex++;

                        if (cindex == UiControls.BrightColours.Length)
                        {
                            // If there are too many don't bother
                            col      = Color.Black;
                            caption2 = "";

                            foreach (var lii in colours)
                            {
                                lii.Value.Colour = Color.Black;
                            }
                        }
                        else
                        {
                            col = UiControls.BrightColours[cindex % UiControls.BrightColours.Length];
                        }
                    }
                }
                else
                {
                    var l           = asses.Select(z => z.Cluster).ToList();
                    int uniqueIndex = Maths.FindMatch(uniqueClusterCombinations, l);

                    if (uniqueIndex == -1)
                    {
                        uniqueIndex = uniqueClusterCombinations.Count;
                        uniqueClusterCombinations.Add(l); // add list of peaks for this peak
                    }

                    col = UiControls.BrightColours[uniqueIndex % UiControls.BrightColours.Length];
                }

                StringBuilder legend = new StringBuilder();
                int           xCount = 0;

                foreach (Annotation potential in peak.Annotations)
                {
                    if (this.Compounds.Contains(potential.Compound))
                    {
                        if (legend.Length != 0)
                        {
                            legend.Append(" OR ");
                        }

                        legend.Append(potential.Compound.DefaultDisplayName);
                    }
                    else
                    {
                        xCount++;
                    }
                }

                if (xCount != 0)
                {
                    legend.Append(" OR " + xCount + " others not in this pathway");
                }

                fakeCluster.Assignments.Add(new Assignment(vec, fakeCluster, double.NaN));


                string seriesName = peak.DisplayName + (!asses.IsEmpty() ? (" (" + StringHelper.ArrayToString(asses.Select(z => z.Cluster)) + ")") : "") + ": " + legend.ToString();
                var    li         = new LineInfo(seriesName, col, DashStyle.Solid);
                colours.Add(peak, li);
            }

            var r = new StylisedCluster(fakeCluster, this, colours);

            r.IsFake            = true;
            r.Highlight         = toHighlight;
            r.CaptionFormat     = (caption1 + caption2 + caption3);
            r.WhatIsHighlighted = highlightContents;
            return(r);
        }