private static int ExecuteDenovoModuleGpu(SearchParametersDto parameters, MsPeaksDto massSpectrometryData) { var pstGenerator = new PstGeneratorGpu(); var pstTags = pstGenerator.GeneratePeptideSequenceTags(parameters, massSpectrometryData); return(pstTags.Count); }
private List <ProteinDto> ExecutePostTranslationalModificationsModule(SearchParametersDto parameters, List <ProteinDto> candidateProteins, MsPeaksDto massSpectrometryData, ExecutionTimeDto executionTimes) { Stopwatch moduleTimer = Stopwatch.StartNew(); List <ProteinDto> proteoformsList; if (parameters.PtmAllow == 1) { proteoformsList = _postTranslationalModificationModule.ExecutePtmModule(candidateProteins, massSpectrometryData, parameters); _insilicoFilter.ComputeInsilicoScore(proteoformsList, massSpectrometryData.Mass, parameters.HopThreshhold); _molecularWeightModule.FilterModifiedProteinsByWholeProteinMass(parameters, proteoformsList, massSpectrometryData); } else { proteoformsList = candidateProteins; foreach (var protein in proteoformsList) { protein.PtmParticulars = new List <PostTranslationModificationsSiteDto>(); } } moduleTimer.Stop(); executionTimes.PtmTime = moduleTimer.Elapsed.ToString(); return(proteoformsList); }
public static void DumpMwTunerResult(MsPeaksDto msData) { using (StreamWriter file = new StreamWriter(_directory + "\\tuned_molecular_weight.txt", true)) { file.Write(msData.WholeProteinMolecularWeight); } }
public static void DumpMsData(MsPeaksDto msData) { using (StreamWriter file = new StreamWriter(_directory + "\\molecular_weight.txt", true)) { file.Write(msData.WholeProteinMolecularWeight); } Application xlApp = new Application(); if (xlApp == null) { return; } string excelFile = _directory + "\\PeakListData.xls"; Application oXL; _Workbook oWB; _Worksheet oSheet; Range oRng; object misvalue = System.Reflection.Missing.Value; try { //Start Excel and get Application object. oXL = new Microsoft.Office.Interop.Excel.Application(); //oXL.Visible = true; //Get a new workbook. oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add("")); oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet; //Add table headers going cell by cell. oSheet.Cells[1, 1] = "Peak"; oSheet.Cells[1, 2] = "Intensity"; for (int i = 0; i < msData.Mass.Count; i++) { oSheet.Cells[i + 2, 1] = msData.Mass[i]; oSheet.Cells[i + 2, 2] = msData.Intensity[i]; } oXL.Visible = false; oXL.UserControl = false; oWB.SaveAs(excelFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); oWB.Close(); } catch (Exception) { } //... }
//Mass Tunner private void ExecuteMassTunerModule(SearchParametersDto parameters, MsPeaksDto peakData, ExecutionTimeDto executionTimes) { Stopwatch moduleTimer = Stopwatch.StartNew(); if (parameters.Autotune == 1) { //double a = parameters.NeutralLoss; _wholeProteinMassTuner.TuneWholeProteinMass(peakData, parameters.MwTolerance); } moduleTimer.Stop(); executionTimes.TunerTime = moduleTimer.Elapsed.ToString(); }
//PST: Peptide Sequence Tags private void ExecuteDenovoModule(SearchParametersDto parameters, MsPeaksDto massSpectrometryData, List <ProteinDto> candidateProteins, ExecutionTimeDto executionTimes) { Stopwatch moduleTimer = Stopwatch.StartNew(); var pstTags = _pstGenerator.GeneratePeptideSequenceTags(parameters, massSpectrometryData); //Logging.DumpPstTags(pstTags); if (candidateProteins.Count > 0) { _pstFilter.ScoreProteinsByPst(pstTags, candidateProteins); } //Logging.DumpPstScores(candidateProteins); pstTags.Clear(); moduleTimer.Stop(); executionTimes.PstTime = moduleTimer.Elapsed.ToString(); }
public List <ProteinDto> ExecutePtmModule(List <ProteinDto> proteinList, MsPeaksDto peakData, SearchParametersDto parameters) { var modifiedProteins = new List <ProteinDto>(); if (parameters.PtmCodeVar.Count != 0) { foreach (var protein in proteinList) { protein.PtmScore = ComputeVariableModificationsScore(protein, modifiedProteins, peakData.Mass, parameters); } } if (parameters.PtmCodeFix.Count != 0) { foreach (var protein in proteinList) { protein.PtmScore = ComputeFixedModificationScore(protein, modifiedProteins, peakData.Mass, parameters); } } proteinList.AddRange(modifiedProteins); return(proteinList); }
//SPECTRAL COMPARISON ALGORITHM: private void ExecuteSpectralComparisonModule(SearchParametersDto parameters, List <ProteinDto> candidateProteins, MsPeaksDto massSpectrometryData, ExecutionTimeDto executionTimes) { Stopwatch moduleTimer = Stopwatch.StartNew(); /////Starting From Here !!!! _insilicoFragmentsAdjustment.adjustForFragmentTypeAndSpecialIons(candidateProteins, parameters.InsilicoFragType, parameters.HandleIons); //// //if (parameters.PtmAllow == 0) // (parameters.PtmAllow == 0) // _insilicoFragmentsAdjustment.adjustForFragmentTypeAndSpecialIons(candidateProteins, parameters.InsilicoFragType, // parameters.HandleIons); ////"Module 7 of 9: Insilico Filteration."; //FARHAN //if (true) // (parameters.PtmAllow == 0) // _insilicoFilter.ComputeInsilicoScore(candidateProteins, massSpectrometryData.Mass, parameters.HopThreshhold); moduleTimer.Stop(); executionTimes.InsilicoTime = moduleTimer.Elapsed.ToString(); }
public void FilterModifiedProteinsByWholeProteinMass(SearchParametersDto parameters, List <ProteinDto> shortlistedProteins, MsPeaksDto peakData) { if (parameters.HasFixedAndVariableModifications()) { if (shortlistedProteins.Count > 1) { for (var p = 1; p < shortlistedProteins.Count; p++) { double buffer = MW_filter(peakData.WholeProteinMolecularWeight, parameters.MwTolerance, shortlistedProteins.ElementAt(p).Mw, false); if ((int)buffer == Constants.OutofBoundModifiedMolecularWeight) { shortlistedProteins.Remove(shortlistedProteins.ElementAt(p)); } else { shortlistedProteins.ElementAt(p).MwScore = buffer; } } } } }
/// <summary> /// This function will align the theoretical and experimental spectra and will print the results in the Console. /// Please note, only three general modifications have been considered in alignment process. /// </summary> /// <param name="experiment"> Experimental MS data </param> /// <param name="proteins"> Candidate Protein List </param> /// <param name="errorTolerance"> Fragment tolerance for determing fragment match </param> /// <param name="noOfModificationsAllowedInAlignment"> Maximum no of Mass shifts allowed in spectral alignment </param> public static void Align(MsPeaksDto experiment, List <ProteinInfo> proteins, double errorTolerance, int noOfModificationsAllowedInAlignment) { // Initializing variables ExperimentalMassList = new List <double>(); AlignmentScores = new List <AlignmentScore>(); MaximumNoOfShifts = noOfModificationsAllowedInAlignment; Tolerance = errorTolerance; // Calculating Prefix Mass List ExperimentalMassList.AddRange(experiment.Mass.Select(t => t - 17.026)); ExperimentalMassList.AddRange(experiment.Mass.Select(t => experiment.WholeProteinMolecularWeight - t)); ExperimentalMassList.Sort(); var n = ExperimentalMassList.Count; string baseAbsoluteUri = Directory.GetCurrentDirectory(); string relativePath = @"\Output\SpectralAlignmentResults.txt"; string path = Path.GetFullPath(baseAbsoluteUri + relativePath); if (proteins.Count == 0) { if (!File.Exists(path)) { var outFile = File.Create(path); outFile.Close(); TextWriter tw = new StreamWriter(path); tw.WriteLine("No Protein Found!"); tw.Close(); } else if (File.Exists(path)) { using (var tw = new StreamWriter(path, true)) { tw.WriteLine("No Protein Found!"); } } //Printing Results if no of candidate proteins are zero Console.WriteLine("No Protein Found."); Console.WriteLine("\nPress Any Key to Continue!"); Console.ReadKey(); } else { // Protein theoretical fragments var theoreticalMassList = proteins[0].TheoreticalFragments; theoreticalMassList.Sort(); var m = theoreticalMassList.Count; // A variable containing theoretical and experimental fragment count Index = new Indices(n, m); // Specific modifications ( Acetylation, Methylation, DiMethylation) SpecificModifications = new List <double> { 42.0106, 14.0156, 28.0313 }; // Initialize the Grid with 0s Grid = new int[Index.X, Index.Y]; for (var i = 0; i < Index.X; i++) { for (var j = 0; j < Index.Y; j++) { Grid[i, j] = 0; } } // For determining alignment without mass Shifts AlignmentScores.Add(new AlignmentScore(Utilities.Grid.EvaluateGrid(theoreticalMassList), 0)); // For determining alignment with mass Shifts Utilities.Grid.EvaluateGridWithMassShifts(MaximumNoOfShifts, theoreticalMassList); // Get Longest Alignment with allowed number of mass shifts var shortlistedAllignments = AlignmentScores.Where(x => x.NoOfShifts == noOfModificationsAllowedInAlignment) .Select(t => t.Indices) .ToList(); if (shortlistedAllignments.Count > 0) { // Get the Longest Alignment var alignment = shortlistedAllignments.OrderByDescending(x => x.Count).First(); if (!File.Exists(path)) { var outFile = File.Create(path); outFile.Close(); TextWriter tw = new StreamWriter(path); // Printing Results foreach (var index in alignment) { tw.WriteLine("(" + index.X + ", " + index.Y + "): Exp[" + index.X + "] = " + ExperimentalMassList[index.X] + ", Thr[" + index.Y + "] = " + theoreticalMassList[index.Y] + " & Difference = " + Convert.ToSingle(Math.Abs(ExperimentalMassList[index.X] - theoreticalMassList[index.Y]))); Console.WriteLine("(" + index.X + ", " + index.Y + "): Exp[" + index.X + "] = " + ExperimentalMassList[index.X] + ", Thr[" + index.Y + "] = " + theoreticalMassList[index.Y] + " & Difference = " + Convert.ToSingle(Math.Abs(ExperimentalMassList[index.X] - theoreticalMassList[index.Y]))); } Console.WriteLine("No of Peaks Matched: " + (alignment.Count - 1)); tw.WriteLine("No of Peaks Matched: " + (alignment.Count - 1)); tw.Close(); } else if (File.Exists(path)) { using (var tw = new StreamWriter(path, false)) { // Printing Results foreach (var index in alignment) { tw.WriteLine("(" + index.X + ", " + index.Y + "): Exp[" + index.X + "] = " + ExperimentalMassList[index.X] + ", Thr[" + index.Y + "] = " + theoreticalMassList[index.Y] + " & Difference = " + Convert.ToSingle(Math.Abs(ExperimentalMassList[index.X] - theoreticalMassList[index.Y]))); Console.WriteLine("(" + index.X + ", " + index.Y + "): Exp[" + index.X + "] = " + ExperimentalMassList[index.X] + ", Thr[" + index.Y + "] = " + theoreticalMassList[index.Y] + " & Difference = " + Convert.ToSingle(Math.Abs(ExperimentalMassList[index.X] - theoreticalMassList[index.Y]))); } Console.WriteLine("No of Peaks Matched: " + (alignment.Count - 1)); tw.WriteLine("No of Peaks Matched: " + (alignment.Count - 1)); } } } else { if (!File.Exists(path)) { File.Create(path); TextWriter tw = new StreamWriter(path); tw.WriteLine("\nNo of Peaks Matched at f = " + MaximumNoOfShifts + " are " + 0); tw.Close(); } else if (File.Exists(path)) { using (var tw = new StreamWriter(path, true)) { tw.WriteLine("\nNo of Peaks Matched at f = " + MaximumNoOfShifts + " are " + 0); } } Console.WriteLine("\nNo of Peaks Matched at f = " + MaximumNoOfShifts + " are " + 0); } Console.WriteLine("\n*** Press Any Key to Continue!"); Console.ReadKey(); } }
public void ExecutePtmModule(List <ProteinDto> input, List <ProteinDto> modifiedProteins, List <ProteinDto> shortlistedProt, MsPeaksDto peakData, SearchParametersDto parameters) { throw new NotImplementedException(); }
private List <ProteinDto> GetCandidateProtein(SearchParametersDto parameters, MsPeaksDto peakData) { Stopwatch moduleTimer = Stopwatch.StartNew(); var listOfProteins = _proteinRepository.ExtractProteins(peakData.WholeProteinMolecularWeight, parameters); moduleTimer.Stop(); return(listOfProteins); }
public void TuneWholeProteinMass(MsPeaksDto peakData, double molTolerance) { //Making a 2D list(peakDatalist) in which Mass & Intensity includes var peakDatalist = new List<peakData2Dlist>(); for (int row = 0; row <= peakData.Mass.Count - 1; row++) { var dataforpeakDatalist = new peakData2Dlist(peakData.Mass[row], peakData.Intensity[row]); peakDatalist.Add(dataforpeakDatalist); } //Sort the peakDatalist with respect to the Mass in ascending order var peakDatalistsort = peakDatalist.OrderBy(n => n.Mass).ToList(); //FIGURE 5: STEP 2:::: SUMMATIONS FOR EACH M/Z I,J IN MS2 DATA [REF: SPCTRUM PAPER] //Description::: Calculate Peak Sums and shortlist those falling within user specified tolerance. var summationMassandaverageintensity = new List<peakData2Dlist>(); for (int i = 0; i <= peakDatalistsort.Count - 2; i++) //i starts from 0 so that's why "peakDatalistsort.Count - 1" and according to Formula "n-1" gives peakDatalistsort.Count - 2 { for (int j = i + 1; j <= peakDatalistsort.Count - 1; j++)//j starts from 0 so that's why peakDatalistsort.Count - 1 and according to Formula just "n" { double cpusummationMassData = peakDatalistsort[i].Mass + peakDatalistsort[j].Mass; //Making Tuple sums of MS2 masses if (peakData.WholeProteinMolecularWeight - molTolerance <= cpusummationMassData && cpusummationMassData <= peakData.WholeProteinMolecularWeight + molTolerance)//Masses & Intensities filter out due to the selected RANGE OF INTACT MASS +/- PROTEIN MASS TOLERANCE { double cpuaverageIntensityData = (peakDatalistsort[i].Intensity + peakDatalistsort[j].Intensity) / 2; var dataforsummationMassandaverageintensity = new peakData2Dlist(cpusummationMassData, cpuaverageIntensityData); summationMassandaverageintensity.Add(dataforsummationMassandaverageintensity); //Making 2D list for Mass & Intensity } } } //FIGURE 5: STEP 3 Running window have size of Proton (and starts from smallest mass of FIGURE 5: STEP 2 list) [REF: SPCTRUM PAPER] double windowposition = summationMassandaverageintensity[0].Mass; //Smallest mass selected from Tuple Sums for creating a window positon const double proton = 1.00727647; //Mass of proton var windowcapturedelementsold = new List<peakData2Dlist>(); var oldindex = new List<int>(); //CHANGE MY NAME... var count = new List<int>(); //CHANGE MY NAME... double olddiff = 1, newdiff = 0; //Add here SliderValue(BELOW) double SliderValue = 0.5699; //HARD CODE NOW FOR WORKING WILL ADD THIS FEATURE INTO THE FRONTEND FOR USER DEFINED #FutureWork3b(CPU) int summationMassandaverageintensityindex = summationMassandaverageintensity.Count - 1; while (windowposition < summationMassandaverageintensity[summationMassandaverageintensityindex].Mass) { var newindex = new List<int>(); //CHANGE MY NAME... var windowcapturedelementsnew = new List<peakData2Dlist>(); for (int i = 0; i <= summationMassandaverageintensityindex; i++) { if (windowposition <= summationMassandaverageintensity[i].Mass && summationMassandaverageintensity[i].Mass < windowposition + proton)//#DISCUSSION { var dataforwindowcapturedelementsnew = new peakData2Dlist(summationMassandaverageintensity[i].Mass, summationMassandaverageintensity[i].Intensity); windowcapturedelementsnew.Add(dataforwindowcapturedelementsnew); newindex.Add(i); } else if (summationMassandaverageintensity[i].Mass >= windowposition + proton) { break; } } count.Add(windowcapturedelementsnew.Count); int a = oldindex.Count;//count.Count;///DEL ME AFTER TESTING!!! :) if (windowcapturedelementsnew.Count > windowcapturedelementsold.Count) { windowcapturedelementsold = windowcapturedelementsnew; oldindex = newindex; } else if (windowcapturedelementsnew.Count == windowcapturedelementsold.Count) { olddiff = Math.Abs((windowcapturedelementsold[windowcapturedelementsold.Count - 1].Mass) - peakData.WholeProteinMolecularWeight); newdiff = Math.Abs((windowcapturedelementsnew[windowcapturedelementsnew.Count -1].Mass) - peakData.WholeProteinMolecularWeight); if (olddiff >= newdiff) { windowcapturedelementsold = windowcapturedelementsnew; oldindex = newindex; } } windowposition = windowposition + SliderValue; } //FIGURE 5: STEP 5:::: Applying formula [REF: SPCTRUM PAPER] double[] dataforsumoftunedmassesandintensities = new double[windowcapturedelementsold.Count];//Its tunedmassnominator according to SPECTRUM's formula for TunedMass double sumoftunedmassesandintensities = 0; double sumoftunedintensities = 0; for (int i = 0; i <= windowcapturedelementsold.Count - 1; i++) { dataforsumoftunedmassesandintensities[i] = windowcapturedelementsold[i].Mass * windowcapturedelementsold[i].Intensity; sumoftunedmassesandintensities = sumoftunedmassesandintensities + dataforsumoftunedmassesandintensities[i]; //Actually, ""intensities are not tuned"" (there isn't any terminology in OUR Mass Tuner Algorithm) according to the algorithm but just for the sake of UNDERSTANDING variable names are "dataforsumoftunedintensities" & "sumoftunedintensities". sumoftunedintensities = sumoftunedintensities + windowcapturedelementsold[i].Intensity;//Its tunedmassdenominator according to SPECTRUM's formula for TunedMass } peakData.WholeProteinMolecularWeight = sumoftunedmassesandintensities / sumoftunedintensities;// NOW, Tuned Mass will be consider as Intact Mass(WholeProteinMolecularWeight) }
// Extracts a list Peptide Sequence Tags from the MS/MS peaklist public List <PstTagList> GeneratePeptideSequenceTags(SearchParametersDto parameters, MsPeaksDto peakData) { List <PstTagList> PstTagCPU = new List <PstTagList>(); //////// ************* FARHAN!!! WHAT IF THERE WILL BE NO PST TAGS FOUND THEN, WHAT COULD HAPPENED...????? //////// ************* FARHAN!!! WHAT IF THERE WILL BE NO PST TAGS FOUND THEN, WHAT COULD HAPPENED...????? //////// ************* FARHAN!!! WHAT IF THERE WILL BE NO PST TAGS FOUND THEN, WHAT COULD HAPPENED...????? //Making a 2D list(peakDatalist) in which Mass & Intensity includes var peakDatalist = new List <peakData2Dlist>(); for (int row = 0; row <= peakData.Mass.Count - 1; row++) { var dataforpeakDatalist = new peakData2Dlist(peakData.Mass[row], peakData.Intensity[row]); peakDatalist.Add(dataforpeakDatalist); } //Sort the peakDatalist with respect to the Mass in ascending order var peakDatalistsort = peakDatalist.OrderBy(n => n.Mass).ToList(); var singleLengthPstTagList = GenerateSingleLengthPstList(parameters, peakDatalistsort); // This method will extract Single Length PST Tags var multipleLenghtTagList = GenerateMultipleLenghtPstList(parameters, singleLengthPstTagList); // This method will extract Multiple Length PST Tags //var pstTagsdata = multipleLenghtTagList; // Multiple Tags //////// ************* FARHAN!!! WHAT IF THERE WILL BE NO PST TAGS FOUND THEN, WHAT COULD HAPPENED...????? if (multipleLenghtTagList.Count != 0) // Here filtering out tags according to MIN & MAX threshold of PST lengths... { List <List <PstTagsDto> > TrimPstTagsList = PSTCpuGpuCombineMethod.TrimPstTags(multipleLenghtTagList, parameters); // Break the larger Tags into all possible smaller tags &&& Filtering the Tags according to Minimum-Maximum Range Length of PST var FinalPstTagList = PSTCpuGpuCombineMethod.PstTagInfoList(TrimPstTagsList, parameters); //Calculating PST Tag Error, PST intensity, & Root Mean Square Error etc. && Finding the Unique PSTs: Remove all other redundant PSTs but keep only one having lowest Root Mean Square Error(RMSE) //If 2 or more Tags are same then also keep just one if (FinalPstTagList.Count != 0) { //var AccoFinalPstTagList = AccomodateIsoforms(FinalPstTagList, parameters); // Its Accomodated Isoforms also, considered... COMMENT ME MORE List <PstTagList> PstTags = PSTCpuGpuCombineMethod.AccomodateIsoforms(FinalPstTagList, parameters); PstTagCPU = PstTags; } } return(PstTagCPU); }
public void TuneWholeProteinMass(MsPeaksDto peakData, double molTolerance) {//peakData a data extracted from INPUT FILE //molTolerance is Intact Mass Tolerance //var peakDataMassSort = new int [peakData.Mass.Count]; Make an array of size of peakData.Mass for storing peakData.Mass ////////////peakData.Mass.Sort(); // SORTING OF MASSES WHY SORTING FOR ...???? //peakData.Intensity.Sort(); //SORTING OF INTENSITIES -- DON'T SORT INTENSITIES... ///////****************************************/////// ///////*****************STEPS*****************/////// ///////**************************************/////// /////////////FOR MASSES///////////// //sizeofarray = peakData.Mass.Count * peakData.Mass.Count // GPU Initializations // GPU variable initalizations // GPU variable data Preperation // Launching GPU Code // Post GPU Processing //Converting 2dimensional array{outputarray(summation matrix of masses)} into 1dimensional array for easy to use... //Removing null values(which was redundant & GPU give them value = 0 due to its redundancy) {e.g. [0,1] = 1130.638 & [1,0] = 1130.638. So, GPU gives us [0,1] = 1130.638 & [1,0] = 0 to remove the redundancy because [0,1] and [1,0] are the same} // Converting 1D array to 1D list for easy to use in future.. e.g. sorting etc. /////////////FOR INTENSITIES///////////// // GPU variable initalizations // GPU variable data Preperation // Launching GPU Code //Removing null values(which was redundant & GPU give them value = 0 due to its redundancy) {e.g. [0,1] = 1130.638 & [1,0] = 1130.638. So, GPU gives us [0,1] = 1130.638 & [1,0] = 0 to remove the redundancy because [0,1] and [1,0] are the same} //Converting summation to average i.e. dividing by 2 //Previously size of array(gpuaverageIntensityData) allocated more which is "sizeofarray". So, now resizing the array(gpuaverageIntensityData) to the size of gpuaverageIntensityDataIndex because remain enteries(elements) are empty(=0) /////////////FURTHER PROCESSING///////////// // Now, making 2D-list(gpuprocessedpeaklistdata) from two 1D-lists that are (1D-list of)GPU processed tuple sums OF masses(gpusummationMassData) & (1D-list of)GPU processed tuple sums OF intensities divided by 2(gpuaverageIntensityData) // Sorting gpuprocessedpeaklistdata(2D-list) with respect to the Masses in ascending Order //FIGURE 5: STEP 2:::: SUMMATIONS FOR EACH M/Z I,J IN MS2 DATA [REF: SPCTRUM PAPER] //Description::: Calculate Peak Sums and shortlist those falling within user specified tolerance. //FIGURE 5: STEP 3 Running window have size of Proton (and starts from smallest mass of FIGURE 5: STEP 2 list) [REF: SPCTRUM PAPER] //FIGURE 5: STEP 5:::: Applying formula [REF: SPCTRUM PAPER] var sizeofarray = peakData.Mass.Count * peakData.Mass.Count; /////////////FOR MASSES///////////// // GPU Initializations var gpu = CudafyHost.GetDevice(CudafyModes.Target); var arch = gpu.GetArchitecture(); var km = CudafyTranslator.Cudafy(arch); gpu.LoadModule(km); // GPU variable initalizations var lengthGpuArray = sizeofarray; //peak * peak [In the given case (51 * 51 = 2601)] var monoisotopicMassPeaks = peakData.Mass.ToArray(); var peakListLength = new int[1]; peakListLength[0] = peakData.Mass.Count; var gpuoutputarraymasses = new double[peakData.Mass.Count, peakData.Mass.Count]; // GPU variable data Preperation var monoisotopicMassPeaksDevice = gpu.Allocate(monoisotopicMassPeaks); var peakListLengthDevice = gpu.Allocate(peakListLength); var outputDevice = gpu.Allocate(gpuoutputarraymasses); gpu.CopyToDevice(monoisotopicMassPeaks, monoisotopicMassPeaksDevice); gpu.CopyToDevice(peakListLength, peakListLengthDevice); gpu.CopyToDevice(gpuoutputarraymasses, outputDevice); // Launching GPU Code var numOfBlocks = (int)Math.Ceiling((double)lengthGpuArray / NumberOfThreads); gpu.Launch(numOfBlocks, NumberOfThreads).DeviceGenerateFragmentPairMatrix(monoisotopicMassPeaksDevice, peakListLengthDevice, outputDevice); gpu.CopyFromDevice(outputDevice, gpuoutputarraymasses); gpu.FreeAll(); // Post GPU Processing //Converting 2dimensional array{outputarray(summation matrix of masses)} into 1dimensional array for easy to use... var gpusummationMassData = new double[sizeofarray]; int gpusummationMassDataIndex = 0; for (int rowwise = 0; rowwise <= peakData.Mass.Count - 1; rowwise++) // -1 (peakData.Mass.Count - 1) because its starting from 0 (rowwise = 0) { for (int columnwise = 0; columnwise <= peakData.Mass.Count - 1; columnwise++) //Removing null values(which was redundant & GPU give them value = 0 due to its redundancy) {e.g. [0,1] = 1130.638 & [1,0] = 1130.638. So, GPU gives us [0,1] = 1130.638 & [1,0] = 0 to remove the redundancy because [0,1] and [1,0] are the same} { if (gpuoutputarraymasses[rowwise, columnwise] != 0) { gpusummationMassData[gpusummationMassDataIndex++] = gpuoutputarraymasses[rowwise, columnwise]; } } } Array.Resize(ref gpusummationMassData, gpusummationMassDataIndex); //Previously size of array(gpusummationMassData) allocated more which is "sizeofarray". So, now resizing the array(gpusummationMassData) to the size of gpusummationMassDataIndex because remain enteries(elements) are empty(=0) List <double> gpusummationMassDatalist = gpusummationMassData.ToList(); // Converting 1D array to 1D list for easy to use in future.. e.g. sorting etc. /////////////FOR INTENSITIES///////////// // GPU variable initalizations var monoisotopicIntensityPeaks = peakData.Intensity.ToArray(); var intensitypeakListLength = new int[1]; intensitypeakListLength[0] = peakData.Intensity.Count; var gpuoutputarrayintensities = new double[peakData.Mass.Count, peakData.Mass.Count]; // GPU variable data Preperation var monoisotopicIntensityPeaksDevice = gpu.Allocate(monoisotopicIntensityPeaks); var intensitypeakListLengthDevice = gpu.Allocate(intensitypeakListLength); //intensitypeakListLengthDevice var intensityoutputDevice = gpu.Allocate(gpuoutputarrayintensities); //intensityoutputDevice gpu.CopyToDevice(monoisotopicIntensityPeaks, monoisotopicIntensityPeaksDevice); gpu.CopyToDevice(intensitypeakListLength, intensitypeakListLengthDevice); gpu.CopyToDevice(gpuoutputarrayintensities, intensityoutputDevice); // Launching GPU Code var numOfBlocksforintensity = (int)Math.Ceiling((double)lengthGpuArray / NumberOfThreads); gpu.Launch(numOfBlocksforintensity, NumberOfThreads).DeviceGenerateFragmentPairMatrix(monoisotopicIntensityPeaksDevice, intensitypeakListLengthDevice, intensityoutputDevice); gpu.CopyFromDevice(intensityoutputDevice, gpuoutputarrayintensities); gpu.FreeAll(); int gpuaverageIntensityDataIndex = 0; var gpuaverageIntensityData = new double[sizeofarray]; for (int rowwise = 0; rowwise <= peakData.Mass.Count - 1; rowwise++)// -1 (peakData.Mass.Count - 1) because its starting from 0 (rowwise = 0) { for (int columnwise = 0; columnwise <= peakData.Mass.Count - 1; columnwise++) { if (gpuoutputarrayintensities[rowwise, columnwise] != 0) //Removing null values(which was redundant & GPU give them value = 0 due to its redundancy) {e.g. [0,1] = 1130.638 & [1,0] = 1130.638. So, GPU gives us [0,1] = 1130.638 & [1,0] = 0 to remove the redundancy because [0,1] and [1,0] are the same} { gpuaverageIntensityData[gpuaverageIntensityDataIndex++] = (gpuoutputarrayintensities[rowwise, columnwise]) / 2; //Converting summation to average i.e. dividing by 2 } } } Array.Resize(ref gpuaverageIntensityData, gpuaverageIntensityDataIndex); //Previously size of array(gpuaverageIntensityData) allocated more which is "sizeofarray". So, now resizing the array(gpuaverageIntensityData) to the size of gpuaverageIntensityDataIndex because remain enteries(elements) are empty(=0) // Now, making 2D-list(gpuprocessedpeaklistdata) from two 1D-lists that are (1D-list of)GPU processed tuple sums OF masses(gpusummationMassData) & (1D-list of)GPU processed tuple sums OF intensities divided by 2(gpuaverageIntensityData) var gpuprocessedpeaklistdata = new List <gpuprocessedmassandintensity>(); List <double> gpuprocessedpeaklist = new List <double>(); //#NECESSARY for (int row = 0; row <= gpuaverageIntensityDataIndex - 1; row++) // -1 (peakData.Mass.Count - 1) because its starting from 0 (rowwise = 0) { double Masses = gpusummationMassData[row]; double Intensities = gpuaverageIntensityData[row]; var dataforgpuprocessedpeaklistdata = new gpuprocessedmassandintensity(Masses, Intensities); gpuprocessedpeaklistdata.Add(dataforgpuprocessedpeaklistdata); } // Sorting gpuprocessedpeaklistdata(2D-list) with respect to the Masses in ascending Order var gpuprocessedpeaklistdatasorted = gpuprocessedpeaklistdata.OrderBy(n => n.Masses).ToList(); // for obtaining Ascending Order list //FIGURE 5: STEP 2:::: SUMMATIONS FOR EACH M/Z I,J IN MS2 DATA [REF: SPCTRUM PAPER] //Description::: Calculate Peak Sums and shortlist those falling within user specified tolerance. var gpushortlistedpeaklist = new List <gpuprocessedmassandintensity>(); for (int rowiselistelements = 0; rowiselistelements <= gpusummationMassDataIndex - 1; rowiselistelements++) { if (peakData.WholeProteinMolecularWeight - molTolerance <= gpuprocessedpeaklistdatasorted[rowiselistelements].Masses && gpuprocessedpeaklistdatasorted[rowiselistelements].Masses <= peakData.WholeProteinMolecularWeight + molTolerance)//Masses & Intensities filter out due to the selected RANGE OF INTACT MASS +/- PROTEIN MASS TOLERANCE { var dataforgpushortlistedpeaklist = new gpuprocessedmassandintensity(gpuprocessedpeaklistdatasorted[rowiselistelements].Masses, gpuprocessedpeaklistdatasorted[rowiselistelements].Intensities); gpushortlistedpeaklist.Add(dataforgpushortlistedpeaklist); } } if (gpushortlistedpeaklist.Count == 0) //numel(Peak.Sums) == 0 #FutureWork2 { // Featuring Baad ma..#FutureWork1 int Tuned_MolWt = 0; int Fragments_SumofMolWt = 0; int Fragments_MaxIntensity = 0; int Histc_Unique_Fragments_MolWt = 0; int Unique_Fragments_Occurrences = 0; } //FIGURE 5: STEP 3 Running window have size of Proton (and starts from smallest mass of FIGURE 5: STEP 2 list) [REF: SPCTRUM PAPER] ///////////// double windowposition = gpushortlistedpeaklist[0].Masses; //Smallest mass selected from Tuple Sums for creating a window positon const double proton = 1.00727647; //Mass of proton var windowcapturedelementsold = new List <gpuprocessedmassandintensity>(); var oldindex = new List <int>(); //CHANGE MY NAME... var count = new List <int>(); //CHANGE MY NAME... double olddiff = 1, newdiff = 0; //HARD CODE NOW FOR WORKING WILL ADD THIS FEATURE INTO THE FRONTEND FOR USER DEFINED #FutureWork3a(GPU)/#HARDCODE - //Add here SliderValue(BELOW) double SliderValueHardCode = 50; double SliderValue = (SliderValueHardCode + peakData.WholeProteinMolecularWeight) / Math.Pow(10, 6);//double SliderValue = 50; // int gpushortlistedpeaklistindex = gpushortlistedpeaklist.Count - 1; while (windowposition < gpushortlistedpeaklist[gpushortlistedpeaklistindex].Masses) //window will run on the gpushortlistedpeaklist ///WHY THIS..?}}}window < gpushortlistedpeaklist[gpushortlistedpeaklistindex].Masses{{{ //windowposition ?? Proper def... { var newindex = new List <int>(); //CHANGE MY NAME... //var windowcapturedelementsnew = new List<double>(); var windowcapturedelementsnew = new List <gpuprocessedmassandintensity>(); for (int i = 0; i <= gpushortlistedpeaklistindex; i++) { if (gpushortlistedpeaklist[i].Masses >= windowposition && gpushortlistedpeaklist[i].Masses < windowposition + proton)// + proton//#DISCUSSION { var dataforwindowcapturedelementsnew = new gpuprocessedmassandintensity(gpushortlistedpeaklist[i].Masses, gpushortlistedpeaklist[i].Intensities); windowcapturedelementsnew.Add(dataforwindowcapturedelementsnew); int counting = windowcapturedelementsnew.Count; //windowcapturedelementsnew.Add(gpushortlistedpeaklist[i].Masses); newindex.Add(i); } else if (gpushortlistedpeaklist[i].Masses >= windowposition + proton) { break; } } count.Add(windowcapturedelementsnew.Count);//CHANGE MY NAME........................................... if (windowcapturedelementsnew.Count > windowcapturedelementsold.Count) { windowcapturedelementsold = windowcapturedelementsnew; oldindex = newindex; } else if (windowcapturedelementsnew.Count == windowcapturedelementsold.Count) { olddiff = Math.Abs((windowcapturedelementsold[windowcapturedelementsold.Count - 1].Masses) - peakData.WholeProteinMolecularWeight); newdiff = Math.Abs((windowcapturedelementsnew[windowcapturedelementsnew.Count - 1].Masses) - peakData.WholeProteinMolecularWeight); if (olddiff >= newdiff) { windowcapturedelementsold = windowcapturedelementsnew; oldindex = newindex; } } windowposition = windowposition + SliderValue; } //FIGURE 5: STEP 5:::: Applying formula [REF: SPCTRUM PAPER] double[] dataforsumoftunedmassesandintensities = new double[windowcapturedelementsold.Count];//Its tunedmassnominator according to SPECTRUM's formula for TunedMass double sumoftunedmassesandintensities = 0; double sumoftunedintensities = 0; for (int i = 0; i <= windowcapturedelementsold.Count - 1; i++) { dataforsumoftunedmassesandintensities[i] = windowcapturedelementsold[i].Masses * windowcapturedelementsold[i].Intensities; sumoftunedmassesandintensities = sumoftunedmassesandintensities + dataforsumoftunedmassesandintensities[i]; //Actually, ""intensities are not tuned"" (there isn't any terminology in OUR Mass Tuner Algorithm) according to the algorithm but just for the sake of UNDERSTANDING variable name is "sumoftunedintensities". sumoftunedintensities = sumoftunedintensities + windowcapturedelementsold[i].Intensities; //Its tunedmassdenominator according to SPECTRUM's formula for TunedMass } peakData.WholeProteinMolecularWeight = sumoftunedmassesandintensities / sumoftunedintensities; // NOW, Tuned Mass will be consider as Intact Mass(WholeProteinMolecularWeight) }
public List <PstTagList> GeneratePeptideSequenceTags(SearchParametersDto parameters, MsPeaksDto peakData) { //Converting Peak List Data into 2D List var peakDatalist = new List <peakData2Dlist>(); //Making a 2D list(peakDatalist) in which Mass & Intensity includes {{FARHAN!! ITS NOT AN EFFICIENT WAY}} NOt NEEDED THIS IF ONCE MsPeaksDto.cs is modified for (int row = 0; row <= peakData.Mass.Count - 1; row++) { var dataforpeakDatalist = new peakData2Dlist(peakData.Mass[row], peakData.Intensity[row]); peakDatalist.Add(dataforpeakDatalist); } var peakDatalistsort = peakDatalist.OrderBy(n => n.Mass).ToArray(); double[] MassPeakData = peakDatalistsort.Select(n => n.Mass).ToArray(); double[] IntensityPeakData = peakDatalistsort.Select(n => n.Intensity).ToArray(); var pstList = new List <NewPstTagsDtoGpu>(); GeneratePstGpu(MassPeakData, pstList, parameters.HopThreshhold, IntensityPeakData); //if (IsFilterPstByLength(parameters)) // pstList = pstList.Where(t => t.AminoAcidTag.Length >= parameters.MinimumPstLength && t.AminoAcidTag.Length <= parameters.MaximumPstLength).ToList(); //FilterTagsWithMultipleOccurences(pstList); ////////////var PstTagListGpu = AccomodateIsoforms(pstList, parameters); //AccomodateIsoforms(pstList); //return pstList; var pstList2 = new List <PstTagList>(); return(pstList2); }