Beispiel #1
0
        public void LoadFactorsFromDMS(ObservableCollection<DatasetInformation> datasets,
            FeatureDataAccessProviders providers)
        {
            if (datasets.Count < 1)
            {
                return;
            }

            var sink = new MultiAlignFactorSink(datasets,
                providers.DatasetCache,
                providers.FactorCache,
                providers.FactorAssignmentCache);
            foreach (var info in datasets)
            {
                var query = m_sqlQuery + string.Format(" = '{0}'", info.DatasetName);
                var reader = new MSSQLReader();
                reader.Server = Server;
                reader.Database = Database;
                reader.SQLText = query;

                var pipeline = ProcessingPipeline.Assemble("PlainFactors", reader, sink);
                pipeline.RunRoot(null);
            }
            sink.CommitChanges();
        }
        public void CalculateClusterErrorHistograms(FeatureDataAccessProviders providers, List<double> massErrorPpm, List<double> netError, List<double> counts, FeatureTolerances tolerances)
        {
            List<UMCLight> featuresA = providers.FeatureCache.FindByDatasetId(0);
            List<UMCLight> featuresB = providers.FeatureCache.FindByDatasetId(1);

            featuresA.Sort(

                delegate (UMCLight x, UMCLight y)
                    {
                        return x.MassMonoisotopic.CompareTo(y.MassMonoisotopic);
                    }
                );

            featuresB.Sort(

                delegate (UMCLight x, UMCLight y)
                    {
                        return x.MassMonoisotopic.CompareTo(y.MassMonoisotopic);
                    }
                );

            int i = 0;
            foreach(UMCLight featureA in featuresA)
            {
                double count = 0;
                int j        = i + 1;
                foreach (UMCLight featureB in featuresB)
                {
                    double ppmDiff = Feature.ComputeMassPPMDifference(featureB.MassMonoisotopicAligned, featureA.MassMonoisotopicAligned);
                    if (Math.Abs(ppmDiff) > tolerances.Mass)
                    {
                        continue;
                    }

                    double netDiff = featureA.RetentionTime - featureB.RetentionTime;
                    if (Math.Abs(netDiff) > tolerances.RetentionTime)
                    {
                        continue;
                    }

                    massErrorPpm.Add(ppmDiff);
                    netError.Add(netDiff);
                }
                i = j;
                counts.Add(count);
            }
        }
Beispiel #3
0
        public static FeatureDataAccessProviders CreateDataAccessProviders(string path, bool deleteIfExists)
        {
            if (deleteIfExists)
            {
                var exists = File.Exists(path);
                if (exists)
                {
                    File.Delete(path);
                }
            }
            try
            {
                NHibernateUtil.ConnectToDatabase(path, true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            IUmcDAO featureCache = new UmcDAOHibernate();
            IUmcClusterDAO clusterCache = new UmcClusterDAOHibernate();
            IMSFeatureDAO msFeatureCache = new MSFeatureDAOHibernate();
            IMSnFeatureDAO msnFeatureCache = new MSnFeatureDAOHibernate();
            IMsnFeatureToMSFeatureDAO msnMSCache = new MSnFeatureToMSFeatureDAOHibernate();
            IDatasetDAO datasetCache = new DatasetDAOHibernate();
            IMassTagDAO massTagCache = new MassTagDAOHibernate();
            IMassTagMatchDAO massTagMatchCache = new MassTagMatchDAO();
            ISequenceToMsnFeatureDAO sequenceMap = new SequenceToMsnDAOHibernate();

            var providers =
                new FeatureDataAccessProviders(featureCache,
                    clusterCache,
                    msFeatureCache,
                    msnFeatureCache,
                    msnMSCache,
                    datasetCache,
                    massTagMatchCache,
                    massTagCache,
                    new FactorDAOHibernate(),
                    new DatasetToFactorDAOHibernate(),
                    new MSMSClusterMapClusterDAOHibernate(),
                    new DatabaseSearchSequenceDAOHiberate(),
                    sequenceMap);

            return providers;
        }
Beispiel #4
0
        public void LoadFactorsFromFile(string path, ObservableCollection<DatasetInformation> datasets,
            FeatureDataAccessProviders providers)
        {
            if (datasets.Count < 1)
            {
                return;
            }

            var sink = new MultiAlignFactorSink(datasets,
                providers.DatasetCache,
                providers.FactorCache,
                providers.FactorAssignmentCache);

            var reader = new DelimitedFileReader();
            reader.Delimiter = "\t";
            reader.FilePath = path;

            var pipeline = ProcessingPipeline.Assemble("PlainFactors", reader, sink);
            pipeline.RunRoot(null);
            sink.CommitChanges();
        }
Beispiel #5
0
        private IEnumerable<UMCLight> RetrieveFeatures(int datasetId, FeatureDataAccessProviders providers)
        {
            var features     = providers.FeatureCache.FindByDatasetId(datasetId);
            var spectra      = providers.MSnFeatureCache.FindByDatasetId(datasetId);
            if (spectra == null)
                throw new ArgumentNullException(@"There were no MS/MS spectra in the database");

            var sequences    = providers.DatabaseSequenceCache.FindAll();
            var sequenceMaps = providers.SequenceMsnMapCache.FindByDatasetId(datasetId);
            var spectraMaps  = providers.MSFeatureToMSnFeatureCache.FindByDatasetId(datasetId);
            var msFeatures   = providers.MSFeatureCache.FindByDatasetId(datasetId);

            // Make a one pass through each enumerable list,
            // then use the maps to join the data together
            var dictFeatures = new Dictionary<int, UMCLight>();
            var dictSpectra  = new Dictionary<int, MSSpectra>();
            var dictPeptide  = new Dictionary<int, Peptide>();
            var dictMsFeatures = new Dictionary<int, MSFeatureLight>();

            foreach (var sequence in sequences)
            {
                if (sequence.GroupId != datasetId)
                    continue;

                var peptide = new Peptide
                {
                    Sequence =  sequence.Sequence,
                    Id       =  sequence.Id,
                };
                dictPeptide.Add(peptide.Id, peptide);
            }

            msFeatures.ForEach(x => dictMsFeatures.Add(x.Id, x));
            features.ForEach(x => dictFeatures.Add(x.Id, x));
            spectra.ForEach(x  => dictSpectra.Add(x.Id, x));

            var count = 0;
            // Map the MSMS
            foreach (var map in sequenceMaps)
            {
                MSSpectra spectrum;
                Peptide   peptide;
                var workedSpectra = dictSpectra.TryGetValue(map.MsnFeatureId, out spectrum);
                var workedPeptide = dictPeptide.TryGetValue(map.SequenceId, out peptide);

                if (workedSpectra && workedPeptide)
                {
                    spectrum.Peptides.Add(peptide);
                    peptide.Spectrum = spectrum;
                    count++;
                }
            }

            Console.WriteLine("Mapped {0} peptides to spectra", count);
            count = 0;

            // Map the spectra....
            foreach (var map in spectraMaps)
            {
                UMCLight  feature;
                MSSpectra spectrum;
                MSFeatureLight msFeature;

                var workedFeatures  = dictFeatures.TryGetValue(map.LCMSFeatureID, out feature);
                var workedSpectra   = dictSpectra.TryGetValue(map.MSMSFeatureID,  out spectrum);
                var workedMsFeature = dictMsFeatures.TryGetValue(map.MSFeatureID, out msFeature);
                if (!workedFeatures || !workedSpectra || !workedMsFeature)
                    continue;

                var metaData = new ScanSummary
                {
                    MsLevel = 2,
                    PrecursorMz = spectrum.PrecursorMz,
                    Scan = spectrum.Scan
                };
                spectrum.ScanMetaData = metaData;

                msFeature.MSnSpectra.Add(spectrum);
                spectrum.ParentFeature = msFeature;
                feature.AddChildFeature(msFeature);
                msFeature.Umc = feature;
                count++;
            }

            Console.WriteLine("Mapped {0} spectra to parent Features", count);
            return features;
        }
Beispiel #6
0
 private FeatureDataAccessProviders SetupDataProviders(bool createNewDatabase)
 {
     FeatureDataAccessProviders providers;
     Logger.PrintMessage("Setting up data providers for caching and storage.");
     try
     {
         var path = AnalysisPathUtils.BuildAnalysisName(m_config.AnalysisPath, m_config.AnalysisName);
         providers = SetupDataProviders(path, createNewDatabase);
     }
     catch (IOException ex)
     {
         Logger.PrintMessage(ex.Message);
         Logger.PrintMessage(ex.StackTrace);
         throw;
     }
     return providers;
 }
        /// <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;
        }
Beispiel #8
0
        /// <summary>
        ///     Determines if MS/MS should also be discovered.
        /// </summary>
        /// <param name="cluster"></param>
        /// <param name="providers"></param>
        /// <param name="getMsMS"></param>
        public static void ReconstructUMCCluster(this UMCClusterLight cluster, FeatureDataAccessProviders providers,
            bool getMsFeature, bool getMsMs)
        {
            cluster.Features.Clear();

            var features = providers.FeatureCache.FindByClusterID(cluster.Id);

            var totalSpectra = 0;
            var totalIdentified = 0;
            foreach (var feature in features)
            {
                cluster.AddChildFeature(feature);

                if (getMsFeature)
                {
                    feature.ReconstructUMC(providers, getMsMs);

                    foreach (var msFeature in feature.MsFeatures)
                    {
                        totalSpectra += msFeature.MSnSpectra.Count;
                        foreach (var spectrum in msFeature.MSnSpectra)
                        {
                            if (spectrum.Peptides.Count > 0)
                                totalIdentified++;
                        }
                    }
                }
            }

            cluster.IdentifiedSpectraCount = totalIdentified;
            cluster.MsMsCount = totalSpectra;
        }
Beispiel #9
0
 /// <summary>
 ///     Gets a cluster and it's subsequent data structures.
 /// </summary>
 /// <param name="cluster"></param>
 /// <param name="providers"></param>
 public static void ReconstructUMCCluster(this UMCClusterLight cluster, FeatureDataAccessProviders providers)
 {
     cluster.ReconstructUMCCluster(providers, true, true);
 }
Beispiel #10
0
 /// <summary>
 ///     Retrieves a list of known peptides attributed to this cluster.
 /// </summary>
 /// <param name="cluster"></param>
 /// <param name="providers"></param>
 /// <returns></returns>
 public static List<MSSpectra> FindSpectra(this UMCClusterLight cluster, FeatureDataAccessProviders providers)
 {
     var peptides = new List<MSSpectra>();
     return peptides;
 }
Beispiel #11
0
        private void ExportData(FeatureDataAccessProviders providers, List<DatasetInformation> datasets)
        {
            if (m_config.ClusterExporters.Count > 0)
            {
                var clusters = providers.ClusterCache.FindAll();
                if (clusters.Count < 1)
                {
                    Logger.PrintMessage("No clusters present in the database.");
                    return;
                }
                var features = providers.FeatureCache.FindAllClustered();

                var clusterFeatureMap = new Dictionary<int, UMCClusterLight>();
                foreach (var cluster in clusters)
                {
                    clusterFeatureMap[cluster.Id] = cluster;
                }
                foreach (var umc in features)
                {
                    clusterFeatureMap[umc.ClusterId].AddChildFeature(umc);
                }

                Logger.PrintMessage("Checking for mass tag matches");
                var clusterMatches = providers.MassTagMatches.FindAll();

                Logger.PrintMessage("Checking for mass tags");
                var massTags = providers.MassTags.FindAll();

                var clusterMap = new Dictionary<int, List<ClusterToMassTagMap>>();
                if (clusterMatches.Count > 0)
                {
                    foreach (var map in clusterMatches)
                    {
                        if (!clusterMap.ContainsKey(map.ClusterId))
                        {
                            clusterMap.Add(map.ClusterId, new List<ClusterToMassTagMap>());
                        }
                        clusterMap[map.ClusterId].Add(map);
                    }
                }

                var tags = new Dictionary<string, MassTagLight>();
                if (massTags.Count > 0)
                {
                    foreach (var tag in massTags)
                    {
                        var key = tag.ConformationId + "-" + tag.Id;
                        if (!tags.ContainsKey(key))
                        {
                            tags.Add(key, tag);
                        }
                    }
                }

                Logger.PrintMessage("Exporting Data");
                foreach (var writer in m_config.ClusterExporters)
                {
                    Logger.PrintMessage("Exporting in " + writer + " format to " + m_config.AnalysisPath);
                    writer.WriteClusters(clusters,
                        clusterMap,
                        datasets,
                        tags);
                }
            }
        }
Beispiel #12
0
        /// <summary>
        ///     Loads factors from file or other.
        /// </summary>
        private void ConstructFactorInformation(InputAnalysisInfo analysisSetupInformation,
            ObservableCollection<DatasetInformation> datasets, FeatureDataAccessProviders providers)
        {
            var mage = new MAGEFactorAdapter();

            if (analysisSetupInformation.FactorFile == null)
            {
                Logger.PrintMessage("Loading Factor Information from DMS");
                mage.LoadFactorsFromDMS(datasets, providers);
            }
            else
            {
                Logger.PrintMessage("Loading Factor Information from file: " + analysisSetupInformation.FactorFile);
                mage.LoadFactorsFromFile(analysisSetupInformation.FactorFile, datasets, providers);
            }
        }
Beispiel #13
0
        /// <summary>
        ///     Creates the analysis processor and synchronizs the events.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="providers"></param>
        /// <returns></returns>
        private MultiAlignAnalysisProcessor ConstructAnalysisProcessor(AlgorithmBuilder builder,
            FeatureDataAccessProviders providers)
        {
            var processor = new MultiAlignAnalysisProcessor();
            processor.AnalysisStarted += processor_AnalysisStarted;
            processor.AnalysisError += processor_AnalysisError;
            processor.FeaturesAligned += processor_FeaturesAligned;
            processor.FeaturesLoaded += processor_FeaturesLoaded;
            processor.MassTagsLoaded += processor_MassTagsLoaded;
            processor.FeaturesClustered += processor_FeaturesClustered;
            processor.FeaturesPeakMatched += processor_FeaturesPeakMatched;
            processor.AnalysisComplete += processor_AnalysisComplete;
            processor.Progress += processor_Progress;
            processor.BaselineFeaturesLoaded += processor_BaselineFeaturesLoaded;
            m_config.Analysis.DataProviders = providers;
            processor.AlgorithmProviders = builder.GetAlgorithmProvider(m_config.Analysis.Options);

            return processor;
        }