Exemple #1
0
        /// <summary>
        /// Initiates a dynamic connection with a Thermo .raw file. Data can be "streamed" instead of loaded all at once. Use
        /// GetOneBasedScanFromDynamicConnection to get data from a particular scan. Use CloseDynamicConnection to close the
        /// dynamic connection after all desired data has been retrieved from the dynamic connection.
        /// </summary>
        private void InitiateDynamicConnection(string filePath)
        {
            Loaders.LoadElements();

            if (dynamicConnection != null)
            {
                dynamicConnection.Dispose();
            }

            dynamicConnection = RawFileReaderAdapter.FileFactory(filePath);

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException();
            }

            if (!dynamicConnection.IsOpen)
            {
                throw new MzLibException("Unable to access RAW file!");
            }

            if (dynamicConnection.IsError)
            {
                throw new MzLibException("Error opening RAW file!");
            }

            if (dynamicConnection.InAcquisition)
            {
                throw new MzLibException("RAW file still being acquired!");
            }

            dynamicConnection.SelectInstrument(Device.MS, 1);
            GetMsOrdersByScanInDynamicConnection();
        }
Exemple #2
0
        public List <Modification> get_mods(string current_directory)
        {
            var psiModDeserialized = Loaders.LoadPsiMod(Path.Combine(current_directory, "Mods", "PSI-MOD.obo.xml"));
            Dictionary <string, int> formalChargesDictionary = Loaders.GetFormalChargesDictionary(psiModDeserialized);

            Loaders.LoadElements();
            List <Modification> all_known_modifications = new List <Modification>();

            foreach (string filename in Directory.GetFiles(Path.Combine(current_directory, "Mods")))
            {
                List <Modification> new_mods = !filename.EndsWith("variable.txt") || Sweet.lollipop.methionine_oxidation ?
                                               PtmListLoader.ReadModsFromFile(filename, formalChargesDictionary, out List <(Modification, string)> filteredModificationsWithWarnings).ToList() :
                                               new List <Modification>(); // Empty variable modifications if not selected
                if (filename.EndsWith("variable.txt"))
                {
                    variableModifications = new_mods;
                }
                if (filename.EndsWith("UniprotGlycanDatabase.txt"))
                {
                    glycan_mods = new_mods;
                    continue;
                }

                all_known_modifications.AddRange(new_mods);
            }
            all_known_modifications = new HashSet <Modification>(all_known_modifications).ToList();
            uniprotModifications    = make_modification_dictionary(all_known_modifications);
            all_mods_with_mass      = uniprotModifications.SelectMany(kv => kv.Value).Concat(variableModifications).ToList();
            return(all_known_modifications);
        }
        public void Modification_read_write_into_proteinDb()
        {
            Loaders.LoadElements(Path.Combine(TestContext.CurrentContext.TestDirectory, "elements2.dat"));
            var sampleModList = PtmListLoader.ReadModsFromFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "z.txt")).ToList();

            Assert.AreEqual(1, sampleModList.OfType <ModificationWithMass>().Count());
            Protein protein = new Protein("MCSSSSSSSSSS", "accession", "organism", new List <Tuple <string, string> >(), new Dictionary <int, List <Modification> > {
                { 2, sampleModList.OfType <Modification>().ToList() }
            }, null, "name", "full_name", false, false, new List <DatabaseReference>(), new List <SequenceVariation>(), new List <DisulfideBond>());

            Assert.AreEqual(1, protein.OneBasedPossibleLocalizedModifications[2].OfType <ModificationWithMass>().Count());
            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), new List <Protein> {
                protein
            }, Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins.xml"));
            List <Protein> new_proteins = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins.xml"), true, DecoyType.None, new List <Modification>(), false, new List <string>(), out Dictionary <string, Modification> um);

            Assert.AreEqual(1, new_proteins.Count);
            Assert.AreEqual(1, new_proteins[0].OneBasedPossibleLocalizedModifications.Count);
            Assert.AreEqual(1, new_proteins[0].OneBasedPossibleLocalizedModifications.SelectMany(kv => kv.Value).Count());
            Assert.AreEqual("Type", new_proteins[0].OneBasedPossibleLocalizedModifications.SelectMany(kv => kv.Value).OfType <ModificationWithMass>().First().modificationType);
            Assert.AreEqual("Palmitoylation of C", new_proteins[0].OneBasedPossibleLocalizedModifications[2][0].id);
            Assert.AreEqual(1, new_proteins[0].OneBasedPossibleLocalizedModifications[2].OfType <ModificationWithMass>().Count());

            // Check that Modifications were saved after last load
            Assert.AreEqual(1, ProteinDbLoader.GetPtmListFromProteinXml(Path.Combine(TestContext.CurrentContext.TestDirectory, @"test_modifications_with_proteins.xml")).Count);
            Assert.True(ProteinDbLoader.GetPtmListFromProteinXml(Path.Combine(TestContext.CurrentContext.TestDirectory, @"test_modifications_with_proteins.xml"))[0] == new_proteins[0].OneBasedPossibleLocalizedModifications.SelectMany(kv => kv.Value).First());

            //But that we can still read modifications from other protein XMLs that exist
            Assert.AreEqual(0, ProteinDbLoader.GetPtmListFromProteinXml(Path.Combine(TestContext.CurrentContext.TestDirectory, "xml.xml")).Count);
        }
        public static Dictionary <string, List <Modification> > read_mods()
        {
            Loaders.LoadElements(Path.Combine(TestContext.CurrentContext.TestDirectory, "elements.dat"));
            List <ModificationWithLocation> all_modifications = SaveState.lollipop.get_files(SaveState.lollipop.input_files, Purpose.PtmList).SelectMany(file => PtmListLoader.ReadModsFromFile(file.complete_path)).ToList();

            return(SaveState.lollipop.theoretical_database.make_modification_dictionary(all_modifications));
        }
Exemple #5
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string dir = System.IO.Directory.GetCurrentDirectory();

            Loaders.LoadElements(dir + @"\elements.dat");
            listView.ItemsSource = DeconvolutedFeatures;

            /*
             * REngine R;
             * REngine.SetEnvironmentVariables();
             * R = REngine.GetInstance();
             * R.Initialize();
             * R.Evaluate("source(\"https://bioconductor.org/biocLite.R\")");
             * try
             * {
             *  R.Evaluate("biocLite(\"Prostar\")");
             * }
             * catch(Exception ex)
             * {
             *
             * }
             * R.Evaluate("");
             * R.Dispose();
             */
        }
        public void DoNotWriteSameModTwiceButWriteInHeaderSinceDifferent()
        {
            Loaders.LoadElements(Path.Combine(TestContext.CurrentContext.TestDirectory, "elements2.dat"));
            var     sampleModList = PtmListLoader.ReadModsFromFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "z.txt")).ToList();
            Protein protein       = new Protein("MCSSSSSSSSSS", "accession", "organism", new List <Tuple <string, string> >(), new Dictionary <int, List <Modification> > {
                { 2, sampleModList.OfType <Modification>().ToList() }
            }, null, "name", "full_name", false, false, new List <DatabaseReference>(), new List <SequenceVariation>(), new List <DisulfideBond>());

            Assert.AreEqual(1, protein.OneBasedPossibleLocalizedModifications[2].OfType <ModificationWithMass>().Count());

            Dictionary <string, HashSet <Tuple <int, Modification> > > dictWithThisMod = new Dictionary <string, HashSet <Tuple <int, Modification> > >();

            HashSet <Tuple <int, Modification> > value = new HashSet <Tuple <int, Modification> >();

            ModificationMotif.TryGetMotif("C", out ModificationMotif motif);
            ModificationWithMass newMod = new ModificationWithMass("Palmitoylation of C", "mt", motif, TerminusLocalization.Any, double.NaN, null, null);

            Assert.AreNotEqual(newMod, sampleModList.First());

            value.Add(new Tuple <int, Modification>(2, newMod));

            dictWithThisMod.Add("accession", value);

            var newModResEntries = ProteinDbWriter.WriteXmlDatabase(dictWithThisMod, new List <Protein> {
                protein
            }, Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins2.xml"));

            Assert.AreEqual(0, newModResEntries.Count);
            List <Protein> new_proteins = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins2.xml"), true, DecoyType.None, new List <Modification>(), false, new List <string>(), out Dictionary <string, Modification> um);

            Assert.AreEqual(1, new_proteins.Count);
            Assert.AreEqual(1, new_proteins[0].OneBasedPossibleLocalizedModifications.Count);
            Assert.AreEqual(2, new_proteins[0].OneBasedPossibleLocalizedModifications.SelectMany(kv => kv.Value).Count());
        }
        /// <summary>
        /// Gets UniProt ptmlist
        /// </summary>
        /// <param name="spritzDirectory"></param>
        /// <returns></returns>
        public static List <Modification> GetUniProtMods(string spritzDirectory)
        {
            Loaders.LoadElements();
            var psiModDeserialized = Loaders.LoadPsiMod(Path.Combine(spritzDirectory, "PSI-MOD.obo.xml"));

            return(Loaders.LoadUniprot(Path.Combine(spritzDirectory, "ptmlist.txt"), Loaders.GetFormalChargesDictionary(psiModDeserialized)).ToList());
        }
Exemple #8
0
 public void FilesLoading()
 {
     Loaders.LoadElements(Path.Combine(TestContext.CurrentContext.TestDirectory, "elements.dat"));
     Loaders.LoadUnimod(Path.Combine(TestContext.CurrentContext.TestDirectory, "unimod_tables.xml"));
     Loaders.LoadPsiMod(Path.Combine(TestContext.CurrentContext.TestDirectory, "PSI-MOD.obo.xml"));
     Loaders.LoadUniprot(Path.Combine(TestContext.CurrentContext.TestDirectory, "ptmlist.txt"));
 }
Exemple #9
0
        public void Setup()
        {
            Loaders.LoadElements();

            Assert.That(Thread.CurrentThread.CurrentCulture == CultureInfo.InvariantCulture);
            Assert.That(Thread.CurrentThread.CurrentUICulture == CultureInfo.InvariantCulture);
        }
        public static void SetUpGlobalVariables()
        {
            Loaders.LoadElements();
            AcceptedDatabaseFormats = new List <string> {
                ".fasta", ".fa", ".xml", ".msp"
            };
            AcceptedSpectraFormats = new List <string> {
                ".raw", ".mzml", ".mgf"
            };
            AnalyteType                = "Peptide";
            _InvalidAminoAcids         = new char[] { 'X', 'B', 'J', 'Z', ':', '|', ';', '[', ']', '{', '}', '(', ')', '+', '-' };
            ExperimentalDesignFileName = "ExperimentalDesign.tsv";
            SeparationTypes            = new List <string> {
                { "HPLC" }, { "CZE" }
            };

            SetMetaMorpheusVersion();
            SetUpDataDirectory();
            LoadCrosslinkers();
            LoadModifications();
            LoadGlycans();
            LoadCustomAminoAcids();
            SetUpGlobalSettings();
            LoadDissociationTypes();
        }
        public static Dictionary <string, List <Modification> > read_mods()
        {
            Loaders.LoadElements();
            List <Modification> all_modifications = Sweet.lollipop.get_files(Sweet.lollipop.input_files, Purpose.PtmList).SelectMany(file => PtmListLoader.ReadModsFromFile(file.complete_path, out List <(Modification, string)> filteredModificationsWithWarnings)).ToList();

            return(Sweet.lollipop.theoretical_database.make_modification_dictionary(all_modifications));
        }
Exemple #12
0
        public void load_save_unlocalized()
        {
            Loaders.LoadElements();
            TheoreticalProteoformDatabase tpd  = new TheoreticalProteoformDatabase();
            List <Modification>           mods = PtmListLoader.ReadModsFromFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "Mods", "ptmlist.txt"), out List <(Modification, string)> filteredModificationsWithWarnings).ToList();

            foreach (Modification m in mods)
            {
                if (!Sweet.lollipop.modification_ranks.TryGetValue(Math.Round((double)m.MonoisotopicMass, 5), out int x))
                {
                    Sweet.lollipop.modification_ranks.Add(Math.Round((double)m.MonoisotopicMass, 5), -1);
                }
            }
            tpd.unlocalized_lookup = tpd.make_unlocalized_lookup(mods);
            tpd.load_unlocalized_names(Path.Combine(TestContext.CurrentContext.TestDirectory, "Mods", "stored_mods.modnames"));
            tpd.save_unlocalized_names(Path.Combine(TestContext.CurrentContext.TestDirectory, "Mods", "fake_stored_mods.modnames"));
            Modification firstAcetyl = mods.FirstOrDefault(x => x.OriginalId.StartsWith("N-acetyl"));

            Assert.AreNotEqual(firstAcetyl.OriginalId, tpd.unlocalized_lookup[firstAcetyl].id);

            //Test amending
            mods.AddRange(PtmListLoader.ReadModsFromFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "Mods", "intact_mods.txt"), out filteredModificationsWithWarnings).OfType <Modification>());
            Sweet.lollipop.modification_ranks = mods.DistinctBy(m => m.MonoisotopicMass).ToDictionary(m => Math.Round((double)m.MonoisotopicMass, 5), m => - 1);
            tpd.unlocalized_lookup            = tpd.make_unlocalized_lookup(mods.OfType <Modification>());
            tpd.amend_unlocalized_names(Path.Combine(TestContext.CurrentContext.TestDirectory, "Mods", "fake_stored_mods.modnames"));
        }
Exemple #13
0
        /// <summary>
        /// Requires at least one ProteinDatabase input file and one input file listing modifications.
        /// </summary>
        /// <returns></returns>
        public bool ready_to_make_database(string current_directory)
        {
            Loaders.LoadElements();
            List <InputFile> proteinDbs = Sweet.lollipop.get_files(Sweet.lollipop.input_files, Purpose.ProteinDatabase).ToList();

            return(proteinDbs.Count > 0 &&
                   (proteinDbs.Any(file => file.extension == ".xml" && ProteinDbLoader.GetPtmListFromProteinXml(file.complete_path).Count > 0) ||
                    Sweet.lollipop.get_files(Sweet.lollipop.input_files, Purpose.PtmList).Count() > 0));
        }
        /// <summary>
        /// Requires at least one ProteinDatabase input file and one input file listing modifications.
        /// </summary>
        /// <returns></returns>
        public bool ready_to_make_database(string current_directory)
        {
            Loaders.LoadElements(Path.Combine(current_directory, "elements.dat"));
            List <InputFile> proteinDbs = SaveState.lollipop.get_files(SaveState.lollipop.input_files, Purpose.ProteinDatabase).ToList();

            return(proteinDbs.Count > 0 &&
                   (proteinDbs.Any(file => ProteinDbLoader.GetPtmListFromProteinXml(file.complete_path).Count > 0) ||
                    SaveState.lollipop.get_files(SaveState.lollipop.input_files, Purpose.PtmList).Count() > 0));
        }
Exemple #15
0
        public static void TestPeakSplittingRight()
        {
            string fileToWrite = "myMzml.mzML";
            string peptide     = "PEPTIDE";
            double intensity   = 1e6;

            Loaders.LoadElements(Path.Combine(TestContext.CurrentContext.TestDirectory, @"elements.dat"));

            // generate mzml file

            // 1 MS1 scan per peptide
            MsDataScan[] scans = new MsDataScan[10];
            double[]     intensityMultipliers = { 1, 3, 5, 10, 5, 3, 1, 1, 3, 1 };

            for (int s = 0; s < scans.Length; s++)
            {
                ChemicalFormula      cf          = new Proteomics.AminoAcidPolymer.Peptide(peptide).GetChemicalFormula();
                IsotopicDistribution dist        = IsotopicDistribution.GetDistribution(cf, 0.125, 1e-8);
                double[]             mz          = dist.Masses.Select(v => v.ToMz(1)).ToArray();
                double[]             intensities = dist.Intensities.Select(v => v * intensity * intensityMultipliers[s]).ToArray();

                // add the scan
                scans[s] = new MsDataScan(massSpectrum: new MzSpectrum(mz, intensities, false), oneBasedScanNumber: s + 1, msnOrder: 1, isCentroid: true,
                                          polarity: Polarity.Positive, retentionTime: 1.0 + s / 10.0, scanWindowRange: new MzRange(400, 1600), scanFilter: "f",
                                          mzAnalyzer: MZAnalyzerType.Orbitrap, totalIonCurrent: intensities.Sum(), injectionTime: 1.0, noiseData: null, nativeId: "scan=" + (s + 1));
            }

            // write the .mzML
            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(new FakeMsDataFile(scans),
                                                                          Path.Combine(TestContext.CurrentContext.TestDirectory, fileToWrite), false);

            // set up spectra file info
            SpectraFileInfo file1 = new SpectraFileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, fileToWrite), "", 0, 0, 0);

            // create some PSMs
            var pg = new ProteinGroup("MyProtein", "gene", "org");

            Identification id1 = new Identification(file1, peptide, peptide,
                                                    new Proteomics.AminoAcidPolymer.Peptide(peptide).MonoisotopicMass, 1.3 + 0.001, 1, new List <ProteinGroup> {
                pg
            });

            // create the FlashLFQ engine
            FlashLFQEngine engine = new FlashLFQEngine(new List <Identification> {
                id1
            });

            // run the engine
            var results = engine.Run();
            ChromatographicPeak peak = results.Peaks.First().Value.First();

            Assert.That(peak.Apex.RetentionTime == 1.3);
            Assert.That(peak.SplitRT == 1.6);
            Assert.That(!peak.IsotopicEnvelopes.Any(p => p.RetentionTime > 1.6));
            Assert.That(peak.IsotopicEnvelopes.Count == 6);
        }
Exemple #16
0
        public static void Setup()
        {
            Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
            Loaders.LoadElements(Path.Combine(TestContext.CurrentContext.TestDirectory, elementsLocation));

            MetaMorpheusEngine.WarnHandler += WarnStatusHandler;
            MetaMorpheusTask.WarnHandler   += WarnStatusHandler;

            EverythingRunnerEngine.FinishedAllTasksEngineHandler += SuccessfullyFinishedAllTasks;
        }
Exemple #17
0
        public void TestUpdateElements()
        {
            var elementLocation = Path.Combine(TestContext.CurrentContext.TestDirectory, "lal.dat");

            try
            {
                Loaders.LoadElements(elementLocation);
            }
            catch { }
            Loaders.UpdateElements(elementLocation);
            Assert.Throws <ArgumentException>(() => { Loaders.LoadElements(elementLocation); });
            Assert.AreEqual(ValidationResult.PassedAbundanceValidation, PeriodicTable.ValidateAbundances(1e-15).ThisValidationResult);
            Assert.AreEqual(ValidationResult.PassedAverageMassValidation, PeriodicTable.ValidateAverageMasses(1e-2).ThisValidationResult);
        }
Exemple #18
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            //Quick way to check parameters
            //var apath = "G:\\Parameters\\Parameters_Topdown_ChargeExclusion_Mesh.toml";
            //Parameters aparameters = AddParametersFromFile(apath);

            //Initiate Element
            Loaders.LoadElements();
            //Loading avagine model for Deconvolution
            var test = new MzSpectrumXY(new double[] { 1 }, new double[] { 1 }, true);

            //Load parameters
            string path = "";

            if (args.Count() > 0)
            {
                path = args[0];
            }

            Parameters parameters = AddParametersFromFile(path);

            //Generate Static BoxCarScan Properties.
            BoxCarScan.BuildStaticBoxString(parameters);

            //Start the task
            if (parameters.GeneralSetting.TestMod)
            {
                Console.WriteLine("--------------In Test Mod--------------");
                new CustomScansTandemByArrival(parameters).DoJob(5 * 60000);
            }
            else
            {
                Console.WriteLine("--------------In Gather Mod--------------");
                var dataReceiver = new DataReceiver(parameters);
                dataReceiver.InstrumentAccess = Connection.GetFirstInstrument();
                dataReceiver.ScanContainer    = dataReceiver.InstrumentAccess.GetMsScanContainer(0);

                dataReceiver.DetectStartSignal();
                dataReceiver.DoJob();

                dataReceiver.ScanContainer    = null;
                dataReceiver.InstrumentAccess = null;
            }

            Console.WriteLine("Task Finished...");
        }
        public void FilesLoading()
        {
            Loaders.LoadElements(Path.Combine(TestContext.CurrentContext.TestDirectory, "elements2.dat"));

            var unimodMods = Loaders.LoadUnimod(Path.Combine(TestContext.CurrentContext.TestDirectory, "unimod_tables2.xml")).ToList();

            Assert.AreEqual(2, (unimodMods.First(b => b.id.Equals("HexNAc(2) on N at Any")) as ModificationWithMass).neutralLosses.Count);
            var psiModDeserialized = Loaders.LoadPsiMod(Path.Combine(TestContext.CurrentContext.TestDirectory, "PSI-MOD.obo2.xml"));

            // N6,N6,N6-trimethyllysine
            var trimethylLysine = psiModDeserialized.Items.OfType <UsefulProteomicsDatabases.Generated.oboTerm>().First(b => b.id.Equals("MOD:00083"));

            Assert.AreEqual("1+", trimethylLysine.xref_analog.First(b => b.dbname.Equals("FormalCharge")).name);

            // Phosphoserine
            Assert.IsFalse(psiModDeserialized.Items.OfType <UsefulProteomicsDatabases.Generated.oboTerm>().First(b => b.id.Equals("MOD:00046")).xref_analog.Any(b => b.dbname.Equals("FormalCharge")));

            Dictionary <string, int> formalChargesDictionary = Loaders.GetFormalChargesDictionary(psiModDeserialized);

            var uniprotPtms = Loaders.LoadUniprot(Path.Combine(TestContext.CurrentContext.TestDirectory, "ptmlist2.txt"), formalChargesDictionary).ToList();

            using (StreamWriter w = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "test.txt")))
            {
                foreach (var nice in uniprotPtms)
                {
                    w.WriteLine(nice.ToString());
                    w.WriteLine("//");
                }
                foreach (var nice in unimodMods)
                {
                    w.WriteLine(nice.ToString());
                    w.WriteLine("//");
                }
            }

            var sampleModList = PtmListLoader.ReadModsFromFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "test.txt")).ToList();

            string stringRepresentation = "ID   (3R)-3-hydroxyarginine\r\nMT   UniProt\r\nPP   Anywhere.\r\nDR   RESID; AA0601\r\nDR   PSI-MOD; MOD:01956\r\nDR   UniProt; PTM-0476\r\nTG   R\r\nMM   15.994915\r\nCF   O";

            Assert.AreEqual(stringRepresentation, sampleModList.First().ToString());

            // N,N,N-trimethylalanine
            var thisMod = sampleModList.First(b => b.id.Equals(@"N,N,N-trimethylalanine")) as ModificationWithMass;

            Assert.IsTrue(thisMod.monoisotopicMass > 42);
            Assert.IsTrue(thisMod.monoisotopicMass < 43);
        }
Exemple #20
0
        protected override void InitiateDynamicConnection()
        {
            if (!File.Exists(FilePath))
            {
                throw new FileNotFoundException();
            }

            if (Path.GetExtension(FilePath).ToUpper() != ".MGF")
            {
                throw new InvalidDataException();
            }

            Loaders.LoadElements();
            reader = new StreamReader(FilePath);

            BuildIndex();
        }
Exemple #21
0
        public ProteoformRelation(Proteoform pf1, Proteoform pf2, ProteoformComparison relation_type, double delta_mass, string current_directory)
        {
            connected_proteoforms[0] = pf1;
            connected_proteoforms[1] = pf2;
            RelationType             = relation_type;
            DeltaMass  = delta_mass;
            InstanceId = instanceCounter;
            lock (SaveState.lollipop) instanceCounter += 1; //Not thread safe

            if (CH2 == null || HPO3 == null)
            {
                Loaders.LoadElements(Path.Combine(current_directory, "elements.dat"));
                CH2  = ChemicalFormula.ParseFormula("C1 H2");
                HPO3 = ChemicalFormula.ParseFormula("H1 O3 P1");
            }

            if (SaveState.lollipop.neucode_labeled)
            {
                lysine_count = pf1.lysine_count;
            }

            if ((relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy) &&
                SaveState.lollipop.theoretical_database.possible_ptmset_dictionary.TryGetValue(Math.Round(delta_mass, 1), out List <PtmSet> candidate_sets) &&
                pf2 as TheoreticalProteoform != null)
            {
                TheoreticalProteoform t      = pf2 as TheoreticalProteoform;
                double        mass_tolerance = t.modified_mass / 1000000 * (double)SaveState.lollipop.mass_tolerance;
                List <PtmSet> narrower_range_of_candidates = candidate_sets.Where(s => Math.Abs(s.mass - delta_mass) < 0.05).ToList();
                candidate_ptmset = t.generate_possible_added_ptmsets(narrower_range_of_candidates, delta_mass, mass_tolerance, SaveState.lollipop.theoretical_database.all_mods_with_mass, t, t.sequence, SaveState.lollipop.mod_rank_first_quartile)
                                   .OrderBy(x => x.ptm_rank_sum + Math.Abs(Math.Abs(x.mass) - Math.Abs(delta_mass)) * 10E-6) // major score: delta rank; tie breaker: deltaM, where it's always less than 1
                                   .FirstOrDefault();
            }

            // Start the model (0 Da) at the mass defect of CH2 or HPO3 itself, allowing the peak width tolerance on either side
            double half_peak_width = RelationType == ProteoformComparison.ExperimentalTheoretical || RelationType == ProteoformComparison.ExperimentalDecoy ?
                                     SaveState.lollipop.peak_width_base_et / 2 :
                                     SaveState.lollipop.peak_width_base_ee / 2;
            double low_decimal_bound  = half_peak_width + ((CH2.MonoisotopicMass - Math.Truncate(CH2.MonoisotopicMass)) / CH2.MonoisotopicMass) * (Math.Abs(delta_mass) <= CH2.MonoisotopicMass ? CH2.MonoisotopicMass : Math.Abs(delta_mass));
            double high_decimal_bound = 1 - half_peak_width + ((HPO3.MonoisotopicMass - Math.Ceiling(HPO3.MonoisotopicMass)) / HPO3.MonoisotopicMass) * (Math.Abs(delta_mass) <= HPO3.MonoisotopicMass ? HPO3.MonoisotopicMass : Math.Abs(delta_mass));
            double delta_mass_decimal = Math.Abs(delta_mass - Math.Truncate(delta_mass));

            outside_no_mans_land = delta_mass_decimal <= low_decimal_bound || delta_mass_decimal >= high_decimal_bound ||
                                   high_decimal_bound <= low_decimal_bound;
        }
Exemple #22
0
        public void TestMgf()
        {
            // Get temp path for writing the test MGF
            var tempFilePath = Path.GetTempPath();

            var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"small.RAW");
            var parseInput  = new ParseInput(testRawFile, tempFilePath, null, OutputFormat.MGF);

            RawFileParser.Parse(parseInput);

            // Do this for the mzLib library issue
            var tempFileName = Path.GetTempPath() + "elements.dat";

            Loaders.LoadElements(tempFileName);

            var mgfData = Mgf.LoadAllStaticData(Path.Combine(tempFilePath, "small.mgf"));

            Assert.AreEqual(34, mgfData.NumSpectra);
        }
        public static void ProteaseModTest()
        {
            Loaders.LoadElements();
            string subFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"DigestionTest");

            Directory.CreateDirectory(subFolder);

            string databasePath1 = Path.Combine(TestContext.CurrentContext.TestDirectory, "DatabaseTests", "ProteaseModTest.fasta");
            var    protDic       = ProteaseDictionary.LoadProteaseDictionary(Path.Combine(GlobalVariables.DataDir, @"ProteolyticDigestion", @"proteases.tsv"), GlobalVariables.ProteaseMods);

            DigestionParams param       = new DigestionParams(protease: "CNBr", maxMissedCleavages: 0);
            var             proteinList = ProteinDbLoader.LoadProteinFasta(databasePath1, true, DecoyType.None, false, out List <string> errors);
            var             protein     = proteinList[0];
            var             peptides    = protein.Digest(param, new List <Modification>(), new List <Modification>()).ToList();

            Assert.AreEqual(2, peptides.Count());
            Assert.AreNotEqual(peptides[0].FullSequence, peptides[1].FullSequence);
            Assert.AreEqual(882.39707781799996, peptides[0].MonoisotopicMass);
            Assert.AreEqual(930.400449121, peptides[1].MonoisotopicMass);
        }
Exemple #24
0
        public MainWindow()
        {
            InitializeComponent();
            dataGridPeptideFiles.DataContext         = DataFilesObservableCollection;
            dataGridDatabaseFiles.DataContext        = DatabasesObservableCollection;
            DisplayedSamplesDataGrid.DataContext     = FilesToDisplayObservableCollection;
            HiddenSamplesDataGrid.DataContext        = FilesToHideObservableCollection;
            DisplayAnalyzedFilesDataGrid.DataContext = DataFilesObservableCollection;
            HalfLifeHistogramPlot.Configure(enableScrollWheelZoom: false);
            PrecisionPlot.Configure(enableScrollWheelZoom: false);
            HalfLifeComparisonPlot.Configure(enableScrollWheelZoom: false);
            RatioComparisonPlot.Configure(enableScrollWheelZoom: false);
            peptideRadioButton.IsChecked         = true;
            proteinSpecificRadioButton.IsChecked = DisplayProteinInSpecificTable;

            DisplayPeptidesView = CollectionViewSource.GetDefaultView(PeptidesToDisplay);
            DisplayPeptidesDataGrid.DataContext = DisplayPeptidesView;
            Loaders.LoadElements();
            PopulateChoices();
        }
        static void Main(string[] args)
        {
            List <string> files = args.Where(f => File.Exists(f) & (Path.GetExtension(f) == ".xml" || Path.GetExtension(f) == ".xml.gz")).ToList();

            if (files.Count < 2)
            {
                Console.WriteLine("Please enter at least two protein .xml or .xml.gz databases.");
                return;
            }

            // check that file path is valid
            string timestamp = DateTime.Now.Year.ToString("0000") + "-" + DateTime.Now.Month.ToString("00") + "-" + DateTime.Now.Day.ToString("00") + "-" + DateTime.Now.Hour.ToString("00") + "-" + DateTime.Now.Minute.ToString("00") + "-" + DateTime.Now.Second.ToString("00");
            string outpath   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "merged_database_" + timestamp + ".xml");

            // merge databases
            Loaders.LoadElements(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "elements.dat"));
            List <Protein> merged = ProteinDbLoader.merge_proteins(files.SelectMany(f => ProteinDbLoader.LoadProteinXML(f, false, new List <Modification>(), false, new List <string>(), out Dictionary <string, Modification> un))).ToList();

            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), merged, outpath);
        }
Exemple #26
0
        /// <summary>
        /// Initiates the dynamic connection with the .mzML file.
        /// </summary>
        protected override void InitiateDynamicConnection()
        {
            if (!File.Exists(FilePath))
            {
                throw new FileNotFoundException();
            }

            if (Path.GetExtension(FilePath).ToUpper() != ".MZML")
            {
                throw new InvalidDataException();
            }

            Loaders.LoadElements();
            reader = new StreamReader(FilePath);

            ScanNumberToByteOffset = new Dictionary <int, long>();
            NativeIdToScanNumber   = new Dictionary <string, int>();

            FindOrCreateIndex();
        }
Exemple #27
0
        private static void BenchmarkDatabaseLoadWrite()
        {
            Console.WriteLine("Starting benchmark BenchmarkDatabaseLoadWrite");

            Stopwatch stopWatch = new Stopwatch();

            Loaders.LoadElements("elements2.dat");
            IEnumerable <Modification> ya = PtmListLoader.ReadModsFromFile(@"ptmlist.txt").ToList();

            stopWatch.Restart();
            var a = ProteinDbLoader.LoadProteinXML(@"yeast_160126.xml.gz", true, ya, false, null, out Dictionary <string, Modification> um);

            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <System.Tuple <int, ModificationWithMass> > >(), a.Where(p => !p.IsDecoy).ToList(), "rewrite_yeast.xml");
            var b = ProteinDbLoader.LoadProteinXML(@"rewrite_yeast.xml", true, ya, false, null, out um);

            stopWatch.Stop();

            Console.WriteLine("Time for getting formulas: " + stopWatch.Elapsed);

            Console.WriteLine("Benchmark BenchmarkDatabaseLoadWrite finished");
        }
Exemple #28
0
        /// <summary>
        /// Initiates a dynamic connection with a Thermo .raw file. Data can be "streamed" instead of loaded all at once. Use
        /// GetOneBasedScanFromDynamicConnection to get data from a particular scan. Use CloseDynamicConnection to close the
        /// dynamic connection after all desired data has been retrieved from the dynamic connection.
        /// </summary>
        protected override void InitiateDynamicConnection()
        {
            if (!File.Exists(FilePath))
            {
                throw new FileNotFoundException();
            }

            if (Path.GetExtension(FilePath).ToUpper() != ".RAW")
            {
                throw new InvalidDataException();
            }

            Loaders.LoadElements();

            if (dynamicConnection != null)
            {
                dynamicConnection.Dispose();
            }

            dynamicConnection = RawFileReaderAdapter.FileFactory(FilePath);

            if (!dynamicConnection.IsOpen)
            {
                throw new MzLibException("Unable to access RAW file!");
            }

            if (dynamicConnection.IsError)
            {
                throw new MzLibException("Error opening RAW file!");
            }

            if (dynamicConnection.InAcquisition)
            {
                throw new MzLibException("RAW file still being acquired!");
            }

            dynamicConnection.SelectInstrument(Device.MS, 1);
            GetMsOrdersByScanInDynamicConnection();
        }
Exemple #29
0
        public void DoNotWriteSameModTwiceAndDoNotWriteInHeaderSinceDifferent()
        {
            Loaders.LoadElements();
            var     sampleModList = PtmListLoader.ReadModsFromFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "DatabaseTests", "z.txt"), out var errors).ToList();
            Protein protein       = new Protein("MCSSSSSSSSSS", "accession", "organism", new List <Tuple <string, string> >(), new Dictionary <int, List <Modification> > {
                { 2, sampleModList.OfType <Modification>().ToList() }
            }, null, "name", "full_name", false, false, new List <DatabaseReference>(), new List <SequenceVariation>(), disulfideBonds: new List <DisulfideBond>());

            Assert.AreEqual(1, protein.OneBasedPossibleLocalizedModifications[2].OfType <Modification>().Count());

            Dictionary <string, HashSet <Tuple <int, Modification> > > dictWithThisMod = new Dictionary <string, HashSet <Tuple <int, Modification> > >();

            HashSet <Tuple <int, Modification> > value = new HashSet <Tuple <int, Modification> >();

            var modReadFromFile = sampleModList.First() as Modification;

            ModificationMotif.TryGetMotif("C", out ModificationMotif motif);
            Modification newMod = new Modification(_originalId: "Palmitoylation of C", _modificationType: "Type", _target: motif, _locationRestriction: "Anywhere.", _chemicalFormula: modReadFromFile.ChemicalFormula, _monoisotopicMass: modReadFromFile.MonoisotopicMass, _featureType: "MOD_RES", _fileOrigin: "E:\\GitClones\\mzLib\\Test\\bin\\x64\\Debug\\DatabaseTests\\z.txt");

            Assert.IsTrue(newMod.Equals(sampleModList.First()));

            Assert.AreEqual(newMod, sampleModList.First());
            Assert.AreEqual(sampleModList.First(), newMod);

            value.Add(new Tuple <int, Modification>(2, newMod));

            dictWithThisMod.Add("accession", value);
            var newModResEntries = ProteinDbWriter.WriteXmlDatabase(dictWithThisMod, new List <Protein> {
                protein
            }, Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins3.xml"));

            Assert.AreEqual(0, newModResEntries.Count);
            List <Protein> new_proteins = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins3.xml"),
                                                                         true, DecoyType.None, new List <Modification>(), false, new List <string>(), out Dictionary <string, Modification> um);

            Assert.AreEqual(1, new_proteins.Count);
            Assert.AreEqual(1, new_proteins[0].OneBasedPossibleLocalizedModifications.Count);
            Assert.AreEqual(1, new_proteins[0].OneBasedPossibleLocalizedModifications.SelectMany(kv => kv.Value).Count());
        }
Exemple #30
0
        public static Mgf LoadAllStaticData(string filePath, FilteringParams filterParams = null)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException();
            }

            Loaders.LoadElements();

            List <MsDataScan> scans = new List <MsDataScan>();
            HashSet <int>     checkForDuplicateScans = new HashSet <int>();

            using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (BufferedStream bs = new BufferedStream(fs))
                {
                    using (StreamReader sr = new StreamReader(bs))
                    {
                        while (sr.Peek() > 0)
                        {
                            string line = sr.ReadLine();
                            if (line != "BEGIN IONS")
                            {
                                continue;
                            }

                            var scan = GetNextMsDataOneBasedScanFromConnection(sr, checkForDuplicateScans, filterParams);

                            scans.Add(scan);
                        }
                    }
                }
            }

            SourceFile sourceFile = new SourceFile("no nativeID format", "mgf format", null, null, null);

            return(new Mgf(scans.OrderBy(x => x.OneBasedScanNumber).ToArray(), sourceFile));
        }