/* This method is to extract all the precursors' mz values. * [M+H]+; [M+Na]+; [M+K]+; [M+NH4]+ * //*/ public static void FindPrecursorMZ(List <SpectrumData> allSpectraList, string outputFilePath) { List <double> mzList = new List <double>(); for (int i = 0; i < allSpectraList.Count; i++) { for (int j = 0; j < allSpectraList[i].peakList.Count; j++) { string iso = allSpectraList[i].peakList[j].isotopes; if (!IdMSMS_Deconvolution.IsIsotope(iso)) { //if (true) { mzList.Add(allSpectraList[i].peakList[j].mz); } } } using (StreamWriter sw = new StreamWriter(outputFilePath)) { for (int i = 0; i < mzList.Count; i++) { if (i == mzList.Count - 1) { sw.Write(mzList[i]); } else { sw.Write(mzList[i] + ","); //if (i%300==0&&i!=0) { // sw.WriteLine(); //} } } } Console.WriteLine(mzList.Count); }
private static SpectrumData GenerateMergedSpectrum(SpectrumData allPeakDataInEachGroup) { // adMSMS data(20ev-50ev-MS) of each group is treated by first calculating relative intensities among group, // then calculating the average intensities in each CID, next taking the max of the value among CIDs SpectrumData mergedSpectrum = new SpectrumData(); mergedSpectrum = CalMaxAverageIntensity(IdMSMS_Deconvolution.CalRelativeIntensity(allPeakDataInEachGroup)); return(mergedSpectrum); }
/* This method is to calculate all the neutral loss in each spectrum. * cross over all peaks! * //*/ public static List <double> FindNeutralLoss(SpectrumData spectrum) { List <double> neutralLossList = new List <double>(); List <PeakData> sortedPeakList = spectrum.peakList.OrderByDescending(x => x.mz).Where(x => !IdMSMS_Deconvolution.IsIsotope(x.isotopes)).ToList(); //并计算和isotope的NL double mzPrecursor = double.Parse(spectrum.group.Split('_')[0]); for (int i = 0; i < sortedPeakList.Count; i++) // add precursor neutral loss { double neutralLoss = mzPrecursor - sortedPeakList[i].mz; if (neutralLoss > 14) { neutralLossList.Add(neutralLoss); } } for (int i = 0; i < sortedPeakList.Count; i++) // add peaks neutral loss { for (int j = i + 1; j < sortedPeakList.Count; j++) { double neutralLoss = sortedPeakList[i].mz - sortedPeakList[j].mz; if (neutralLoss > 14) { neutralLossList.Add(neutralLoss); } } } neutralLossList = neutralLossList.Distinct().ToList(); return(neutralLossList); }
static void Main(string[] args) { Stopwatch watch = new Stopwatch(); watch.Start(); string rootPath = @"E:\Different tissues\idMSMS different tissue\MIX Results\"; /** * Fill 0 values in XCMS peaktable */ //string fillpeaksPath = rootPath + "NormPeakArea.csv"; //string nonefillpeaksPath = rootPath + "data_minfrac0.1_sn3_nonfill.csv"; //string outPath = rootPath + "NormPeakArea_fill0.csv"; //Data_Operation.Fill0Peaks(fillpeaksPath, nonefillpeaksPath, outPath); /** * export precursors (change parapeters to export all/without isotope/only adducts) */ //string CSVFilePath = rootPath + "NormPeakArea.csv"; //List<SpectrumData> allSpectraList = IdMSMS_Deconvolution.ProcessPeaktableToSpectralist(CSVFilePath); //Data_Operation.FindPrecursorMZ(allSpectraList, outPrecursorPath); /** * Assemble idMS/MS with multi-eV */ string CSVFilePath = rootPath + "AllDeconvolutedSpectra_MS_pvals_9s.csv"; string outputFilePath = rootPath + "idmsms_3_6_0.9_minCor_rmv50_50ev.csv"; string NLOutputFilePath = rootPath + "NL_motif.csv"; string NDPmatrixPath = rootPath + "NDPmatrix.csv"; List <SpectrumData> allMergedList = IdMSMS_Deconvolution.MergeIdMSMSOfDiffCIDs(CSVFilePath); FileProcess.WriteSpectrumList(allMergedList, outputFilePath); //output idMSMS spectra FileProcess.OutputNeutralLoss(allMergedList, NLOutputFilePath); //output NL_motif string commonNLPath = rootPath + "Common NL table.csv"; string outNLHitPath = rootPath + "NLmatrix.csv"; FileProcess.OutputSelectedNLto360Spec(allMergedList, commonNLPath, outNLHitPath); //output binary NL hit table //List<SpectrumData> allSpectraList = FileProcess.ReadSpectralCSVFile(CSVFilePath); // use if there is spectra list to read //List<SpectrumData> allKnownSpectraList = FileProcess.ReadKnownMSMSSpectraList(knownMSMSPath); // use if there is known spectra list List <SpectrumData> allKnownSpectraList = allMergedList; List <double[]> NDPResultList = new List <double[]>(); string[] queryTitleLine = new string[allMergedList.Count]; // add QueryTitle line to result for (int i = 0; i < allMergedList.Count; i++) { queryTitleLine[i] = allMergedList[i].group.ToString(); } string[] libraryTitleLine = new string[allKnownSpectraList.Count]; // add Library title to result for (int i = 0; i < allKnownSpectraList.Count; i++) { libraryTitleLine[i] = allKnownSpectraList[i].peakList[0].sampleName; } for (int i = 0; i < allMergedList.Count; i++) { double[] line = new double[allMergedList.Count]; // for (int j = 0; j < allMergedList.Count; j++) // { line[j] = Cal_Cosine_Product.CalCosineProduct(allMergedList[i], allMergedList[j]); // } NDPResultList.Add(line); } FileProcess.WriteNDPListToFile(NDPResultList, queryTitleLine, queryTitleLine, NDPmatrixPath); // output NDPmatrix watch.Stop(); Console.WriteLine("weight: " + IdMSMS_Deconvolution.weight + " minSamp:" + IdMSMS_Deconvolution.minSampleNrForCor + " ndpThreh:" + IdMSMS_Deconvolution.ndpThreshold); Console.WriteLine("Deconvoluted spectra number: " + allMergedList.Count); Console.WriteLine("calculation time: " + watch.Elapsed); Console.WriteLine("OK"); Console.Read(); }