Exemplo n.º 1
0
        /// <summary>
        ///     Grabs the data from the provider cache and shoves into UI where needed.  This is done
        ///     here like this to prevent holding large amounts of data in memory.
        /// </summary>
        private void SetCluster(UMCClusterLightMatched cluster)
        {
            // Grab the data from the cache
            UpdatePlotsWithClusterData(cluster);

            ChargeHistogramModel = new UmcClusterChargeHistogram(cluster.Cluster, "Charge State Histogram");
        }
Exemplo n.º 2
0
        private void LoadCluster(UMCClusterLightMatched cluster)
        {
            m_selectedCluster = cluster;

            MassTagResults.Clear();
            DatabaseResults.Clear();

            var peptides = cluster.Cluster.FindPeptides();

            peptides.ForEach(x => DatabaseResults.Add(new PeptideViewModel(x)));
            cluster.ClusterMatches.ForEach(x => MassTagResults.Add(new MassTagMatchedViewModel(x)));
        }
Exemplo n.º 3
0
        private void LoadCluster(UMCClusterLightMatched cluster)
        {
            Spectra.Clear();

            if (cluster == null)
            {
                return;
            }

            //TODO: Make this a task!!!


            var spectra = cluster.Cluster.GetLoadedSpectra();

            m_maxMz        = 0.0;
            m_maxIntensity = 0.0;
            foreach (var spectrum in spectra)
            {
                spectrum.Peaks = SpectraLoader.LoadSpectrum(spectrum);
                if (spectrum.Peaks.Count > 0)
                {
                    m_maxMz        = Math.Max(m_maxMz, spectrum.Peaks.Max(x => x.X));
                    m_maxIntensity = Math.Max(m_maxIntensity, spectrum.Peaks.Max(x => x.Y));
                }

                var msSpectrum = new MsSpectraViewModel(spectrum);
                Spectra.Add(msSpectrum);
            }

            foreach (var model in Spectra)
            {
                model.SetMax(m_maxMz, m_maxIntensity);
                model.SelectedSpectrumPlotModel.PlotSpectra(model.Spectrum);
            }

            if (spectra.Count > 0)
            {
                SelectedSpectra = Spectra[0];
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Reconstructs the mass tags and clusters joining tabled data.
        /// </summary>
        /// <param name="clusters"></param>
        /// <param name="matches"></param>
        /// <param name="database"></param>
        /// <returns></returns>
        public static Tuple <List <UMCClusterLightMatched>, List <MassTagToCluster> > MapMassTagsToClusters(
            this List <UMCClusterLight> clusters,
            List <ClusterToMassTagMap> matches,
            MassTagDatabase database)
        {
            var matchedClusters = new List <UMCClusterLightMatched>();
            var matchedTags     = new List <MassTagToCluster>();

            // Maps a cluster ID to a cluster that was matched (or not in which case it will have zero matches).
            var clusterMap = new Dictionary <int, UMCClusterLightMatched>();

            // Maps the mass tags to clusters, the second dictionary is for the conformations.
            var massTagMap =
                new Dictionary <int, Dictionary <int, MassTagToCluster> >();

            // Index the clusters.
            foreach (var cluster in clusters)
            {
                if (!clusterMap.ContainsKey(cluster.Id))
                {
                    var matchedCluster = new UMCClusterLightMatched();
                    matchedCluster.Cluster = cluster;
                    clusterMap.Add(cluster.Id, matchedCluster);
                }
            }

            if (database != null)
            {
                // Index the mass tags.
                foreach (var tag in database.MassTags)
                {
                    if (!massTagMap.ContainsKey(tag.Id))
                    {
                        massTagMap.Add(tag.Id, new Dictionary <int, MassTagToCluster>());
                    }
                    if (!massTagMap[tag.Id].ContainsKey(tag.ConformationId))
                    {
                        var matchedTag = new MassTagToCluster();
                        matchedTag.MassTag = tag;
                        massTagMap[tag.Id].Add(tag.ConformationId, matchedTag);
                    }
                }

                // Keeps track of all the proteins that we have mapped so far.
                var proteinList = new Dictionary <int, ProteinToMassTags>();

                // Link up the protein data
                foreach (var massTagId in massTagMap.Keys)
                {
                    foreach (var conformationID in massTagMap[massTagId].Keys)
                    {
                        var clusterTag = massTagMap[massTagId][conformationID];

                        // Here we make sure we link up the protein data too
                        if (database.Proteins.ContainsKey(massTagId))
                        {
                            // Get a list of the proteins this tag mapped to.
                            var proteins = database.Proteins[massTagId];

                            // Then for each protein, wrap it with a proteintomasstag map, then
                            //    mapping the tag to the protein
                            //    and mapping the protein to the tags.
                            foreach (var p in proteins)
                            {
                                if (!proteinList.ContainsKey(p.ProteinId))
                                {
                                    var tempProtein = new ProteinToMassTags();
                                    tempProtein.Protein = p;
                                    proteinList.Add(p.ProteinId, tempProtein);
                                }

                                var protein = proteinList[p.ProteinId];

                                // Double link the data so we can go back and forth
                                protein.MassTags.Add(clusterTag);
                                clusterTag.MatchingProteins.Add(protein);
                            }
                        }
                    }
                }
            }

            // Index and align matches
            foreach (var match in matches)
            {
                // Find the cluster map
                if (clusterMap.ContainsKey(match.ClusterId))
                {
                    var cluster = clusterMap[match.ClusterId];
                    cluster.ClusterMatches.Add(match);

                    MassTagToCluster tag = null;
                    if (massTagMap.ContainsKey(match.MassTagId))
                    {
                        tag = massTagMap[match.MassTagId][match.ConformerId];
                        tag.Matches.Add(cluster);
                        match.MassTag = tag;
                    }
                }
            }

            foreach (var clusterId in clusterMap.Keys)
            {
                matchedClusters.Add(clusterMap[clusterId]);
            }

            foreach (var tagId in massTagMap.Keys)
            {
                foreach (var conformerId in massTagMap[tagId].Keys)
                {
                    matchedTags.Add(massTagMap[tagId][conformerId]);
                }
            }

            var tuple =
                new Tuple <List <UMCClusterLightMatched>, List <MassTagToCluster> >(matchedClusters, matchedTags);

            return(tuple);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Updates the plots with data stored in the cache.
        /// </summary>
        private void UpdatePlotsWithClusterData(UMCClusterLightMatched matchedCluster)
        {
            //TODO: Make this select mass!
            ClusterMassPlot = ScatterPlotFactory.CreateFeatureMassScatterPlot(matchedCluster.Cluster.Features);

            //TODO: Make this select drift time!
            ClusterDriftPlot = ScatterPlotFactory.CreateFeatureDriftTimeScatterPlot(matchedCluster.Cluster.Features);

            var cluster = matchedCluster.Cluster;

            // Then we find all the nearby clusters
            var massPpm = ClusterTolerances.Mass;
            var net     = ClusterTolerances.Net;


            //TODO: Add other clusters back
            // var minMass = FeatureLight.ComputeDaDifferenceFromPPM(cluster.MassMonoisotopic, massPpm);
            //var maxMass = FeatureLight.ComputeDaDifferenceFromPPM(cluster.MassMonoisotopic, -massPpm);
            //var minNet = cluster.Net - net;
            //var maxNet = cluster.Net + net;

            //var otherClusters
            //    = SingletonDataProviders.Providers.ClusterCache.FindNearby(minMass, maxMass, minNet, maxNet);

            //// Remove self from the list
            //var index = otherClusters.FindIndex(x => x.Id == cluster.Id);

            //if (index > -1)
            //{
            //    otherClusters.RemoveAt(index);
            //}


            //// Then find the matching clusters and map them back to previously matched (to mass tag data)
            //var otherClusterMatches = new List<UMCClusterLightMatched>();
            //otherClusters.ForEach(x => otherClusterMatches.Add(FeatureCacheManager<UMCClusterLightMatched>.FindById(x.Id)));

            //foreach (var matchedOtherCluster in otherClusterMatches)
            //{
            //    matchedOtherCluster.Cluster.Features.Clear();
            //    matchedOtherCluster.Cluster.ReconstructUMCCluster(SingletonDataProviders.Providers, false, false);
            //}


            // Map out the MS/MS spectra.
            var msmsFeatures = new List <MSFeatureMsMs>();

            foreach (var feature in cluster.Features)
            {
                foreach (var msFeature in feature.MsFeatures)
                {
                    msmsFeatures.AddRange(msFeature.MSnSpectra.Select(spectrum => new MSFeatureMsMs
                    {
                        FeatureID               = msFeature.Id,
                        FeatureGroupID          = msFeature.GroupId,
                        Mz                      = msFeature.Mz,
                        PrecursorMZ             = spectrum.PrecursorMz,
                        FeatureScan             = msFeature.Scan,
                        MsMsScan                = spectrum.Scan,
                        MassMonoisotopicAligned = msFeature.MassMonoisotopicAligned,
                        ChargeState             = msFeature.ChargeState,
                        Sequence                = "",
                        PeptideSequence         = ""
                    }));
                }
            }


            var features = new List <UMCLight>();

            features.AddRange(matchedCluster.Cluster.Features);

            Features.Clear();
            features.ForEach(x => Features.Add(new UMCTreeViewModel(x)));
            SelectedFeature = Features[0];
        }
Exemplo n.º 6
0
        public UMCClusterTreeViewModel(UMCClusterLightMatched matchedCluster, TreeItemViewModel parent)
        {
            m_items   = new ObservableCollection <TreeItemViewModel>();
            m_parent  = parent;
            m_cluster = matchedCluster;
            var features = new UMCCollectionTreeViewModel(matchedCluster.Cluster);

            features.FeatureSelected += feature_FeatureSelected;
            features.Name             = "Features";

            // Cluster level statistics
            var cluster = matchedCluster.Cluster;

            AddStatistics("Mass", cluster.MassMonoisotopic);


            var item = new StringTreeViewItem(
                cluster.Net.ToString("F3",
                                     CultureInfo.InvariantCulture),
                "NET");

            m_items.Add(item);

            if (cluster.DriftTime > 0)
            {
                AddStatistics("Drift Time", cluster.DriftTime);
            }
            AddStatistics("Datasets", cluster.DatasetMemberCount);
            AddStatistics("Total", cluster.MemberCount);

            AddStatistics("Total MS/MS", cluster.MsMsCount);
            AddStatistics("Total Identifications", cluster.IdentifiedSpectraCount);

            var allIdentifications = new GenericCollectionTreeViewModel();

            allIdentifications.Name = "Identifications";

            // Items to display the base childen.
            var identifications = new PeptideCollectionTreeViewModel(cluster);

            identifications.Name             = "Search Results";
            identifications.FeatureSelected += feature_FeatureSelected;


            var spectra = new MsMsCollectionTreeViewModel(cluster);

            spectra.Name              = "MS/MS";
            m_spectra                 = spectra;
            spectra.SpectrumSelected += spectra_SpectrumSelected;
            spectra.FeatureSelected  += feature_FeatureSelected;

            var matches = new MassTagCollectionMatchTreeViewModel(matchedCluster.ClusterMatches);

            matches.Name = "AMT Tags";

            allIdentifications.Items.Add(identifications);
            allIdentifications.Items.Add(spectra);
            allIdentifications.Items.Add(matches);
            m_allIdentifications = allIdentifications;

            m_items.Add(features);
            m_items.Add(allIdentifications);
        }
Exemplo n.º 7
0
 public UMCClusterTreeViewModel(UMCClusterLightMatched cluster) :
     this(cluster, null)
 {
 }