public MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase();
            var massTags = new List<MassTagLight>();
            var masstagMap = new Dictionary<int, List<Protein>>();

            //TODO: Put into base table file reader
            var lines = File.ReadAllLines(DatabasePath);

            var delimiters = new[] {"\t"};

            for (var i = 1; i < lines.Length; i++)
            {
                var data = lines[i].Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                var tag = new MassTagLight();
                if (data.Length > 4)
                {
                    tag.Id = Convert.ToInt32(data[0]);
                    tag.PeptideSequence = data[1];
                    tag.MassMonoisotopic = Convert.ToDouble(data[2]);
                    tag.Net = Convert.ToDouble(data[3]);
                    tag.DriftTime = Convert.ToDouble(data[4]);
                }
                massTags.Add(tag);
            }

            database.AddMassTagsAndProteins(massTags, masstagMap);
            return database;
        }
Exemple #2
0
        /// <summary>
        /// Aligns a dataset to a mass tag database
        /// </summary>
        /// <param name="massTagDatabase"></param>
        /// <param name="features"></param>
        /// <param name="progress"></param>
        /// <returns></returns>
        public AlignmentData Align(MassTagDatabase massTagDatabase,
                                   IEnumerable <UMCLight> features,
                                   IProgress <ProgressData> progress = null)
        {
            var alignmentProcessor = new LcmsWarpAlignmentProcessor(_options);

            alignmentProcessor.Progress += AlignmentProcessor_Progress;

            var umcLights   = features as IList <UMCLight> ?? features.ToList();
            var featureTest = umcLights.ToList().Find(x => x.DriftTime > 0);

            if (featureTest != null && !massTagDatabase.DoesContainDriftTime)
            {
                OnStatus("Warning! Data contains drift time information and the database does not.");
            }

            OnStatus("Configuring features as mass tags.");

            OnStatus("Setting reference features using mass tags.");
            alignmentProcessor.SetReferenceDatasetFeatures(massTagDatabase.MassTags);
            var data = AlignFeatures(alignmentProcessor,
                                     umcLights,
                                     _options,
                                     progress);

            return(data);
        }
Exemple #3
0
        public MassTagDatabase LoadDatabase()
        {
            var database   = new MassTagDatabase();
            var massTags   = new List <MassTagLight>();
            var masstagMap = new Dictionary <int, List <Protein> >();

            //TODO: Put into base table file reader
            var lines = File.ReadAllLines(DatabasePath);

            var delimiters = new[] { "\t" };

            for (var i = 1; i < lines.Length; i++)
            {
                var data = lines[i].Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                var tag  = new MassTagLight();
                if (data.Length > 4)
                {
                    tag.Id = Convert.ToInt32(data[0]);
                    tag.PeptideSequence  = data[1];
                    tag.MassMonoisotopic = Convert.ToDouble(data[2]);
                    tag.Net       = Convert.ToDouble(data[3]);
                    tag.DriftTime = Convert.ToDouble(data[4]);
                }
                massTags.Add(tag);
            }

            database.AddMassTagsAndProteins(massTags, masstagMap);
            return(database);
        }
        public AnalysisControl()
        {
            InitializeComponent();

            m_processor = new MTDBProcessor();
            m_processor.DatabaseCreated    += new EventHandler <DatabaseCreatedEventArgs>(processor_DatabaseCreated);
            m_processor.Status             += new EventHandler <StatusEventArgs>(processor_Status);
            m_processor.Error              += new EventHandler <StatusEventArgs>(processor_Error);
            m_processor.AnalysisCompleted  += new EventHandler <AnalysisCompletedEventArgs>(processor_AnalysisCompleted);
            m_processor.ProcessingAnalysis += new EventHandler <AnalysisCompletedEventArgs>(processor_ProcessingAnalysis);
            m_processor.AnalysisFailed     += new EventHandler <DatabaseCreatedEventArgs>(m_processor_AnalysisFailed);

            m_displayCache = new Dictionary <Analysis, clsSeries>();
            m_manager      = new AnalysisManager();
            radioButtonPredictedNET.Checked = true;
            radioButtonAverageNET.Enabled   = false;

            m_database = null;
            listViewDatasets.SmallImageList = imageList1;

            // Create a save MTDB Dialog window for selecting where to output the data
            m_saveMTDBDialog          = new SaveFileDialog();
            m_saveMTDBDialog.FileName = CONST_DEFAULT_DATABASE_NAME;

            mobjTransformPlotter = new ChartPostRenderingProcessor(this.DrawNetRegressionLine);
            ctlChartScanVsNET.AddPostProcessor(mobjTransformPlotter, PostProcessPriority.Mid);

            listViewDatasets.DoubleClick += new EventHandler(listViewDatasets_DoubleClick);
        }
Exemple #5
0
        /// <summary>
        /// Aligns to a mass tag database.  The baseline provider should be able to convert a mass tag sequence into a theoretical spectrum.
        /// </summary>
        /// <param name="baseline"></param>
        /// <param name="alignee"></param>
        /// <returns></returns>
        public IEnumerable <SpectralAnchorPointMatch> Align(MassTagDatabase baseline,
                                                            IEnumerable <UMCLight> alignee, IProgress <ProgressData> progress = null)
        {
            OnProgress("Finding anchor point matches");
            var finder  = new SpectralAnchorPointFinder();
            var matches = finder.FindAnchorPoints(BaselineSpectraProvider as ISpectraProvider,
                                                  AligneeSpectraProvider as ISpectraProvider,
                                                  SpectralComparer,
                                                  Filter,
                                                  Options);

            OnProgress("Creating Alignment Functions");
            var aligner = new SpectralAnchorPointAligner();
            var spectralAnchorPointMatches = matches as SpectralAnchorPointMatch[] ?? matches.ToArray();

            //TODO: Brian modified to test alignment using LCMSWarp regression code.
            aligner.CreateAlignmentFunctions(spectralAnchorPointMatches);

            OnProgress("Transforming sub-features");
            foreach (var feature in alignee)
            {
                feature.NetAligned = feature.Net; // aligner.AlignNet(feature.Net);
            }

            return(spectralAnchorPointMatches);
        }
Exemple #6
0
        /// <summary>
        ///     Writes the peak matching results to the local peak matching database.
        /// </summary>
        public void WritePeakMatchResults(PeakMatchingResults <UMCClusterLight, MassTagLight> results,
                                          MassTagDatabase database,
                                          out int matchedMassTags,
                                          out int matchedProteins)
        {
            var clusterToMassTagMapDaoHibernate = new ClusterToMassTagMapDAOHibernate();

            var stacFdrdaoHibernate     = new STACDAOHibernate();
            var massTagList             = new List <MassTagLight>();
            var proteinList             = new Dictionary <int, Protein>();
            var clusterToMassTagMapList = new List <ClusterToMassTagMap>();

            clusterToMassTagMapDaoHibernate.ClearAll();
            stacFdrdaoHibernate.ClearAll();

            foreach (var match in results.Matches)
            {
                var tag                 = match.Target;
                var feature             = match.Observed;
                var clusterToMassTagMap = new ClusterToMassTagMap(feature.Id, tag.Id);
                clusterToMassTagMap.ConformerId = tag.ConformationId;

                if (!clusterToMassTagMapList.Contains(clusterToMassTagMap))
                {
                    clusterToMassTagMapList.Add(clusterToMassTagMap);
                    clusterToMassTagMap.StacScore = match.Confidence;
                    clusterToMassTagMap.StacUP    = match.Uniqueness;
                }

                if (!massTagList.Contains(tag))
                {
                    massTagList.Add(tag);
                }

                var databaseContainsProtein = database.Proteins.ContainsKey(tag.Id);
                if (databaseContainsProtein)
                {
                    var proteins = database.Proteins[tag.Id];
                    foreach (var protein in proteins.Where(protein => !proteinList.ContainsKey(protein.ProteinId)))
                    {
                        proteinList.Add(protein.ProteinId, protein);
                    }
                }
            }

            var uniqueProteins = new List <Protein>();

            foreach (var protein in proteinList.Values)
            {
                uniqueProteins.Add(protein);
            }

            matchedMassTags = massTagList.Count;
            matchedProteins = uniqueProteins.Count;
            clusterToMassTagMapDaoHibernate.AddAll(clusterToMassTagMapList);
            stacFdrdaoHibernate.AddAll(results.FdrTable);
        }
Exemple #7
0
        private IList <UMCLight> AlignDataset(
            IList <UMCLight> features,
            IEnumerable <UMCLight> baselineFeatures,
            MassTagDatabase database,
            DatasetInformation datasetInfo,
            DatasetInformation baselineInfo)
        {
            AlignmentData alignmentData;

            if (baselineInfo == null && database == null)
            {
                throw new NullReferenceException("No reference was set for LC-MS alignment.");
            }

            // align the data.
            if (baselineFeatures != null && baselineInfo != null && baselineInfo.IsBaseline)
            {
                // Align pairwise and cache results intermediately.
                var aligner = m_algorithms.DatasetAligner;
                RegisterProgressNotifier(aligner);

                UpdateStatus("Aligning " + datasetInfo.DatasetName + " to baseline.");
                alignmentData = aligner.Align(baselineFeatures, features);

                DeRegisterProgressNotifier(aligner);
            }
            else
            {
                // Align pairwise and cache results intermediately.
                var aligner = m_algorithms.DatabaseAligner;
                RegisterProgressNotifier(aligner);

                UpdateStatus("Aligning " + datasetInfo.DatasetName + " to mass tag database.");
                alignmentData = aligner.Align(database, features);

                DeRegisterProgressNotifier(aligner);
            }

            if (alignmentData != null)
            {
                alignmentData.AligneeDataset = datasetInfo.DatasetName;
                alignmentData.DatasetID      = datasetInfo.DatasetId;
            }

            var args = new FeaturesAlignedEventArgs(datasetInfo,
                                                    baselineFeatures,
                                                    features,
                                                    alignmentData);

            if (FeaturesAligned != null)
            {
                FeaturesAligned(this, args);
            }

            UpdateStatus("Updating cache with aligned features.");
            return(features);
        }
        /// <summary>
        ///     Writes the peak matching results to the local peak matching database.
        /// </summary>
        public void WritePeakMatchResults(PeakMatchingResults<UMCClusterLight, MassTagLight> results,
            MassTagDatabase database,
            out int matchedMassTags,
            out int matchedProteins)
        {
            var clusterToMassTagMapDaoHibernate = new ClusterToMassTagMapDAOHibernate();

            var stacFdrdaoHibernate = new STACDAOHibernate();
            var massTagList = new List<MassTagLight>();
            var proteinList = new Dictionary<int, Protein>();
            var clusterToMassTagMapList = new List<ClusterToMassTagMap>();

            clusterToMassTagMapDaoHibernate.ClearAll();
            stacFdrdaoHibernate.ClearAll();

            foreach (var match in results.Matches)
            {
                var tag = match.Target;
                var feature = match.Observed;
                var clusterToMassTagMap = new ClusterToMassTagMap(feature.Id, tag.Id);
                clusterToMassTagMap.ConformerId = tag.ConformationId;

                if (!clusterToMassTagMapList.Contains(clusterToMassTagMap))
                {
                    clusterToMassTagMapList.Add(clusterToMassTagMap);
                    clusterToMassTagMap.StacScore = match.Confidence;
                    clusterToMassTagMap.StacUP = match.Uniqueness;
                }

                if (!massTagList.Contains(tag))
                {
                    massTagList.Add(tag);
                }

                var databaseContainsProtein = database.Proteins.ContainsKey(tag.Id);
                if (databaseContainsProtein)
                {
                    var proteins = database.Proteins[tag.Id];
                    foreach (var protein in proteins.Where(protein => !proteinList.ContainsKey(protein.ProteinId)))
                    {
                        proteinList.Add(protein.ProteinId, protein);
                    }
                }
            }

            var uniqueProteins = new List<Protein>();
            foreach (var protein in proteinList.Values)
            {
                uniqueProteins.Add(protein);
            }

            matchedMassTags = massTagList.Count;
            matchedProteins = uniqueProteins.Count;
            clusterToMassTagMapDaoHibernate.AddAll(clusterToMassTagMapList);
            stacFdrdaoHibernate.AddAll(results.FdrTable);
        }
Exemple #9
0
        /// <summary>
        ///     Loads the mass tag database from the underlying database system.
        /// </summary>
        /// <returns></returns>
        public virtual MassTagDatabase LoadDatabase()
        {
            var database   = new MassTagDatabase();
            var tags       = LoadMassTags();
            var proteinMap = LoadProteins();

            database.AddMassTagsAndProteins(tags, proteinMap);

            return(database);
        }
        /// <summary>
        ///     Loads the mass tag database from the underlying database system.
        /// </summary>
        /// <returns></returns>
        public virtual MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase();
            var tags = LoadMassTags();
            var proteinMap = LoadProteins();

            database.AddMassTagsAndProteins(tags, proteinMap);

            return database;
        }
        /// <summary>
        ///     Default constructor for a MultiAlign analysis object.
        /// </summary>
        public MultiAlignAnalysis()
        {
            // Meta Data Information about the analysis and datasets.
            MetaData = new AnalysisMetaData {AnalysisName = string.Empty};
            Options = new MultiAlignAnalysisOptions();
            MassTagDatabase = new MassTagDatabase();

            // Alignment options and data.
            AlignmentData = new List<classAlignmentData>();
            MatchResults = null;
        }
Exemple #12
0
        public new AlignmentData Align(MassTagDatabase database, IEnumerable <UMCLight> alignee, IProgress <ProgressData> progress = null)
        {
            var matches = base.Align(database, alignee);
            var data    = new AlignmentData {
                Matches = matches
            };

            Matches = matches;

            return(data);
        }
Exemple #13
0
        /// <summary>
        ///     Default constructor for a MultiAlign analysis object.
        /// </summary>
        public MultiAlignAnalysis()
        {
            // Meta Data Information about the analysis and datasets.
            MetaData = new AnalysisMetaData {
                AnalysisName = string.Empty
            };
            Options         = new MultiAlignAnalysisOptions();
            MassTagDatabase = new MassTagDatabase();

            // Alignment options and data.
            AlignmentData = new List <AlignmentData>();
            MatchResults  = null;
        }
        /// <summary>
        /// Saves the database to file.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="path"></param>
        private void SaveDatabase(MassTagDatabase database, string path)
        {
            IMassTagDatabaseWriter writer = MassTagDatabaseWriterFactory.CreateWriter(MtdbWriterType.Sqlite);

            OnStatus("Filtering Database For Export Based on Options.");
            // Here we make sure that we filter the database...
            //MassTagDatabase filteredDatabase = new MassTagDatabase(database, m_options);

            OnStatus("Saving Database.");
            writer.WriteDatabase(database, path);

            OnStatus("Database Saved.");
            mbutton_showDatabase.Visible = true;
        }
Exemple #15
0
        private static MassTagDatabase ReadDatabase(string databasePath)
        {
            MassTagDatabase database = null;

            //Perform the reading from the binary file, saving data into database
            var fileBytes = File.ReadAllBytes(databasePath);

            var sb = new StringBuilder();

            foreach (var b in fileBytes)
            {
                sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
            }
            //Now it's a string of data
            var data = sb.ToString();

            return(database);
        }
        public MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase();

            var sink = new MAGEMetaSampleDatabaseSink();
            var reader = new DelimitedFileReader();

            reader.Delimiter = ",";
            reader.FilePath = Path;

            var pipeline = ProcessingPipeline.Assemble("MetaSample", reader, sink);
            pipeline.RunRoot(null);

            var tags =
                sink.MassTags.FindAll(
                    delegate(MassTagLight x) { return x.ObservationCount >= m_options.MinimumObservationCountFilter; });

            database.AddMassTagsAndProteins(tags, new Dictionary<int, List<Protein>>());

            // Fill in logic to read new type of mass tag database.
            return database;
        }
Exemple #17
0
        public AlignmentData AlignToDatabase(
            ref IList <UMCLight> features,
            DatasetInformation datasetInfo,
            MassTagDatabase mtdb,
            IProgress <ProgressData> progress = null)
        {
            progress = progress ?? new Progress <ProgressData>();
            var aligner       = this.m_algorithms.DatabaseAligner;
            var alignmentData = aligner.Align(mtdb, features, progress);

            aligner.Progress += aligner_Progress;

            if (alignmentData != null)
            {
                alignmentData.AligneeDataset = datasetInfo.DatasetName;
                alignmentData.DatasetID      = datasetInfo.DatasetId;
            }

            aligner.Progress -= aligner_Progress;

            return(alignmentData);
        }
        void processor_DatabaseCreated(object sender, DatabaseCreatedEventArgs e)
        {
            // This is a thread safe thing here.  We can never access the GUI elements except from the
            // thread that created it...STA.
            if (InvokeRequired)
            {
                Invoke(new EventHandler <DatabaseCreatedEventArgs>(processor_DatabaseCreated), sender, e);
                return;
            }

            mprogress_analysis.Visible = false;
            m_database = e.Database;
            mbutton_saveDatabase.Visible  = true;
            radioButtonAverageNET.Enabled = true;

            databaseControl1.UpdateDatabaseView(m_database);
            OnStatus("Database Created.");
            if (DatabaseCreated != null)
            {
                DatabaseCreated(sender, new DatabaseCreatedEventArgs(e.Database));
            }

            m_database.ConsensusTargets.ForEach(x => x.Targets.Clear());
        }
Exemple #19
0
        public MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase();


            var sink   = new MAGEMetaSampleDatabaseSink();
            var reader = new DelimitedFileReader();

            reader.Delimiter = ",";
            reader.FilePath  = Path;

            var pipeline = ProcessingPipeline.Assemble("MetaSample", reader, sink);

            pipeline.RunRoot(null);



            var tags = sink.MassTags.Where(x => x.ObservationCount >= m_options.MinimumObservationCountFilter);

            database.AddMassTagsAndProteins(tags.ToList(), new Dictionary <int, List <Protein> >());

            // Fill in logic to read new type of mass tag database.
            return(database);
        }
Exemple #20
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;
        }
Exemple #21
0
        public MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase();

            //Implement the loading / reading of the MTDB Framework objects.

            var reader       = new SqLiteTargetDatabaseReader();
            var mtdbDatabase = reader.ReadDb(m_path);
            var massTags     = new List <MassTagLight>();

            // Mapping objects to create unique proteins and for the mass tag database to load only those proteins for
            // the given consensus targets/mass tags.
            var proteinMap        = new Dictionary <int, Protein>();
            var massTagProteinMap = new Dictionary <int, List <Protein> >();

            if (mtdbDatabase == null)
            {
                return(database);
            }

            foreach (var target in mtdbDatabase.ConsensusTargets)
            {
                // Copy the consensus data into a mass tag light.
                var tag = new MassTagLight
                {
                    Id = target.Id,
                    MassMonoisotopic     = target.TheoreticalMonoIsotopicMass,
                    NetAverage           = target.AverageNet,
                    NetPredicted         = target.PredictedNet,
                    PeptideSequence      = target.Sequence,
                    NetStandardDeviation = target.StdevNet
                };


                // Here we create unique proteins for the mass tag copying information from the consensus target proteins.
                var proteinsForMassTag = new List <Protein>();
                foreach (var targetProtein in target.Proteins)
                {
                    if (!proteinMap.ContainsKey(targetProtein.Id))
                    {
                        var newProtein = new Protein
                        {
                            Id   = targetProtein.Id,
                            Name = targetProtein.ProteinName,
                            ResidueStartPosition = targetProtein.ResidueStart,
                            ResidueEndPosition   = targetProtein.ResidueEnd
                        };
                        //TODO: Do something about the cleavage state and terminus state of a protein loaded from MTDBCreator database.
                        //protein.CleavageState = ??
                        //protein.TerminusState = ??

                        proteinMap.Add(newProtein.Id, newProtein);
                    }

                    var protein = proteinMap[targetProtein.Id];
                    proteinsForMassTag.Add(protein);
                }

                massTagProteinMap.Add(tag.Id, proteinsForMassTag);
                massTags.Add(tag);
            }

            database.AddMassTagsAndProteins(massTags, massTagProteinMap);
            return(database);
        }
        public MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase {Name = ""};

            UpdateStatus("Loading all of the mass tags.");
            // Get all of the mass tags
            var massTags = Provider.FindAll();

            UpdateStatus("Loading all of the tag to protein references.");
            // Then get all of the mass tag to protein maps
            IGenericDAO<MassTagToProteinMap> tagToProteinMapCache = new GenericDAOHibernate<MassTagToProteinMap>();
            var maps = tagToProteinMapCache.FindAll();

            // Then get all of the proteins
            UpdateStatus("Loading all of the protein data.");
            IProteinDAO proteinCache = new ProteinDAO();
            var proteins = proteinCache.FindAll();

            UpdateStatus("Indexing the protein data for faster assembly.");
            var proteinMap = new Dictionary<int, Protein>();
            foreach (var p in proteins)
            {
                if (!proteinMap.ContainsKey(p.ProteinId))
                {
                    proteinMap.Add(p.ProteinId, p);
                }
            }

            var matchedMaps = new Dictionary<int, List<MassTagToProteinMap>>();

            foreach (var singleMap in maps)
            {
                if (!matchedMaps.ContainsKey(singleMap.MassTagId))
                {
                    matchedMaps.Add(singleMap.MassTagId, new List<MassTagToProteinMap>());
                }
                matchedMaps[singleMap.MassTagId].Add(singleMap);
            }

            UpdateStatus("Re-mapping the proteins to the mass tags.");
            var massTagProteinMap = new Dictionary<int, List<Protein>>();

            // Then map them.
            foreach (var tag in massTags)
            {
                var id = tag.Id;

                if (!massTagProteinMap.ContainsKey(id))
                {
                    massTagProteinMap.Add(id, new List<Protein>());
                }

                var matches = new List<MassTagToProteinMap>();

                if (matchedMaps.ContainsKey(id))
                {
                    matches = matchedMaps[id];
                }

                var newProteins = new List<Protein>();
                foreach (var mtMap in matches)
                {
                    if (proteinMap.ContainsKey(mtMap.ProteinId))
                    {
                        newProteins.Add(proteinMap[mtMap.ProteinId]);
                    }
                }
                massTagProteinMap[id].AddRange(newProteins);
            }

            UpdateStatus("Building the in memory mass tag database.");
            database.AddMassTagsAndProteins(massTags, massTagProteinMap);
            database.AllProteins = proteins;

            var totalMassTags = database.MassTags.Count;
            UpdateStatus("Loaded " + totalMassTags + " mass tags.");

            return database;
        }
Exemple #23
0
 public BaselineFeaturesLoadedEventArgs(DatasetInformation info, List <UMCLight> features,
                                        MassTagDatabase database) :
     base(info, features)
 {
     Database = database;
 }
Exemple #24
0
 /// <summary>
 ///     Arguments that hold dataset information when features are loaded.
 /// </summary>
 public MassTagsLoadedEventArgs(List <MassTagLight> tags, MassTagDatabase database)
 {
     MassTags = tags;
     Database = database;
 }
Exemple #25
0
 public AlignmentData Align(MassTagDatabase database,
                            IEnumerable <UMCLight> features, IProgress <ProgressData> progress = null)
 {
     return(null);
 }
        /// <summary>
        ///     Loads baseline data for alignment.
        /// </summary>
        private IList<UMCLight> LoadBaselineData(DatasetInformation baselineInfo,
            MsFeatureFilteringOptions msFilterOptions,
            LcmsFeatureFindingOptions lcmsFindingOptions,
            LcmsFeatureFilteringOptions lcmsFilterOptions,
            FeatureDataAccessProviders dataProviders,
            MassTagDatabase database,
            bool shouldUseMassTagDbAsBaseline)
        {
            IList<UMCLight> baselineFeatures = null;

            UpdateStatus("Loading baseline features.");
            if (!shouldUseMassTagDbAsBaseline)
            {
                if (baselineInfo == null)
                {
                    throw new Exception("The baseline dataset was never set.");
                }

                var cache = new FeatureLoader
                {
                    Providers = dataProviders
                };

                RegisterProgressNotifier(cache);

                UpdateStatus("Loading baseline features from " + baselineInfo.DatasetName + " for alignment.");

                baselineFeatures = cache.LoadDataset(baselineInfo,
                    msFilterOptions,
                    lcmsFindingOptions,
                    lcmsFilterOptions);

                cache.CacheFeatures(baselineFeatures);
                if (BaselineFeaturesLoaded != null)
                {
                    BaselineFeaturesLoaded(this,
                        new BaselineFeaturesLoadedEventArgs(baselineInfo, baselineFeatures.ToList()));
                }

                DeRegisterProgressNotifier(cache);
            }
            else
            {
                if (database == null)
                    throw new NullReferenceException(
                        "The mass tag database has to have data in it if it's being used for drift time alignment.");

                UpdateStatus("Setting baseline features for post drift time alignment from mass tag database.");
                var tags = FeatureDataConverters.ConvertToUMC(database.MassTags);

                if (BaselineFeaturesLoaded == null)
                    return tags;

                if (tags != null)
                    BaselineFeaturesLoaded(this, new BaselineFeaturesLoadedEventArgs(null, tags.ToList(), database));
            }
            return baselineFeatures;
        }
Exemple #27
0
        /// <summary>
        ///     Loads baseline data for alignment.
        /// </summary>
        private IList <UMCLight> LoadBaselineData(DatasetInformation baselineInfo,
                                                  MsFeatureFilteringOptions msFilterOptions,
                                                  LcmsFeatureFindingOptions lcmsFindingOptions,
                                                  LcmsFeatureFilteringOptions lcmsFilterOptions,
                                                  DataLoadingOptions dataLoadOptions,
                                                  FeatureDataAccessProviders dataProviders,
                                                  MassTagDatabase database,
                                                  bool shouldUseMassTagDbAsBaseline)
        {
            IList <UMCLight> baselineFeatures = null;

            UpdateStatus("Loading baseline features.");
            if (!shouldUseMassTagDbAsBaseline)
            {
                if (baselineInfo == null)
                {
                    throw new Exception("The baseline dataset was never set.");
                }

                var cache = new FeatureLoader
                {
                    Providers = dataProviders
                };

                RegisterProgressNotifier(cache);

                UpdateStatus("Loading baseline features from " + baselineInfo.DatasetName + " for alignment.");

                baselineFeatures = cache.LoadDataset(baselineInfo,
                                                     msFilterOptions,
                                                     lcmsFindingOptions,
                                                     lcmsFilterOptions,
                                                     dataLoadOptions,
                                                     m_scanSummaryProviderCache,
                                                     this.m_identificationsProvider);

                cache.CacheFeatures(baselineFeatures);
                if (BaselineFeaturesLoaded != null)
                {
                    BaselineFeaturesLoaded(this,
                                           new BaselineFeaturesLoadedEventArgs(baselineInfo, baselineFeatures.ToList()));
                }

                DeRegisterProgressNotifier(cache);
            }
            else
            {
                if (database == null)
                {
                    throw new NullReferenceException(
                              "The mass tag database has to have data in it if it's being used for drift time alignment.");
                }

                UpdateStatus("Setting baseline features for post drift time alignment from mass tag database.");
                var tags = FeatureDataConverters.ConvertToUMC(database.MassTags);

                if (BaselineFeaturesLoaded == null)
                {
                    return(tags);
                }

                if (tags != null)
                {
                    BaselineFeaturesLoaded(this, new BaselineFeaturesLoadedEventArgs(null, tags.ToList(), database));
                }
            }
            return(baselineFeatures);
        }
 public BaselineFeaturesLoadedEventArgs(DatasetInformation info, List<UMCLight> features,
     MassTagDatabase database)
     : base(info, features)
 {
     Database = database;
 }
Exemple #29
0
        /// <summary>
        /// Load a Liquid lipd MS/MS search results file as a MultiAlign
        /// <see cref="MassTagDatabase" />.
        /// </summary>
        /// <returns>The resulting mass tag database.</returns>
        /// <exception cref="FormatException">
        /// Throws a format exception when there are missing headers, or
        /// a non-numeric value was found in a column that was expected to be numeric.
        /// </exception>
        public MassTagDatabase LoadDatabase()
        {
            var headers = new Dictionary <string, int>();

            var massTags = new List <MassTagLight>();

            // Mapping between protein (actually lipid) name, to protein object (currently represents lipids).
            var commonNameToProtein = new Dictionary <string, Protein>();

            int lipidId = 0;

            // Parse lines of file into mass tags.
            int lineCount = 0;

            foreach (var line in File.ReadLines(this.filePath))
            {
                var parts = line.Split('\t');
                if (lineCount++ == 0)
                {   // Header line, store header indices
                    for (int i = 0; i < parts.Length; i++)
                    {
                        headers.Add(parts[i], i);
                    }

                    // Make sure all of the headers we are expecting are actually in the file.
                    this.DetectMissingHeaders(headers);
                    continue;
                }

                var net  = Convert.ToDouble(parts[headers["NET"]]);
                var mz   = Convert.ToDouble(parts[headers["Exact m/z"]]);
                var mass = mz - Constants.Proton;

                var name    = parts[headers["Common Name"]];
                var formula = parts[headers["Formula"]];

                // Add lipid to mapping if it isn't already there
                if (!commonNameToProtein.ContainsKey(name))
                {
                    commonNameToProtein.Add(
                        name,
                        new Protein
                    {
                        Id               = lipidId++,
                        ChargeState      = 1,
                        ChemicalFormula  = formula,
                        MassMonoisotopic = mass,
                        Mz               = mz,
                        Name             = name,
                        Sequence         = formula,
                    });
                }

                // Data line, create mass tag
                massTags.Add(
                    new MassTagLight
                {                                            // TODO: We have lipid data now, we're not doing just proteomics anymore. We should have omic-independent names for this stuff.
                    Id                      = lineCount - 2, // Subtract 2 because i will be incremented once when it sees the headers, and once before it gets to this line
                    ProteinName             = name,
                    PeptideSequence         = formula,
                    Net                     = net,
                    NetAligned              = net,
                    NetAverage              = net,
                    NetPredicted            = net,
                    MassMonoisotopic        = mass,
                    MassMonoisotopicAligned = mass,
                    Mz                      = mz,
                });
            }

            // Mapping from masstags to proteins (actually lipids)
            var massTagToProtein = new Dictionary <int, List <Protein> >();

            // Create mappings.
            foreach (var massTag in massTags)
            {
                var protein = commonNameToProtein[massTag.ProteinName];

                massTagToProtein.Add(massTag.Id, new List <Protein>());
                massTagToProtein[massTag.Id].Add(protein);
            }

            // Finally, create the mass tag database.
            var massTagDatabase = new MassTagDatabase();

            massTagDatabase.AddMassTagsAndProteins(massTags, massTagToProtein);

            return(massTagDatabase);
        }
Exemple #30
0
        public MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase {
                Name = ""
            };

            UpdateStatus("Loading all of the mass tags.");
            // Get all of the mass tags
            var massTags = Provider.FindAll();


            UpdateStatus("Loading all of the tag to protein references.");
            // Then get all of the mass tag to protein maps
            IGenericDAO <MassTagToProteinMap> tagToProteinMapCache = new GenericDAOHibernate <MassTagToProteinMap>();
            var maps = tagToProteinMapCache.FindAll();

            // Then get all of the proteins
            UpdateStatus("Loading all of the protein data.");
            IProteinDAO proteinCache = new ProteinDAO();
            var         proteins     = proteinCache.FindAll();

            UpdateStatus("Indexing the protein data for faster assembly.");
            var proteinMap = new Dictionary <int, Protein>();

            foreach (var p in proteins)
            {
                if (!proteinMap.ContainsKey(p.ProteinId))
                {
                    proteinMap.Add(p.ProteinId, p);
                }
            }

            var matchedMaps = new Dictionary <int, List <MassTagToProteinMap> >();

            foreach (var singleMap in maps)
            {
                if (!matchedMaps.ContainsKey(singleMap.MassTagId))
                {
                    matchedMaps.Add(singleMap.MassTagId, new List <MassTagToProteinMap>());
                }
                matchedMaps[singleMap.MassTagId].Add(singleMap);
            }

            UpdateStatus("Re-mapping the proteins to the mass tags.");
            var massTagProteinMap = new Dictionary <int, List <Protein> >();

            // Then map them.
            foreach (var tag in massTags)
            {
                var id = tag.Id;

                if (!massTagProteinMap.ContainsKey(id))
                {
                    massTagProteinMap.Add(id, new List <Protein>());
                }

                var matches = new List <MassTagToProteinMap>();

                if (matchedMaps.ContainsKey(id))
                {
                    matches = matchedMaps[id];
                }

                var newProteins = new List <Protein>();
                foreach (var mtMap in matches)
                {
                    if (proteinMap.ContainsKey(mtMap.ProteinId))
                    {
                        newProteins.Add(proteinMap[mtMap.ProteinId]);
                    }
                }
                massTagProteinMap[id].AddRange(newProteins);
            }

            UpdateStatus("Building the in memory mass tag database.");
            database.AddMassTagsAndProteins(massTags, massTagProteinMap);
            database.AllProteins = proteins;

            var totalMassTags = database.MassTags.Count;

            UpdateStatus("Loaded " + totalMassTags + " mass tags.");

            return(database);
        }
Exemple #31
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);
        }
 /// <summary>
 ///     Arguments that hold dataset information when features are loaded.
 /// </summary>
 public MassTagsLoadedEventArgs(List<MassTagLight> tags, MassTagDatabase database)
 {
     MassTags = tags;
     Database = database;
 }
        public MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase();

            //Implement the loading / reading of the MTDB Framework objects.

            var reader          = new SqLiteTargetDatabaseReader();
            var mtdbDatabase    = reader.ReadDb(m_path);
            var massTags        = new List<MassTagLight>();

            // Mapping objects to create unique proteins and for the mass tag database to load only those proteins for
            // the given consensus targets/mass tags.
            var proteinMap          = new Dictionary<int, Protein>();
            var massTagProteinMap   = new Dictionary<int, List<Protein>>();

            if (mtdbDatabase == null)
                return database;

            foreach (var target in mtdbDatabase.ConsensusTargets)
            {
                // Copy the consensus data into a mass tag light.
                var tag = new MassTagLight
                {
                    Id = target.Id,
                    MassMonoisotopic = target.TheoreticalMonoIsotopicMass,
                    NetAverage = target.AverageNet,
                    NetPredicted = target.PredictedNet,
                    PeptideSequence = target.Sequence,
                    NetStandardDeviation = target.StdevNet
                };

                // Here we create unique proteins for the mass tag copying information from the consensus target proteins.
                var proteinsForMassTag = new List<Protein>();
                foreach (var targetProtein in target.Proteins)
                {
                    if (!proteinMap.ContainsKey(targetProtein.Id))
                    {
                        var newProtein = new Protein
                        {
                            Id = targetProtein.Id,
                            Name = targetProtein.ProteinName,
                            ResidueStartPosition = targetProtein.ResidueStart,
                            ResidueEndPosition = targetProtein.ResidueEnd
                        };
                        //TODO: Do something about the cleavage state and terminus state of a protein loaded from MTDBCreator database.
                        //protein.CleavageState = ??
                        //protein.TerminusState = ??

                        proteinMap.Add(newProtein.Id, newProtein);
                    }

                    var protein = proteinMap[targetProtein.Id];
                    proteinsForMassTag.Add(protein);
                }

                massTagProteinMap.Add(tag.Id, proteinsForMassTag);
                massTags.Add(tag);
            }

            database.AddMassTagsAndProteins(massTags, massTagProteinMap);
            return database;
        }
        private IList<UMCLight> AlignDataset(
            IList<UMCLight> features,
            IEnumerable<UMCLight> baselineFeatures,
            MassTagDatabase database,
            DatasetInformation datasetInfo,
            DatasetInformation baselineInfo)
        {
            classAlignmentData alignmentData;

            if (baselineInfo == null && database == null)
            {
                throw new NullReferenceException("No reference was set for LC-MS alignment.");
            }

            // align the data.
            if (baselineFeatures != null && baselineInfo != null && baselineInfo.IsBaseline)
            {
                // Align pairwise and cache results intermediately.
                var aligner = m_algorithms.DatasetAligner;
                RegisterProgressNotifier(aligner);

                UpdateStatus("Aligning " + datasetInfo.DatasetName + " to baseline.");
                alignmentData = aligner.Align(baselineFeatures, features);

                DeRegisterProgressNotifier(aligner);
            }
            else
            {
                // Align pairwise and cache results intermediately.
                var aligner = m_algorithms.DatabaseAligner;
                RegisterProgressNotifier(aligner);

                UpdateStatus("Aligning " + datasetInfo.DatasetName + " to mass tag database.");
                alignmentData = aligner.Align(database, features);

                DeRegisterProgressNotifier(aligner);
            }

            if (alignmentData != null)
            {
                alignmentData.aligneeDataset = datasetInfo.DatasetName;
                alignmentData.DatasetID = datasetInfo.DatasetId;
            }

            var args = new FeaturesAlignedEventArgs(datasetInfo,
                baselineFeatures,
                features,
                alignmentData);

            if (FeaturesAligned != null)
                FeaturesAligned(this, args);

            UpdateStatus("Updating cache with aligned features.");
            return features;
        }
Exemple #35
0
 public LcmsWarpAlignmentData Align(MassTagDatabase baseline, IEnumerable <UMCLight> alignee)
 {
     throw new NotImplementedException();
 }
Exemple #36
0
        /// <summary>
        ///     Performs STAC against the mass tag database.
        /// </summary>
        public List <MultiAlignCore.Data.MassTags.FeatureMatchLight <T, MassTagLight> > PerformPeakMatching(List <T> clusters, MassTagDatabase database)
        {
            var clusterMap = new Dictionary <int, T>();
            var tagMap     = new Dictionary <int, Dictionary <int, MassTagLight> >();

            var massTags = new List <MassTagLight>();
            var i        = 0;

            foreach (var tag in database.MassTags)
            {
                var mt = new MassTagLight
                {
                    Abundance      = Convert.ToInt32(tag.Abundance),
                    ChargeState    = tag.ChargeState,
                    CleavageState  = tag.CleavageState,
                    ConformationId = tag.ConformationId,
                    ConformationObservationCount = tag.ConformationObservationCount,
                    DiscriminantMax    = tag.DiscriminantMax,
                    DriftTime          = Convert.ToSingle(tag.DriftTime),
                    DriftTimePredicted = tag.DriftTimePredicted,
                    Id = tag.Id,
                    MassMonoisotopic  = tag.MassMonoisotopic,
                    ModificationCount = tag.ModificationCount,
                    Modifications     = tag.Modifications,
                    Molecule          = tag.Molecule,
                    MsgfSpecProbMax   = tag.MsgfSpecProbMax,
                    Net                  = tag.NetAverage,
                    NetAverage           = tag.NetAverage,
                    NetPredicted         = tag.NetPredicted,
                    NetStandardDeviation = tag.NetStandardDeviation,
                    ObservationCount     = tag.ObservationCount,
                    PeptideSequence      = tag.PeptideSequence,
                    PeptideSequenceEx    = tag.PeptideSequenceEx,
                    PriorProbability     = tag.PriorProbability,
                    QualityScore         = tag.QualityScore,
                    XCorr                = tag.XCorr
                };
                mt.Index = i++;
                massTags.Add(mt);
                if (!tagMap.ContainsKey(tag.Id))
                {
                    tagMap.Add(tag.Id, new Dictionary <int, MassTagLight>());
                }
                tagMap[tag.Id].Add(tag.ConformationId, tag);
            }

            // convert data needed by the algorithm.
            var features = new List <UMCClusterLight>();

            foreach (var cluster in clusters)
            {
                var feature = new UMCClusterLight
                {
                    Id = cluster.Id,
                    MassMonoisotopicAligned = cluster.MassMonoisotopic,
                    MassMonoisotopic        = cluster.MassMonoisotopic
                };
                feature.Net              = cluster.Net;
                feature.NetAligned       = cluster.Net;
                feature.ChargeState      = cluster.ChargeState;
                feature.DriftTime        = Convert.ToSingle(cluster.DriftTime);
                feature.DriftTimeAligned = Convert.ToDouble(cluster.DriftTime);
                features.Add(feature);

                clusterMap.Add(cluster.Id, cluster);
            }

            // create a stac manager and run.
            var matcher = new FeatureMatcher <UMCClusterLight, MassTagLight>(features, massTags, Options);

            matcher.MessageEvent            += StatusHandler;
            matcher.ProcessingCompleteEvent += StatusHandler;
            matcher.MatchFeatures();
            Matcher = matcher;


            Matcher.PopulateStacfdrTable(matcher.MatchList);

            var matches = new List <MultiAlignCore.Data.MassTags.FeatureMatchLight <T, MassTagLight> >();

            foreach (var match in matcher.MatchList)
            {
                var matched = new MultiAlignCore.Data.MassTags.FeatureMatchLight <T, MassTagLight>
                {
                    Observed   = clusterMap[match.ObservedFeature.Id],
                    Target     = tagMap[match.TargetFeature.Id][match.TargetFeature.ConformationId],
                    Confidence = match.STACScore,
                    Uniqueness = match.STACSpecificity
                };
                matches.Add(matched);
            }


            matcher.MessageEvent            -= StatusHandler;
            matcher.ProcessingCompleteEvent -= StatusHandler;

            return(matches);
        }
        /// <summary>
        ///     Load the data from the dataset information objects to the cache at the analysis Path
        /// </summary>
        private void PerformDataLoadAndAlignment(AnalysisConfig config)
        {
            UmcLoaderFactory.Status += UMCLoaderFactory_Status;

            UpdateStatus("Loading data.");
            var analysisOptions = config.Analysis.Options;
            var datasets = config.Analysis.MetaData.Datasets.ToList();
            var lcmsFilterOptions = analysisOptions.LcmsFilteringOptions;
            var msFilterOptions = analysisOptions.MsFilteringOptions;
            var baselineDataset = config.Analysis.MetaData.BaselineDataset;
            var baselineFeatures = LoadBaselineData(baselineDataset,
                msFilterOptions,
                analysisOptions.LcmsFindingOptions,
                lcmsFilterOptions,
                config.Analysis.DataProviders,
                config.Analysis.MassTagDatabase,
                config.Analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB);

            var alignmentData = new AlignmentDAOHibernate();
            alignmentData.ClearAll();

            var providers = config.Analysis.DataProviders;
            var featureCache = new FeatureLoader
            {
                Providers = providers
            };

            RegisterProgressNotifier(featureCache);

            MassTagDatabase database = null;
            if (config.Analysis.MassTagDatabase != null)
                database = new MassTagDatabase(config.Analysis.MassTagDatabase,
                    config.Analysis.Options.AlignmentOptions.MassTagObservationCount);

            SingletonDataProviders.Providers = config.Analysis.DataProviders;

            foreach (var dataset in datasets)
            {
                if (dataset.IsBaseline)
                    continue;

                var features = featureCache.LoadDataset(dataset,
                    analysisOptions.MsFilteringOptions,
                    analysisOptions.LcmsFindingOptions,
                    analysisOptions.LcmsFilteringOptions);
                features = AlignDataset(features,
                    baselineFeatures,
                    database,
                    dataset,
                    baselineDataset);
                featureCache.CacheFeatures(features);
            }
            UmcLoaderFactory.Status -= UMCLoaderFactory_Status;
        }
Exemple #38
0
        /// <summary>
        ///     Load the data from the dataset information objects to the cache at the analysis Path
        /// </summary>
        private void PerformDataLoadAndAlignment(AnalysisConfig config)
        {
            UmcLoaderFactory.Status += UMCLoaderFactory_Status;

            UpdateStatus("Loading data.");
            var analysisOptions   = config.Analysis.Options;
            var datasets          = config.Analysis.MetaData.Datasets.ToList();
            var lcmsFilterOptions = analysisOptions.LcmsFilteringOptions;
            var msFilterOptions   = analysisOptions.MsFilteringOptions;
            var dataLoadOptions   = analysisOptions.DataLoadOptions;
            var baselineDataset   = config.Analysis.MetaData.BaselineDataset;

            var baselineFeatures = LoadBaselineData(baselineDataset,
                                                    msFilterOptions,
                                                    analysisOptions.LcmsFindingOptions,
                                                    lcmsFilterOptions,
                                                    dataLoadOptions,
                                                    config.Analysis.DataProviders,
                                                    config.Analysis.MassTagDatabase,
                                                    config.Analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB);

            var alignmentData = new AlignmentDAOHibernate();

            alignmentData.ClearAll();


            var providers    = config.Analysis.DataProviders;
            var featureCache = new FeatureLoader
            {
                Providers = providers
            };

            RegisterProgressNotifier(featureCache);

            MassTagDatabase database = null;

            if (config.Analysis.MassTagDatabase != null)
            {
                database = new MassTagDatabase(config.Analysis.MassTagDatabase,
                                               config.Analysis.Options.AlignmentOptions.MassTagObservationCount);
            }

            SingletonDataProviders.Providers = config.Analysis.DataProviders;

            foreach (var dataset in datasets)
            {
                if (dataset.IsBaseline)
                {
                    continue;
                }

                var features = featureCache.LoadDataset(dataset,
                                                        analysisOptions.MsFilteringOptions,
                                                        analysisOptions.LcmsFindingOptions,
                                                        analysisOptions.LcmsFilteringOptions,
                                                        analysisOptions.DataLoadOptions,
                                                        m_scanSummaryProviderCache,
                                                        m_identificationsProvider);
                features = AlignDataset(features,
                                        baselineFeatures,
                                        database,
                                        dataset,
                                        baselineDataset);
                featureCache.CacheFeatures(features);
            }
            UmcLoaderFactory.Status -= UMCLoaderFactory_Status;
        }
Exemple #39
0
        public void UpdateDatabaseView(MassTagDatabase database)
        {
            mtree_proteins.Nodes.Clear();
            if (database == null)
            {
                return;
            }


            List <ConsensusTarget> targets = database.ConsensusTargets;
            TreeNode rootNode = new TreeNode(string.Format("Mass Tags ({0})", targets.Count));

            rootNode.ImageIndex = CONST_DATABASE;

            targets.Sort(delegate(ConsensusTarget p, ConsensusTarget p2)
            {
                return(p.Sequence.CompareTo(p2.Sequence));
            });

            long count = 0;

            foreach (ConsensusTarget target in targets)
            {
                if (count++ > 100)
                {
                    count = 0;
                    Application.DoEvents(); // I hate doing this but we should "draw" every N nodes (100 in this case)
                }

                // Only for predicted targets
                bool skip = false;
                foreach (Target t in target.Targets)
                {
                    if (!t.IsPredicted)
                    {
                        skip = true;
                    }
                }
                if (skip)
                {
                    continue;
                }

                TreeNode targetNode = new TreeNode(
                    string.Format("{0} ({1})",
                                  target.CleanSequence,
                                  target.Targets.Count
                                  ));
                targetNode.ImageIndex = CONST_MASS_TAG_RED;
                targetNode.Nodes.Add(string.Format("Avg NET: {0:F2}", target.GaNetAverage));
                targetNode.Nodes.Add(string.Format("Stdev. NET: {0:F2}", target.GaNetStdev));
                targetNode.Nodes.Add(string.Format("Min NET: {0:F2}", target.GaNetMinium));
                targetNode.Nodes.Add(string.Format("MaxNET: {0:F2}", target.GaNetMax));
                // Cheating...
                targetNode.Nodes[0].ImageIndex = CONST_PROPERTY;
                targetNode.Nodes[1].ImageIndex = CONST_PROPERTY;
                targetNode.Nodes[2].ImageIndex = CONST_PROPERTY;
                targetNode.Nodes[3].ImageIndex = CONST_PROPERTY;


                TreeNode targetSubNode = new TreeNode("Peptides");
                targetSubNode.ImageIndex = CONST_FLAME;
                targetNode.Nodes.Add(targetSubNode);

                foreach (Target t in target.Targets)
                {
                    TreeNode node = new TreeNode(t.Sequence);
                    node.ImageIndex = CONST_FLAME;
                    targetSubNode.Nodes.Add(node);
                    node.Nodes.Add(string.Format("Mass: {0:F2}", t.MonoisotopicMass));
                    node.Nodes.Add(string.Format("Scan: {0}", t.Scan));
                    node.Nodes.Add(string.Format("NET Pred: {0:F2}", t.NetPredicted));
                    node.Nodes.Add(string.Format("NET Align: {0:F2}", t.NetAligned));
                    node.Nodes[0].ImageIndex = CONST_PROPERTY;
                    node.Nodes[1].ImageIndex = CONST_PROPERTY;
                    node.Nodes[2].ImageIndex = CONST_PROPERTY;
                    node.Nodes[3].ImageIndex = CONST_PROPERTY;
                }


                TreeNode proteinSubNode = new TreeNode("Proteins");
                proteinSubNode.ImageIndex = CONST_PROTEIN;
                targetNode.Nodes.Add(proteinSubNode);

                foreach (Protein p in target.GetProteins())
                {
                    int matchedTargets = p.GetMappedTargets().Count;

                    TreeNode proteinNode = new TreeNode(
                        string.Format("{0} ({1})",
                                      p.Reference,
                                      matchedTargets));

                    proteinNode.ImageIndex = CONST_PROTEIN;
                    proteinNode.Nodes.Add(string.Format("Matching Mass Tags: {0}", matchedTargets));
                    proteinNode.Nodes[0].ImageIndex = CONST_PROTEIN;
                    proteinSubNode.Nodes.Add(proteinNode);
                }
                rootNode.Nodes.Add(targetNode);
            }
            mtree_proteins.Nodes.Add(rootNode);
            SetNodeSelectImage(rootNode);
            rootNode.Expand();
        }
Exemple #40
0
        /// <summary>
        /// Writes the database to the path provided.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="path"></param>
        public void WriteDatabase(MassTagDatabase database, string path)
        {
            // Remove the path if it already exists.
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            string connectionString = string.Format("Data Source = {0}", path);

            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                connection.Open();

                using (SQLiteCommand command = connection.CreateCommand())
                {
                    command.CommandText = string.Format("CREATE TABLE {0} ({1})", CONST_MASS_TAG_TABLE, CONST_MASS_TAG_COLUMNS);
                    command.ExecuteNonQuery();

                    command.CommandText = string.Format("CREATE TABLE {0} ({1})", CONST_PROTEIN_TABLE, CONST_PROTEIN_COLUMNS);
                    command.ExecuteNonQuery();

                    command.CommandText = string.Format("CREATE TABLE {0} ({1})", CONST_META_DATA_TABLE, CONST_META_DATA_COLUMNS);
                    command.ExecuteNonQuery();
                }

                string massTagValueFormatString  = "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}";
                string metaDataValueFormatString = "'{0}','{1}','{2}','{3}'";
                using (SQLiteTransaction transaction = connection.BeginTransaction())
                {
                    using (SQLiteCommand command = connection.CreateCommand())
                    {
                        foreach (Analysis analysis in database.MetaData)
                        {
                            string values = string.Format(metaDataValueFormatString, analysis.Name, analysis.FilePath, analysis.CreationDate, analysis.NumberOfUniqueMassTags);
                            command.CommandText = BuildTableInsertCommand(CONST_META_DATA_TABLE,
                                                                          values);
                            command.ExecuteNonQuery();
                        }
                    }

                    // Write the mass tags
                    foreach (ConsensusTarget averageTarget in database.ConsensusTargets)
                    {
                        using (SQLiteCommand command = connection.CreateCommand())
                        {
                            string values = string.Format(massTagValueFormatString,
                                                          averageTarget.Id,                                                        // 0
                                                          string.Format("'{0}'", averageTarget.Sequence),                          // 1
                                                          averageTarget.GaNetAverage,                                              // 2
                                                          averageTarget.HighNormalizedScore,                                       // 3
                                                          0,
                                                          averageTarget.GaNetStdev,                                                // 4
                                                          averageTarget.MonoisotopicMass,                                          // 5
                                                          averageTarget.MinimumSpecProbability,                                    // 6
                                                          averageTarget.Targets.Count,                                             // 7
                                                          averageTarget.ModificationCount,                                         // 8
                                                          string.Format("'{0}'", averageTarget.ModificationDescription),           // 9
                                                          averageTarget.HighPeptideProphetProbability,                             // 10
                                                          0,                                                                       // 11
                                                          averageTarget.DriftTime,                                                 // 12
                                                          averageTarget.ConformerCharge,                                           // 13
                                                          averageTarget.ConformerId);                                              // 14

                            string commandText = BuildTableInsertCommand(CONST_MASS_TAG_TABLE,
                                                                         values);
                            command.CommandText = commandText;
                            command.ExecuteNonQuery();
                        }
                    }

                    // Write the proteins - each protein may by mapped by multiple mass tags - or consensus targets
                    foreach (Protein protein in database.Proteins)
                    {
                        List <ConsensusTarget> targets = protein.GetMappedTargets();
                        foreach (ConsensusTarget target in targets)
                        {
                            using (SQLiteCommand command = connection.CreateCommand())
                            {
                                string values = string.Format("{0}, {1}, '{2}', {3}", target.Id,
                                                              protein.Id,
                                                              protein.Reference,
                                                              protein.Id);

                                string commandText = BuildTableInsertCommand(CONST_PROTEIN_TABLE,
                                                                             values);
                                command.CommandText = commandText;
                                command.ExecuteNonQuery();
                            }
                        }
                    }

                    transaction.Commit();
                }
                connection.Close();
            }

            foreach (ConsensusTarget target in database.ConsensusTargets)
            {
                target.Targets.Clear();
            }
        }