public LocalizationEngine(IEnumerable <PeptideSpectralMatch> allResultingIdentifications, List <ProductType> lp, MsDataFile myMsDataFile, CommonParameters commonParameters, List <string> nestedIds) : base(commonParameters, nestedIds) { AllResultingIdentifications = allResultingIdentifications; ProductTypes = lp; MyMsDataFile = myMsDataFile; DissociationTypes = DetermineDissociationType(lp); }
public SpectrumForm(MsDataFile msDataFile) : base(msDataFile.Workspace) { InitializeComponent(); MsDataFile = msDataFile; tbxScanIndex.Leave += (o, e) => ScanIndex = int.Parse(tbxScanIndex.Text); }
private void resetFilesButton_Click(object sender, RoutedEventArgs e) { // clear spectra file path if ((sender as Button).Name.Equals(resetSpectraFileButton.Name)) { spectraFilePath = null; spectraFileNameLabel.Text = "None Selected"; spectraFileNameLabel.ToolTip = null; resetSpectraFileButton.IsEnabled = false; } // clear psm file path, psm data, and stat plot else { tsvResultsFilePath = null; psmFileNameLabel.Text = "None Selected"; psmFileNameLabel.ToolTip = null; psmFileNameLabelStat.Text = "None Selected"; psmFileNameLabelStat.ToolTip = null; resetPsmFileButton.IsEnabled = false; resetPsmFileButtonStat.IsEnabled = false; allPsms.Clear(); filteredListOfPsms.Clear(); psmsBySourceFile.Clear(); sourceFilesList.Clear(); plotViewStat.DataContext = null; } // clear main plot, base sequence, and properties table mainViewModel.Model = null; BaseDraw.clearCanvas(canvas); propertyView.Clear(); MsDataFile = null; }
public DataPointAcquisitionEngine( List <PeptideSpectralMatch> goodIdentifications, MsDataFile myMsDataFile, Tolerance mzToleranceForMs1Search, int minMS1isotopicPeaksNeededForConfirmedIdentification, CommonParameters commonParameters, List <(string FileName, CommonParameters Parameters)> fileSpecificParameters,
public static void TestFilterKeepsPeaksWithHighestIntensity() { double[] mzArray = new double[200]; double[] intArray = new double[200]; Random r = new Random(); for (int i = 0; i < 200; i++) { mzArray[i] = (double)(i + 1); intArray[i] = (i * Math.Abs(r.Next(1, 100)) + 1d); } List <double> l = intArray.ToList(); l.Sort((x, y) => y.CompareTo(x)); l = l.Take(100).ToList(); FilteringParams f = new FilteringParams(100, null, null, null, false, false, false); MsDataFile.WindowModeHelper(ref intArray, ref mzArray, f, mzArray.Min(), mzArray.Max()); List <double> myOut = intArray.ToList(); myOut.Sort((x, y) => y.CompareTo(x)); Assert.IsTrue(l.SequenceEqual(myOut)); }
public static void TestFilteringPeaksTopN_MultipleWindows(int peaksToKeep, int?nominalWindowWidthDaltons, int peakCount, bool normalize) { double[] mzArray = new double[100]; double[] intArray = new double[100]; for (int i = 0; i < 100; i++) { mzArray[i] = 100d + ((double)i / 100d) * 1900; intArray[i] = i; } FilteringParams f = new FilteringParams(peaksToKeep, null, nominalWindowWidthDaltons, null, normalize, false, false); MsDataFile.WindowModeHelper(ref intArray, ref mzArray, f, 100, 2000, false); if (nominalWindowWidthDaltons.HasValue) { Assert.LessOrEqual((decimal)mzArray.Count(), (decimal)peaksToKeep * (decimal)nominalWindowWidthDaltons); } else { Assert.LessOrEqual((decimal)mzArray.Count(), (decimal)peaksToKeep * (decimal)1.0); } if (normalize) { Assert.That(50, Is.EqualTo(intArray.Max()).Within(0.1)); } }
public bool Run_TdMzCal(InputFile raw_file, List <TopDownHit> topdown_hits) { all_topdown_hits = topdown_hits.Where(h => h.score > 0).ToList(); //need to reset m/z in case same td hits used for multiple calibration raw files... Parallel.ForEach(all_topdown_hits, h => h.mz = h.reported_mass.ToMz(h.charge)); high_scoring_topdown_hits = all_topdown_hits.Where(h => h.score >= 40).ToList(); this.raw_file = raw_file; if (high_scoring_topdown_hits.Count < 5) { return(false); } myMsDataFile = Path.GetExtension(raw_file.complete_path) == ".raw" ? ThermoStaticData.LoadAllStaticData(raw_file.complete_path) : null; if (myMsDataFile == null) { myMsDataFile = Mzml.LoadAllStaticData(raw_file.complete_path); } if (myMsDataFile == null) { return(false); } DataPointAquisitionResults dataPointAcquisitionResult = GetDataPoints(); if (dataPointAcquisitionResult.Ms1List.Count < 10) { return(false); } var myMs1DataPoints = new List <(double[] xValues, double yValue)>(); for (int i = 0; i < dataPointAcquisitionResult.Ms1List.Count; i++) { //x values var explanatoryVariables = new double[4]; explanatoryVariables[0] = dataPointAcquisitionResult.Ms1List[i].mz; explanatoryVariables[1] = dataPointAcquisitionResult.Ms1List[i].retentionTime; explanatoryVariables[2] = dataPointAcquisitionResult.Ms1List[i].logTotalIonCurrent; explanatoryVariables[3] = dataPointAcquisitionResult.Ms1List[i].logInjectionTime; //yvalue double mzError = dataPointAcquisitionResult.Ms1List[i].massError; myMs1DataPoints.Add((explanatoryVariables, mzError)); } var ms1Model = GetRandomForestModel(myMs1DataPoints); CalibrateHitsAndComponents(ms1Model); if (Sweet.lollipop.calibrate_raw_files) { MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, raw_file.directory + "\\" + raw_file.filename + "_calibrated.mzML", false); } return(true); }
public static void TestCoIsolation() { List <DigestionMotif> motifs = new List <DigestionMotif> { new DigestionMotif("K", null, 1, null) }; Protease protease = new Protease("CustProtease", CleavageSpecificity.Full, null, null, motifs); ProteaseDictionary.Dictionary.Add(protease.Name, protease); CommonParameters CommonParameters = new CommonParameters(scoreCutoff: 1, deconvolutionIntensityRatio: 50, digestionParams: new DigestionParams(protease.Name, minPeptideLength: 1)); var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var proteinList = new List <Protein> { new Protein("MNNNKNDNK", null) }; var searchModes = new SinglePpmAroundZeroSearchMode(5); Proteomics.AminoAcidPolymer.Peptide pep1 = new Proteomics.AminoAcidPolymer.Peptide("NNNK"); Proteomics.AminoAcidPolymer.Peptide pep2 = new Proteomics.AminoAcidPolymer.Peptide("NDNK"); var dist1 = IsotopicDistribution.GetDistribution(pep1.GetChemicalFormula(), 0.1, 0.01); var dist2 = IsotopicDistribution.GetDistribution(pep2.GetChemicalFormula(), 0.1, 0.01); MsDataScan[] Scans = new MsDataScan[2]; double[] ms1intensities = new double[] { 0.8, 0.8, 0.2, 0.02, 0.2, 0.02 }; double[] ms1mzs = dist1.Masses.Concat(dist2.Masses).OrderBy(b => b).Select(b => b.ToMz(1)).ToArray(); double selectedIonMz = ms1mzs[1]; MzSpectrum MS1 = new MzSpectrum(ms1mzs, ms1intensities, false); Scans[0] = new MsDataScan(MS1, 1, 1, false, Polarity.Positive, 1.0, new MzRange(300, 2000), "first spectrum", MZAnalyzerType.Unknown, MS1.SumOfAllY, null, null, "scan=1"); double[] ms2intensities = new double[] { 1, 1, 1, 1, 1 }; double[] ms2mzs = new double[] { 146.106.ToMz(1), 228.086.ToMz(1), 229.07.ToMz(1), 260.148.ToMz(1), 342.129.ToMz(1) }; MzSpectrum MS2 = new MzSpectrum(ms2mzs, ms2intensities, false); double isolationMZ = selectedIonMz; Scans[1] = new MsDataScan(MS2, 2, 2, false, Polarity.Positive, 2.0, new MzRange(100, 1500), "second spectrum", MZAnalyzerType.Unknown, MS2.SumOfAllY, null, null, "scan=2", selectedIonMz, null, null, isolationMZ, 2.5, DissociationType.HCD, 1, null); var myMsDataFile = new MsDataFile(Scans, null); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters(deconvolutionIntensityRatio: 50)).OrderBy(b => b.PrecursorMass).ToArray(); PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters, new List <string>()).Run(); // Two matches for this single scan! Corresponding to two co-isolated masses Assert.AreEqual(2, allPsmsArray.Length); Assert.IsTrue(allPsmsArray[0].Score > 1); Assert.AreEqual(2, allPsmsArray[0].ScanNumber); Assert.AreEqual("NNNK", allPsmsArray[0].BaseSequence); Assert.AreEqual("NDNK", allPsmsArray[1].BaseSequence); }
/// <summary> /// Uses the boxcar algorithm to merge the boxcar scans in a file, writes a new mzml file to the directory. /// </summary> /// <param name="file"></param> /// <param name="boxcarRanges"></param> /// <param name="finalFilePath"></param> /// <returns></returns> mergedScans, a list of final merged boxcar scans. public static List <MsDataScan> MergeBoxCarScans(MsDataFile file, SetOfBoxcarRanges[] boxcarRanges, string finalFilePath) { SetOfBoxcarRanges[] bcRanges = RemoveOverlap(boxcarRanges); List <SetOfScans> scans = SeparateScans(file); List <MsDataScan> mergedScans = MergeScans(scans, bcRanges); // WriteMzmlFile(mergedScans, file, finalFilePath); return(mergedScans); }
public DataPointAcquisitionEngine( List <PeptideSpectralMatch> goodIdentifications, List <Ms2ScanWithSpecificMass> goodScans, MsDataFile myMsDataFile, Tolerance precursorMassTolerance, Tolerance productMassTolerance, int minMS1isotopicPeaksNeededForConfirmedIdentification, CommonParameters commonParameters, List <(string FileName, CommonParameters Parameters)> fileSpecificParameters,
public DataRow(MsDataFile dataFile, RegressionWithOutliers unrefined, IList <string> regressedPeptides) { MsDataFile = dataFile; Unrefined = unrefined; RegressedPeptides = regressedPeptides; if (Unrefined != null) { Refined = Unrefined.Refine(); } }
public bool EnsureMsDataFile(MsDataFile msDataFile, bool alwaysPrompt) { String errorMessage; if (!alwaysPrompt && msDataFile.Workspace.IsRejected(msDataFile)) { return(false); } if (TryInitMsDataFile(this, msDataFile, out errorMessage)) { return(true); } if (null == errorMessage) { return(false); } DialogResult dialogResult = MessageBox.Show( "Unable to open the data file for " + msDataFile.Name + ". " + errorMessage + " Do you want to look for this file?", Program.AppName, MessageBoxButtons.OKCancel); while (dialogResult == DialogResult.OK) { using (OpenFileDialog fileDialog = new OpenFileDialog { Filter = msDataFile.Name + ".*|" + msDataFile.Name + ".*" + "|All Files|*.*", Title = "Browser for " + msDataFile.Name, InitialDirectory = Settings.Default.RawFilesDirectory }) { fileDialog.ShowDialog(this); if (String.IsNullOrEmpty(fileDialog.FileName)) { break; } Workspace.SetDataDirectory(Path.GetDirectoryName(fileDialog.FileName)); } if (TryInitMsDataFile(this, msDataFile, out errorMessage)) { return(true); } if (null == errorMessage) { return(false); } dialogResult = MessageBox.Show(errorMessage + " Do you want to keep looking for a different file?", Program.AppName, MessageBoxButtons.OKCancel); } Workspace.RejectMsDataFile(msDataFile); return(false); }
public static void Test_ChargeDeconv() { string FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/2076.mzML"); MsDataFile file = Mzml.LoadAllStaticData(FilepathMZML, null); var scans = file.GetAllScansList(); DeconvolutionParameter deconvolutionParameter = new DeconvolutionParameter(); Stopwatch stopwatch0 = new Stopwatch(); stopwatch0.Start(); var spectrum = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true); stopwatch0.Stop(); Stopwatch stopwatch_iso = new Stopwatch(); stopwatch_iso.Start(); var iso = IsoDecon.MsDeconv_Deconvolute(spectrum, spectrum.Range, deconvolutionParameter); stopwatch_iso.Stop(); Stopwatch stopwatch1 = new Stopwatch(); stopwatch1.Start(); var x = ChargeDecon.FindChargesForScan(spectrum, deconvolutionParameter); stopwatch1.Stop(); //Stopwatch stopwatch2 = new Stopwatch(); //stopwatch2.Start(); var stopwatch2 = Stopwatch.StartNew(); var x2 = ChargeDecon.QuickFindChargesForScan(spectrum, deconvolutionParameter); stopwatch2.Stop(); // Stopwatch stopwatch3 = new Stopwatch(); // stopwatch3.Start(); // int indUp = spectrum.ExtractIndicesByY().First(); // double mass_up = spectrum.XArray[indUp]; // var highest = ChargeDecon.FindChargesForPeak(spectrum, indUp, new DeconvolutionParameter()); // stopwatch3.Stop(); // var Parameters = Program.AddParametersFromFile(""); // List<double> masses = highest.Select(p => p.Value.Mz).ToList(); // string dynamicTargets; // string dynamicMaxITs; // Stopwatch stopwatch4 = new Stopwatch(); // stopwatch4.Start(); // var test = BoxCarScan.BuildDynamicBoxString(Parameters, masses, out dynamicTargets, out dynamicMaxITs); // stopwatch4.Stop(); // Assert.That(test == "[(400.0,522.8),(524.8,542.2),(544.2,563.1),(565.1,585.6),(587.6,610.0),(612.0,636.5),(638.5,665.4),(667.4,697.1),(699.1,732.0),(734.0,770.5),(772.5,813.3),(815.3,861.1),(863.1,915.0),(917.0,976.0),(978.0,1045.7),(1047.7,1126.1),(1128.1,1200.0)]"); }
public static void Test_RealDataDeconv() { string FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/20170802_QEp1_FlMe_SA_BOX0_SILAC_BoxCar_SLICED.mzML"); MsDataFile file = Mzml.LoadAllStaticData(FilepathMZML, null); var scans = file.GetAllScansList(); var test = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true); var ms1scans = scans.Where(p => p.MsnOrder == 1).ToList(); DeconvolutionParameter deconvolutionParameter = new DeconvolutionParameter(); }
private async void loadFilesButton_Click(object sender, RoutedEventArgs e) { // check for validity propertyView.Clear(); if (spectraFilePath == null) { MessageBox.Show("Please add a spectra file."); return; } if (tsvResultsFilePath == null) { MessageBox.Show("Please add a search result file."); return; } // load the spectra file (sender as Button).IsEnabled = false; selectSpectraFileButton.IsEnabled = false; selectPsmFileButton.IsEnabled = false; resetSpectraFileButton.IsEnabled = false; resetPsmFileButton.IsEnabled = false; prgsFeed.IsOpen = true; prgsText.Content = "Loading spectra file..."; // Add EventHandlers for popup click-in/click-out behaviour Deactivated += new EventHandler(prgsFeed_Deactivator); Activated += new EventHandler(prgsFeed_Reactivator); var slowProcess = Task <MsDataFile> .Factory.StartNew(() => spectraFileManager.LoadFile(spectraFilePath, new CommonParameters(trimMsMsPeaks: false))); await slowProcess; MsDataFile = slowProcess.Result; // load the PSMs this.prgsText.Content = "Loading PSMs..."; LoadPsms(tsvResultsFilePath, false); DisplayLoadedAndFilteredPsms(); // done loading - restore controls this.prgsFeed.IsOpen = false; // Remove added EventHandlers Deactivated -= new EventHandler(prgsFeed_Deactivator); Activated -= new EventHandler(prgsFeed_Reactivator); (sender as Button).IsEnabled = true; selectSpectraFileButton.IsEnabled = true; selectPsmFileButton.IsEnabled = true; resetSpectraFileButton.IsEnabled = true; resetPsmFileButton.IsEnabled = true; }
// Grouping the scans in the file /// <summary> /// Given a file, reads through the scans and groups them into SetOfScans objects, each containing one or more full ms1 scans and the corresponding boxcar scans. /// Discards all ms2 scans (although the SetOfScans object also has a list to hold these, if you wanted to include them). /// This method includes many comments which can be uncommented for debugging to write information to the console. /// </summary> /// <param name="file"></param> /// <returns></returns> list of SetOfScans objects, each SetOfScans contains one full ms1 scan and its corresponding boxcar scans. public static List <SetOfScans> SeparateScans(MsDataFile file) { List <SetOfScans> sorted = new List <SetOfScans>(); // Get only the ms1 and boxcar scans (discard ms2): var ms1scans = file.GetMS1Scans().ToList(); //Console.WriteLine("Number of ms1scans (full ms and boxcar method): " + ms1scans.Count); // Initialize variables: MsDataScan current = ms1scans.ElementAt(0); string currentFilter = current.ScanFilter; //Console.WriteLine("first scan filter: " + currentFilter); MsDataScan next = ms1scans.ElementAt(1); string nextFilter = next.ScanFilter; //Console.WriteLine("next scan filter: " + nextFilter); SetOfScans set = new SetOfScans(); // Loop through to group the scans. This should create as many SetOfScans objects as there are boxes (specified in the setup of the scan). for (int i = 0; i < ms1scans.Count; i++) { if (current.ScanFilter.Contains("Full ms ")) // the space is important! Otherwise this will be recorded as a boxcar scan instead of an ms1 { set.AddToMs1Scans(current); // Console.WriteLine("Found full ms, added to set"); } // if this boxcar scan has boxcar scans after it else if (current.ScanFilter.Contains("Full msx ms") && next.ScanFilter.Contains("Full msx ms")) { set.AddToBoxcarScans(current); //Console.WriteLine("Found msx ms, added to set"); } // if this boxcar scan is the last boxcar scan in the set, start a new set else if (current.ScanFilter.Contains("Full msx ms") && !next.ScanFilter.Contains("Full msx ms")) { set.AddToBoxcarScans(current); //Console.WriteLine("Found last msx ms in set, added to set"); sorted.Add(set); //Console.WriteLine("Added set to Sorted"); set = new SetOfScans(); } current = next; currentFilter = current.ScanFilter; if ((i + 1) < ms1scans.Count) // if there is a next MsDataScan in the file { next = ms1scans.ElementAt(i + 1); nextFilter = next.ScanFilter; } } return(sorted); }
public DataPointAcquisitionEngine( List <PeptideSpectralMatch> goodIdentifications, MsDataFile myMsDataFile, Tolerance mzToleranceForMs1Search, int minMS1isotopicPeaksNeededForConfirmedIdentification, CommonParameters commonParameters, List <string> nestedIds) : base(commonParameters, nestedIds) { GoodIdentifications = goodIdentifications; MyMsDataFile = myMsDataFile; MzToleranceForMs1Search = mzToleranceForMs1Search; MinMS1isotopicPeaksNeededForConfirmedIdentification = minMS1isotopicPeaksNeededForConfirmedIdentification; }
private async void loadFilesButton_Click(object sender, RoutedEventArgs e) { // check for validity propertyView.Clear(); if (spectraFilePath == null) { MessageBox.Show("Please add a spectra file."); return; } if (psmFilePath == null) { MessageBox.Show("Please add a search result file."); return; } if (proteinFilePath == null) { MessageBox.Show("Please add a protein search result file."); //fixme return; } // load the spectra file (sender as Button).IsEnabled = false; selectSpectraFileButton.IsEnabled = false; selectPsmFileButton.IsEnabled = false; selectProteinGroupFileButton.IsEnabled = false; prgsFeed.IsOpen = true; prgsText.Content = "Loading spectra file..."; var slowProcess = Task <MsDataFile> .Factory.StartNew(() => spectraFileManager.LoadFile(spectraFilePath, new CommonParameters(trimMsMsPeaks: false))); await slowProcess; MsDataFile = slowProcess.Result; // load protein groups this.prgsText.Content = "Loading protein groups..."; LoadProteinGroups(proteinFilePath); // load the PSMs this.prgsText.Content = "Loading PSMs..."; LoadAndDisplayPsms(psmFilePath); // done loading - restore controls prgsFeed.IsOpen = false; (sender as Button).IsEnabled = true; selectSpectraFileButton.IsEnabled = true; selectPsmFileButton.IsEnabled = true; selectProteinGroupFileButton.IsEnabled = true; }
private DataPointAquisitionResults GetDataAcquisitionResults(MsDataFile myMsDataFile, string currentDataFile, List <Modification> variableModifications, List <Modification> fixedModifications, List <Protein> proteinList, string taskId, CommonParameters combinedParameters, Tolerance initPrecTol, Tolerance initProdTol) { var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(currentDataFile); MassDiffAcceptor searchMode = initPrecTol is PpmTolerance ? (MassDiffAcceptor) new SinglePpmAroundZeroSearchMode(initPrecTol.Value) : new SingleAbsoluteAroundZeroSearchMode(initPrecTol.Value); var listOfSortedms2Scans = GetMs2Scans(myMsDataFile, currentDataFile, combinedParameters).OrderBy(b => b.PrecursorMass).ToArray(); PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; Log("Searching with searchMode: " + searchMode, new List <string> { taskId, "Individual Spectra Files", fileNameWithoutExtension }); Log("Searching with productMassTolerance: " + initProdTol, new List <string> { taskId, "Individual Spectra Files", fileNameWithoutExtension }); new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, combinedParameters, this.FileSpecificParameters, new List <string> { taskId, "Individual Spectra Files", fileNameWithoutExtension }).Run(); List <PeptideSpectralMatch> allPsms = allPsmsArray.Where(b => b != null).ToList(); allPsms = allPsms.OrderByDescending(b => b.Score) .ThenBy(b => b.PeptideMonisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.PeptideMonisotopicMass.Value) : double.MaxValue) .GroupBy(b => (b.FullFilePath, b.ScanNumber, b.PeptideMonisotopicMass)).Select(b => b.First()).ToList(); new FdrAnalysisEngine(allPsms, searchMode.NumNotches, CommonParameters, this.FileSpecificParameters, new List <string> { taskId, "Individual Spectra Files", fileNameWithoutExtension }).Run(); List <PeptideSpectralMatch> goodIdentifications = allPsms.Where(b => b.FdrInfo.QValueNotch < 0.001 && !b.IsDecoy && b.FullSequence != null).ToList(); if (!goodIdentifications.Any()) { return(new DataPointAquisitionResults(null, new List <PeptideSpectralMatch>(), new List <LabeledDataPoint>(), new List <LabeledDataPoint>(), 0, 0, 0, 0)); } DataPointAquisitionResults currentResult = (DataPointAquisitionResults) new DataPointAcquisitionEngine( goodIdentifications, myMsDataFile, initPrecTol, CalibrationParameters.MinMS1IsotopicPeaksNeededForConfirmedIdentification, CommonParameters, this.FileSpecificParameters, new List <string> { taskId, "Individual Spectra Files", fileNameWithoutExtension }).Run(); return(currentResult); }
public static void Test_FragmentMesh() { string FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/2076.mzML"); MsDataFile file = Mzml.LoadAllStaticData(FilepathMZML, null); var scans = file.GetAllScansList(); DeconvolutionParameter deconvolutionParameter = new DeconvolutionParameter(); var spectrum = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true); var CEs = ChargeDecon.FindChargesForScan(spectrum, deconvolutionParameter); var mesh = CEs.First().mzs_box; Assert.That(mesh.Count() == 3); }
public CalibrationEngine(MsDataFile myMSDataFile, DataPointAquisitionResults datapoints, CommonParameters commonParameters, List <string> nestedIds) : base(commonParameters, nestedIds) { MyMsDataFile = myMSDataFile; Datapoints = datapoints; // set the random seed based on raw file properties if (MyMsDataFile.SourceFile != null && !string.IsNullOrEmpty(MyMsDataFile.SourceFile.CheckSum)) { RandomSeed = MyMsDataFile.SourceFile.CheckSum.GetHashCode(); } else { RandomSeed = MyMsDataFile.NumSpectra; } }
public static bool TryInitMsDataFile(IWin32Window parent, MsDataFile msDataFile, out string errorMessage) { bool success = false; string message = null; using (var longWaitDialog = new LongWaitDialog(parent, Program.AppName)) { new LongOperationBroker(broker => { broker.UpdateStatusMessage(string.Format("Reading retention times for {0}", msDataFile.Name)); success = MsDataFileUtil.TryInitMsDataFile(msDataFile.Workspace, msDataFile, broker.CancellationToken, out message); }, longWaitDialog).LaunchJob(); } errorMessage = message; return(success); }
public static void BU_dynamicBoxCarRange() { string FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/20170802_QEp1_FlMe_SA_BOX0_SILAC_BoxCar_SLICED.mzML"); MsDataFile file = Mzml.LoadAllStaticData(FilepathMZML, null); var scans = file.GetAllScansList(); var spectrum = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true); Parameters parameters = Program.AddParametersFromFile(""); var isos = IsoDecon.MsDeconv_Deconvolute(spectrum, spectrum.Range, parameters.DeconvolutionParameter); List <List <Tuple <double, double, double> > > Boxes = new List <List <Tuple <double, double, double> > >(); BoxCarScan.GenerateDynamicBoxes_BU(isos, parameters, Boxes); Assert.That(Boxes.Count == 2); }
private void SaveChromatograms(ICollection <AnalysisChromatograms> analyses, MsDataFile msDataFile) { using (ISession session = workspace.OpenWriteSession()) { ITransaction transaction = session.BeginTransaction(); foreach (AnalysisChromatograms analysis in analyses) { var dbPeptideAnalysis = session.Get <DbPeptideFileAnalysis>(analysis.PeptideFileAnalysis.Id); if (dbPeptideAnalysis == null) { continue; } dbPeptideAnalysis.Times = analysis.Times.ToArray(); dbPeptideAnalysis.ScanIndexes = analysis.ScanIndexes.ToArray(); dbPeptideAnalysis.HasChromatograms = true; session.Update(dbPeptideAnalysis); var dbChromatogramDict = dbPeptideAnalysis.GetChromatogramDict(); foreach (Chromatogram chromatogram in analysis.Chromatograms) { DbChromatogram dbChromatogram; if (!dbChromatogramDict.TryGetValue(chromatogram.MzKey, out dbChromatogram)) { dbChromatogram = new DbChromatogram { PeptideFileAnalysis = dbPeptideAnalysis, MzKey = chromatogram.MzKey, }; } dbChromatogram.IntensitiesBytes = ArrayConverter.ToBytes(chromatogram.Intensities.ToArray()); dbChromatogram.PeakMzsBytes = ArrayConverter.ToBytes(chromatogram.PeakMzs.ToArray()); dbChromatogram.Mz = chromatogram.Mz; session.SaveOrUpdate(dbChromatogram); } } if (msDataFile != null) { msDataFile.MsDataFileData.Save(session); } transaction.Commit(); } foreach (var analysis in analyses) { Debug.Assert(_activePeptideFileAnalysisIds.Contains(analysis.PeptideFileAnalysis.Id.Value)); analysis.PeptideFileAnalysis.HasChromatograms = true; } }
public static string GetCohort(MsDataFile msDataFile, bool bySample) { var result = new StringBuilder(); if (msDataFile.Cohort != null) { result.Append(msDataFile.Cohort); } if (bySample && !string.IsNullOrEmpty(msDataFile.Sample)) { if (result.Length > 0) { result.Append(" "); } result.Append(msDataFile.Sample); } return(result.ToString()); }
public static void TestFilterLowIntensity() { double[] mzArray = new double[100]; double[] intArray = new double[100]; for (int i = 0; i < 100; i++) { mzArray[i] = (double)i; intArray[i] = (double)i; } FilteringParams f = new FilteringParams(null, 0.05, null, null, false, false, false); MsDataFile.WindowModeHelper(ref intArray, ref mzArray, f, mzArray.Min(), mzArray.Max()); //The first five intensities are below 5% and therefore removed. Assert.AreEqual(95, intArray.Count()); Assert.AreEqual(95, mzArray.Count()); }
public static void AnotherSpectralLibrarySearchTestDecoy() { var testDir = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch"); string myFile = Path.Combine(testDir, @"slicedMouse.raw"); MyFileManager myFileManager = new MyFileManager(true); CommonParameters commonParameters = new CommonParameters(maxThreadsToUsePerFile: 1, scoreCutoff: 1); MsDataFile myMsDataFile = myFileManager.LoadFile(myFile, commonParameters); var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var proteinList = new List <Protein> { new Protein("QTATIAHVTTMLGEVIGFNDHIVK", "P16858") }; string targetSpectralLibrary = Path.Combine(testDir, @"P16858_target.msp"); string decoySpectralLibrary = Path.Combine(testDir, @"P16858_decoy.msp"); List <string> specLibs = new List <string> { targetSpectralLibrary, decoySpectralLibrary }; SpectralLibrary sl = new SpectralLibrary(specLibs); var searchModes = new SinglePpmAroundZeroSearchMode(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, commonParameters, null, sl, new List <string>(), writeSpectralLibrary).Run(); // Single search mode Assert.AreEqual(7, allPsmsArray.Length); Assert.IsTrue(allPsmsArray[5].Score > 38); Assert.AreEqual("VIHDNFGIVEGLMTTVHAITATQK", allPsmsArray[5].BaseSequence); Assert.IsTrue(allPsmsArray[5].IsDecoy); SpectralLibrarySearchFunction.CalculateSpectralAngles(sl, allPsmsArray, listOfSortedms2Scans, commonParameters); Assert.That(allPsmsArray[5].SpectralAngle, Is.EqualTo(0.69).Within(0.01)); }
public static bool TryInitMsDataFile(Workspace workspace, MsDataFile msDataFile, CancellationToken cancellationToken, out String message) { if (string.IsNullOrEmpty(workspace.GetDataDirectory())) { message = "Workspace data directory has not been specified"; return(false); } var path = workspace.GetDataFilePath(msDataFile.Name); if (path == null) { message = "File could not be found"; return(false); } if (msDataFile.HasTimes()) { message = "File exists and has been read before."; return(true); } try { using (var cMsDataFile = new MsDataFileImpl(path)) { msDataFile.Init(cancellationToken, cMsDataFile); using (var session = workspace.OpenWriteSession()) { session.BeginTransaction(); msDataFile.SaveBinary(session); session.Transaction.Commit(); message = "Success"; return(true); } } } catch (Exception exception) { ErrorHandler.LogException("MsDataFiles", "Exception trying to open " + path, exception); message = "An exception occurred while trying to open the file. Either the file is corrupted, or the necessary libraries to read this file type have not been installed."; return(false); } }
public static bool TryInitMsDataFile(Workspace workspace, MsDataFile msDataFile, String path, out String message) { if (path == null) { message = "Location of data file has never been specified."; return(false); } if (!File.Exists(path)) { message = "File does not exist."; return(false); } if (msDataFile.HasTimes()) { message = "File exists and has been read before."; return(true); } try { using (var cMsDataFile = new MsDataFileImpl(path)) { msDataFile.Init(path, cMsDataFile); using (var session = workspace.OpenWriteSession()) { session.BeginTransaction(); msDataFile.Save(session); session.Transaction.Commit(); message = "Success"; return(true); } } } catch (Exception exception) { Console.Out.Write(exception); message = "An exception occurred while trying to open the file. Either the file is corrupted, or the necessary libraries to read this file type have not been installed."; return(false); } }
public static void TestFilterNumberPeaksPerWindowTenWindows() { double[] mzArray = new double[200]; double[] intArray = new double[200]; for (int i = 0; i < 200; i++) { mzArray[i] = (double)(i + 1); intArray[i] = (double)(i + 1); } FilteringParams f = new FilteringParams(10, null, 20, 10, false, false, false); MsDataFile.WindowModeHelper(ref intArray, ref mzArray, f, mzArray.Min(), mzArray.Max()); Assert.AreEqual(100, intArray.Count()); Assert.AreEqual(100, mzArray.Count()); Assert.AreEqual(11, intArray.Min()); Assert.AreEqual(200, intArray.Max()); Assert.AreEqual(11, mzArray.Min()); Assert.AreEqual(200, mzArray.Max()); }
public IEnumerable <DeconvolutedEnvelope> Deconvolute(MsDataFile file, string fileName = null, int threads = -1) { var items = new List <DeconvolutedEnvelope>(); var scans = file.GetMS1Scans().ToList(); int scansComplete = 0; Parallel.ForEach(Partitioner.Create(0, scans.Count), new ParallelOptions { MaxDegreeOfParallelism = threads }, (range, loopState) => { for (int i = range.Item1; i < range.Item2; i++) { var scan = scans[i]; var deconvolutedEnvs = Deconvolute(scan).ToList(); foreach (var env in deconvolutedEnvs) { env.SpectraFileName = fileName; } lock (items) { items.AddRange(deconvolutedEnvs); scansComplete++; } } }); foreach (var item in items.OrderByDescending(p => p.Score)) { // TODO: feature finding yield return(item); } }
public bool EnsureMsDataFile(MsDataFile msDataFile, bool alwaysPrompt) { String errorMessage; if (!alwaysPrompt && msDataFile.Workspace.IsRejected(msDataFile)) { return false; } if (TryInitMsDataFile(this, msDataFile, out errorMessage)) { return true; } if (null == errorMessage) { return false; } DialogResult dialogResult = MessageBox.Show( "Unable to open the data file for " + msDataFile.Name + ". " + errorMessage + " Do you want to look for this file?", Program.AppName, MessageBoxButtons.OKCancel); while (dialogResult == DialogResult.OK) { using (OpenFileDialog fileDialog = new OpenFileDialog { Filter = msDataFile.Name + ".*|" + msDataFile.Name + ".*" + "|All Files|*.*", Title = "Browser for " + msDataFile.Name, InitialDirectory = Settings.Default.RawFilesDirectory }) { fileDialog.ShowDialog(this); if (String.IsNullOrEmpty(fileDialog.FileName)) { break; } Workspace.SetDataDirectory(Path.GetDirectoryName(fileDialog.FileName)); } if (TryInitMsDataFile(this, msDataFile, out errorMessage)) { return true; } if (null == errorMessage) { return false; } dialogResult = MessageBox.Show(errorMessage + " Do you want to keep looking for a different file?", Program.AppName, MessageBoxButtons.OKCancel); } Workspace.RejectMsDataFile(msDataFile); return false; }
public static bool TryInitMsDataFile(IWin32Window parent, MsDataFile msDataFile, out string errorMessage) { bool success = false; string message = null; using (var longWaitDialog = new LongWaitDialog(parent, Program.AppName)) { new LongOperationBroker(broker=> { broker.UpdateStatusMessage(string.Format("Reading retention times for {0}", msDataFile.Name)); success = MsDataFileUtil.TryInitMsDataFile(msDataFile.Workspace, msDataFile, broker.CancellationToken, out message); }, longWaitDialog).LaunchJob(); } errorMessage = message; return success; }
public bool EnsureMsDataFile(MsDataFile msDataFile) { return EnsureMsDataFile(msDataFile, false); }
public DataRow(MsDataFile dataFile, RegressionWithOutliers unrefined, IList<string> regressedPeptides) { MsDataFile = dataFile; Unrefined = unrefined; RegressedPeptides = regressedPeptides; if (Unrefined != null) { Refined = Unrefined.Refine(); } }
public static string GetCohort(MsDataFile msDataFile, bool bySample) { var result = new StringBuilder(); if (msDataFile.Cohort != null) { result.Append(msDataFile.Cohort); } if (bySample && !string.IsNullOrEmpty(msDataFile.Sample)) { if (result.Length > 0) { result.Append(" "); } result.Append(msDataFile.Sample); } return result.ToString(); }
private void GenerateChromatograms(MsDataFile msDataFile, List<AnalysisChromatograms> analyses) { int totalAnalyses = analyses.Count; if (totalAnalyses == 0) { return; } if (!UpdateProgress(0)) { return; } analyses = new List<AnalysisChromatograms>(analyses); using (var pwizMsDataFileImpl = new MsDataFileImpl(msDataFile.Path)) { var completeAnalyses = new List<AnalysisChromatograms>(); int totalScanCount = pwizMsDataFileImpl.SpectrumCount; double minTime = msDataFile.GetTime(msDataFile.GetSpectrumCount() - 1); double maxTime = msDataFile.GetTime(0); foreach (var analysis in analyses) { minTime = Math.Min(minTime, analysis.FirstTime); maxTime = Math.Max(maxTime, analysis.LastTime); } int firstScan = msDataFile.FindScanIndex(minTime); for (int iScan = firstScan; analyses.Count > 0 && iScan < totalScanCount; iScan++) { double time = msDataFile.GetTime(iScan); int progress = (int)(100 * (time - minTime) / (maxTime - minTime)); progress = Math.Min(progress, 100); progress = Math.Max(progress, 0); if (!UpdateProgress(progress)) { return; } List<AnalysisChromatograms> activeAnalyses = new List<AnalysisChromatograms>(); double nextTime = Double.MaxValue; if (msDataFile.GetMsLevel(iScan, pwizMsDataFileImpl) != 1) { continue; } foreach (var analysis in analyses) { nextTime = Math.Min(nextTime, analysis.FirstTime); if (analysis.FirstTime <= time) { activeAnalyses.Add(analysis); } } if (activeAnalyses.Count == 0) { int nextScan = msDataFile.FindScanIndex(nextTime); iScan = Math.Max(iScan, nextScan - 1); continue; } double[] mzArray, intensityArray; pwizMsDataFileImpl.GetSpectrum(iScan, out mzArray, out intensityArray); foreach (var analysis in activeAnalyses) { var points = new List<MsDataFileUtil.ChromatogramPoint>(); foreach (var chromatogram in analysis.Chromatograms) { points.Add(MsDataFileUtil.GetIntensity(chromatogram.Mz, mzArray, intensityArray)); } analysis.AddPoints(iScan, time, points); } var incompleteAnalyses = new List<AnalysisChromatograms>(); foreach (var analysis in analyses) { if (analysis.LastTime <= time) { completeAnalyses.Add(analysis); } else { incompleteAnalyses.Add(analysis); } } if (completeAnalyses.Count > 10) { SaveChromatograms(completeAnalyses, null); completeAnalyses.Clear(); } analyses = incompleteAnalyses; } completeAnalyses.AddRange(analyses); SaveChromatograms(completeAnalyses, msDataFile); lock(this) { _activePeptideFileAnalysisIds.Clear(); } } }
private void SaveChromatograms(ICollection<AnalysisChromatograms> analyses, MsDataFile msDataFile) { using (ISession session = workspace.OpenWriteSession()) { ITransaction transaction = session.BeginTransaction(); foreach (AnalysisChromatograms analysis in analyses) { var dbPeptideAnalysis = session.Get<DbPeptideFileAnalysis>(analysis.PeptideFileAnalysis.Id); if (dbPeptideAnalysis == null) { continue; } dbPeptideAnalysis.Times = analysis.Times.ToArray(); dbPeptideAnalysis.ScanIndexes = analysis.ScanIndexes.ToArray(); dbPeptideAnalysis.HasChromatograms = true; session.Update(dbPeptideAnalysis); var dbChromatogramDict = dbPeptideAnalysis.GetChromatogramDict(); foreach (Chromatogram chromatogram in analysis.Chromatograms) { DbChromatogram dbChromatogram; if (!dbChromatogramDict.TryGetValue(chromatogram.MzKey, out dbChromatogram)) { dbChromatogram = new DbChromatogram { PeptideFileAnalysis = dbPeptideAnalysis, MzKey = chromatogram.MzKey, }; } dbChromatogram.IntensitiesBytes = ArrayConverter.ToBytes(chromatogram.Intensities.ToArray()); dbChromatogram.PeakMzsBytes = ArrayConverter.ToBytes(chromatogram.PeakMzs.ToArray()); dbChromatogram.Mz = chromatogram.Mz; session.SaveOrUpdate(dbChromatogram); } } if (msDataFile != null) { msDataFile.MsDataFileData.Save(session); } transaction.Commit(); } foreach (var analysis in analyses) { Debug.Assert(_activePeptideFileAnalysisIds.Contains(analysis.PeptideFileAnalysis.Id.Value)); analysis.PeptideFileAnalysis.HasChromatograms = true; } }
public DataFileRow(DataFilesForm form, MsDataFile dataFile) { _form = form; _dataFile = dataFile; }
public static bool InitMsDataFile(Workspace workspace, MsDataFile msDataFile) { String error; return TryInitMsDataFile(workspace, msDataFile, msDataFile.Path, out error); }
public static bool TryInitMsDataFile(Workspace workspace, MsDataFile msDataFile, String path, out String message) { if (path == null) { message = "Location of data file has never been specified."; return false; } if (!File.Exists(path)) { message = "File does not exist."; return false; } if (msDataFile.HasTimes()) { message = "File exists and has been read before."; return true; } try { using(var cMsDataFile = new MsDataFileImpl(path)) { msDataFile.Init(path, cMsDataFile); using (var session = workspace.OpenWriteSession()) { session.BeginTransaction(); msDataFile.Save(session); session.Transaction.Commit(); message = "Success"; return true; } } } catch (Exception exception) { Console.Out.Write(exception); message = "An exception occurred while trying to open the file. Either the file is corrupted, or the necessary libraries to read this file type have not been installed."; return false; } }