Ejemplo n.º 1
0
        /// <summary>
        ///     Loads a mass tag database.
        /// </summary>
        /// <param name="databaseDefinition"></param>
        /// <param name="options">Loading options.</param>
        /// <returns>The mass tag database.</returns>
        public static IMtdbLoader Create(InputDatabase databaseDefinition, MassTagDatabaseOptions options)
        {
            IMtdbLoader loader = null;

            switch (databaseDefinition.DatabaseFormat)
            {
                case MassTagDatabaseFormat.SkipAlignment:
                    loader = new DriftTimeTextFileDatabaseLoader(databaseDefinition.LocalPath);
                    break;
                case MassTagDatabaseFormat.MassTagSystemSql:
                    loader = new MtsMassTagDatabaseLoader(databaseDefinition.DatabaseName,
                        databaseDefinition.DatabaseServer, options);
                    break;
                case MassTagDatabaseFormat.Sqlite:
                    loader = new SQLiteMassTagDatabaseLoader(databaseDefinition.LocalPath, options);
                    break;
                case MassTagDatabaseFormat.MtdbCreator:
                    loader = new MtdbCreatorDatabaseLoader(databaseDefinition.LocalPath);
                    break;
                case MassTagDatabaseFormat.DelimitedTextFile:
                    loader = new MetaSampleDatbaseLoader(databaseDefinition.LocalPath, options);
                    break;
            }
            return loader;
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="databaseName">Database name.</param>
 /// <param name="server">Server the database is hosted on.</param>
 /// <param name="options"></param>
 public MtsMassTagDatabaseLoader(string databaseName, string server, MassTagDatabaseOptions options)
 {
     UserName     = DEFAULT_USERNAME;
     Password     = DEFAULT_PASSWORD;
     DatabaseName = databaseName;
     ServerName   = server;
     Options      = options;
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="databaseName">Database name.</param>
 /// <param name="server">Server the database is hosted on.</param>
 /// <param name="options"></param>
 public MtsMassTagDatabaseLoader(string databaseName, string server, MassTagDatabaseOptions options)
 {
     UserName = DEFAULT_USERNAME;
     Password = DEFAULT_PASSWORD;
     DatabaseName    = databaseName;
     ServerName      = server;
     Options         = options;
 }
Ejemplo n.º 4
0
        public void Filter(MassTagDatabaseOptions options)
        {
            var massTags = MassTags.Where(t => t.Net >= options.MinimumNet)
                           .Where(t => t.Net <= options.MaximumNet)
                           .Where(t => t.MassMonoisotopic >= options.MinimumMass)
                           .Where(t => t.MassMonoisotopic <= options.MaximumMass).ToList();

            this.MassTags.Clear();
            this.AddMassTagsAndProteins(massTags, this.Proteins);
        }
Ejemplo n.º 5
0
 /// <summary>
 ///     Loads a mass tag database.
 /// </summary>
 /// <param name="databaseDefinition"></param>
 /// <param name="options">Loading options.</param>
 /// <returns>The mass tag database.</returns>
 public static MassTagDatabase LoadMassTagDatabase(InputDatabase databaseDefinition,
     MassTagDatabaseOptions options)
 {
     var loader = Create(databaseDefinition, options);
     if (loader == null)
     {
         throw new NullReferenceException("The type of mass tag database format is not supported: " +
                                          databaseDefinition.DatabaseFormat);
     }
     return loader.LoadDatabase();
 }
Ejemplo n.º 6
0
        /// <summary>
        ///     Loads a mass tag database.
        /// </summary>
        /// <param name="databaseDefinition"></param>
        /// <param name="options">Loading options.</param>
        /// <returns>The mass tag database.</returns>
        public static MassTagDatabase LoadMassTagDatabase(InputDatabase databaseDefinition,
                                                          MassTagDatabaseOptions options)
        {
            var loader = Create(databaseDefinition, options);

            if (loader == null)
            {
                throw new NullReferenceException("The type of mass tag database format is not supported: " +
                                                 databaseDefinition.DatabaseFormat);
            }
            return(loader.LoadDatabase());
        }
Ejemplo n.º 7
0
        public void TestLocalMtdbLoader(string path, MassTagDatabaseFormat format)
        {
            var input = new InputDatabase
            {
                DatabaseFormat  = format,
                LocalPath       = path
            };

            var options  = new MassTagDatabaseOptions();
            var loader   = MtdbLoaderFactory.Create(input, options);
            Assert.NotNull(loader);

            var database = loader.LoadDatabase();
            Assert.NotNull(database);
            Assert.Greater(database.MassTags.Count, 100);
        }
Ejemplo n.º 8
0
        public void TestLocalMtdbLoader(string path, MassTagDatabaseFormat format, int expectedNumberOfTargets)
        {
            var input = new InputDatabase
            {
                DatabaseFormat  = format,
                LocalPath       = path
            };

            var options = new MassTagDatabaseOptions();
            var loader = MtdbLoaderFactory.Create(input, options);
            Assert.NotNull(loader);

            var database = loader.LoadDatabase();
            Assert.NotNull(database);
            Assert.AreEqual(database.MassTags.Count, expectedNumberOfTargets);
        }
Ejemplo n.º 9
0
        public void TestLocalMtdbLoader(string path, MassTagDatabaseFormat format, int expectedNumberOfTargets)
        {
            var input = new InputDatabase
            {
                DatabaseFormat = format,
                LocalPath      = path
            };

            var options = new MassTagDatabaseOptions();
            var loader  = MtdbLoaderFactory.Create(input, options);

            Assert.NotNull(loader);

            var database = loader.LoadDatabase();

            Assert.NotNull(database);
            Assert.AreEqual(database.MassTags.Count, expectedNumberOfTargets);
        }
Ejemplo n.º 10
0
        public void TestLocalMtdbLoader(string path, MassTagDatabaseFormat format)
        {
            var input = new InputDatabase
            {
                DatabaseFormat = format,
                LocalPath      = path
            };

            var options = new MassTagDatabaseOptions();
            var loader  = MtdbLoaderFactory.Create(input, options);

            Assert.NotNull(loader);

            var database = loader.LoadDatabase();

            Assert.NotNull(database);
            Assert.Greater(database.MassTags.Count, 100);
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     Loads a mass tag database.
        /// </summary>
        /// <param name="databaseDefinition"></param>
        /// <param name="options">Loading options.</param>
        /// <returns>The mass tag database.</returns>
        public static IMtdbLoader Create(InputDatabase databaseDefinition, MassTagDatabaseOptions options)
        {
            IMtdbLoader loader = null;

            switch (databaseDefinition.DatabaseFormat)
            {
            case MassTagDatabaseFormat.SkipAlignment:
                loader = new DriftTimeTextFileDatabaseLoader(databaseDefinition.LocalPath);
                break;

            case MassTagDatabaseFormat.MassTagSystemSql:
                loader = new MtsMassTagDatabaseLoader(databaseDefinition.DatabaseName,
                                                      databaseDefinition.DatabaseServer, options);
                break;

            case MassTagDatabaseFormat.Sqlite:
                loader = new SQLiteMassTagDatabaseLoader(databaseDefinition.LocalPath, options);
                break;

            case MassTagDatabaseFormat.MtdbCreator:
                loader = new MtdbCreatorDatabaseLoader(databaseDefinition.LocalPath);
                break;

            case MassTagDatabaseFormat.DelimitedTextFile:
                loader = new MetaSampleDatbaseLoader(databaseDefinition.LocalPath, options);
                break;

            case MassTagDatabaseFormat.LiquidResultsFile:
                loader = new LiquidResultsFileLoader(databaseDefinition.LocalPath);
                break;

            case MassTagDatabaseFormat.GenericTsvFile:
                loader = new MtdbFromGenericTsvReader(databaseDefinition.LocalPath);
                break;
            }
            return(loader);
        }
Ejemplo n.º 12
0
 /// <summary>
 ///     Sqlite database loader constructor.
 /// </summary>
 public SQLiteMassTagDatabaseLoader(string databasePath, MassTagDatabaseOptions options)
 {
     DatabasePath = databasePath;
     Options      = options;
 }
Ejemplo n.º 13
0
 public MetaSampleDatbaseLoader(string path, MassTagDatabaseOptions options)
 {
     Path      = path;
     m_options = options;
 }
Ejemplo n.º 14
0
 /// <summary>
 ///     Sqlite database loader constructor.
 /// </summary>
 public ApeMassTagDatabaseLoader(string databasePath, MassTagDatabaseOptions options)
 {
     DatabasePath = databasePath;
     Options = options;
 }
Ejemplo n.º 15
0
 public MassTagDatabaseOptionsViewModel(MassTagDatabaseOptions options)
 {
     m_options = options;
 }
Ejemplo n.º 16
0
 public MetaSampleDatbaseLoader(string path, MassTagDatabaseOptions options)
 {
     Path = path;
     m_options = options;
 }
Ejemplo n.º 17
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static int Main(string[] args)
        {
            var handle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

            SetConsoleMode(handle, ENABLE_EXTENDED_FLAGS);

            var clusterIdMap = new Dictionary <int, UMCClusterLight>();

            try
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("MultiAlignSTACRunner crosstabDirectory databasePath outputName");
                    Console.WriteLine("\tThe cross-tab file will be named similar to the database path");
                    return(1);
                }

                // Setup the analysis processing
                Logger.PrintMessage("Find all datasets", true);
                var directoryPath = args[0].Replace("\r", "").Replace("\n", "");
                var databasePath  = args[1].Replace("\r", "").Replace("\n", "");
                var name          = args[2].Replace("\r", "").Replace("\n", "");
                var files         = Directory.GetFiles(directoryPath, "*.csv");

                Logger.PrintMessage("Creating Log File");
                var loggerPath = AnalysisPathUtils.BuildLogPath(Path.GetDirectoryName(name), Path.GetFileNameWithoutExtension(name));
                Logger.LogPath = loggerPath;
                Logger.PrintMessage("Saving Log Data to: " + loggerPath);


                Logger.PrintMessage(string.Format("Creating STAC"), true);

                // Hardcode bad, but per discussions with OHSU
                var stac = new STACAdapter <UMCClusterLight>
                {
                    Options = new FeatureMatcherParameters
                    {
                        UserTolerances =
                        {
                            MassTolerancePPM   =   25,
                            NETTolerance       = .035,
                            DriftTimeTolerance = 3
                        },
                        UseDriftTime = true
                    }
                };


                var clusterFilteringOptions = new FilteringOptions();

                WriteOptionsToLogFile(clusterFilteringOptions);
                WriteOptionsToLogFile(stac.Options);


                // Read the cluster data
                var allClusters = new List <UMCClusterLight>();
                var clusterId   = 0;
                foreach (var file in files)
                {
                    var filename = Path.GetFileName(file);
                    Logger.PrintMessage(string.Format("Reading {0}", filename));
                    const string chargeString = "charge";

                    if (filename == null)
                    {
                        continue;
                    }

                    if (!filename.Contains(chargeString))
                    {
                        continue;
                    }

                    // Read each file.
                    var start = DateTime.Now;

                    var xname = filename.Replace("_", "");
                    // ReSharper disable once StringIndexOfIsCultureSpecific.1
                    var indexOfChargeString = xname.IndexOf(chargeString);
                    var charge = Convert.ToInt32(xname.Substring(indexOfChargeString + chargeString.Length, 1));

                    var clusters = ReadClusters(file, clusterFilteringOptions);
                    var end      = DateTime.Now;
                    Logger.PrintMessage(string.Format("\tReading Took {0:.00} seconds", end.Subtract(start).TotalSeconds));

                    foreach (var cluster in clusters)
                    {
                        clusterIdMap.Add(clusterId, cluster);
                        cluster.Id          = clusterId++;
                        cluster.ChargeState = charge;
                    }

                    allClusters.AddRange(clusters);
                }


                // Load the database
                Logger.PrintMessage(string.Format("Loading Mass Tag Database: {0}", Path.GetFileNameWithoutExtension(databasePath)));
                var options            = new MassTagDatabaseOptions();
                var databaseDefinition = new InputDatabase
                {
                    DatabaseFormat = MassTagDatabaseFormat.Sqlite,
                    LocalPath      = databasePath
                };
                var database = MtdbLoaderFactory.LoadMassTagDatabase(databaseDefinition, options);

                // Run stac
                try
                {
                    Logger.PrintMessage("Matching clusters to peptides in mass tag database.");
                    var matches = stac.PerformPeakMatching(allClusters, database);

                    Logger.PrintMessage(string.Format("Writing Results To {0}", name));
                    var duplicateMatches = new Dictionary <int, Dictionary <int, FeatureMatchLight <UMCClusterLight, MassTagLight> > >();

                    foreach (var match in matches)
                    {
                        if (!duplicateMatches.ContainsKey(match.Observed.Id))
                        {
                            duplicateMatches.Add(match.Observed.Id, new Dictionary <int, FeatureMatchLight <UMCClusterLight, MassTagLight> >());
                        }

                        if (!duplicateMatches[match.Observed.Id].ContainsKey(match.Target.Id))
                        {
                            duplicateMatches[match.Observed.Id].Add(match.Target.Id, match);
                        }
                    }
                    WriteClusterData(name, duplicateMatches, clusterIdMap);


                    Logger.PrintMessage("ANALYSIS SUCCESS");
                    return(0);
                }
                catch (Exception ex)
                {
                    Logger.PrintMessage("Unhandled Error: " + ex.Message);
                    var innerEx = ex.InnerException;
                    while (innerEx != null)
                    {
                        Logger.PrintMessage("Inner Exception: " + innerEx.Message);
                        innerEx = innerEx.InnerException;
                    }
                    Logger.PrintMessage("Stack: " + ex.StackTrace);
                    Logger.PrintMessage("");
                    Logger.PrintMessage("ANALYSIS FAILED");
                    return(1);
                }
            }
            catch (Exception ex)
            {
                Logger.PrintMessage("Unhandled Error: " + ex.Message, true);
                var innerEx = ex.InnerException;
                while (innerEx != null)
                {
                    Logger.PrintMessage("Inner Exception: " + innerEx.Message);
                    innerEx = innerEx.InnerException;
                }
                Logger.PrintMessage("Stack: " + ex.StackTrace, true);
                Logger.PrintMessage("");
                Logger.PrintMessage("ANALYSIS FAILED");
                return(1);
            }
        }