private ResultPtmSite GetResultPtmSitesModel(Guid resId, PostTranslationModificationsSiteDto ptmSite) //ResultPtmSites { var ptmSites = new ResultPtmSite { ResultId = resId.ToString(), AminoAcid = ptmSite.AminoAcid.Aggregate("", (current, t) => current + t), Index = ptmSite.Index, ModName = ptmSite.ModName, ModWeight = ptmSite.ModWeight, Score = ptmSite.Score, Site = ptmSite.Site //#MIGHTGETERROR //Converted it char(char(7000)) to avoiding string (nvarchar(MAX)) //Aik sa zyada modification sites of modifications ho skti hain...? }; return(ptmSites); }
public static void BlindPTM(List <double> experimentalSpectrum, double molW, List <ProteinDto> candidateProteinsList, double pepTol, double userHopThreshold, string pepUnit) { var stopwatch = new Stopwatch(); // Data Preperation and Loading GPU Module stopwatch.Start(); var peaks = new List <double>(); var aminoAcidList = new List <string>(); var modificationList = new List <string>(); var startList = new List <double>(); var endList = new List <double>(); foreach (var peak in experimentalSpectrum) { peaks.Add(peak + 1.00727647); peaks.Add(molW - (peak + 1.00727647)); //peaks.Add(peak); //peaks.Add(molW - (peak)); } peaks.Sort(); GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target); CudafyModule km = CudafyModule.TryDeserialize(); if (km == null || !km.TryVerifyChecksums()) { km = CudafyTranslator.Cudafy(); km.Serialize(); } gpu.LoadModule(km); stopwatch.Stop(); Console.WriteLine("Data Preperation: " + stopwatch.Elapsed); // GPU Module stopwatch.Restart(); var lengthSquared = peaks.Count * peaks.Count; var peaksArray = peaks.ToArray(); var lengthOfPeakList = new int[1]; lengthOfPeakList[0] = peaks.Count; var outputArray = new char[peaks.Count, peaks.Count, 37]; var errorArray = new double[peaks.Count, peaks.Count, 37]; var modMassList = ModificationMass; char[,,] outputArrayDevice = gpu.Allocate(outputArray); double[,,] errorArrayDevice = gpu.Allocate(errorArray); double[] peaksDevice = gpu.Allocate <double>(peaksArray.Length); int[] lengthOfPeakListDevice = gpu.Allocate <int>(lengthOfPeakList.Length); double[] ptmMassListDevice = gpu.Allocate <double>(modMassList.Length); gpu.CopyToDevice(peaksArray, peaksDevice); gpu.CopyToDevice(lengthOfPeakList, lengthOfPeakListDevice); gpu.CopyToDevice(ModificationMass, ptmMassListDevice); int block = (int)Math.Ceiling((double)lengthSquared * 37 / N); gpu.Launch(block, N).PtmExtractor(peaksDevice, lengthOfPeakListDevice, ptmMassListDevice, outputArrayDevice, errorArrayDevice); gpu.CopyFromDevice(outputArrayDevice, outputArray); gpu.CopyFromDevice(errorArrayDevice, errorArray); gpu.FreeAll(); for (var i = 0; i < peaks.Count; i++) { for (var j = 0; j < peaks.Count; j++) { for (var k = 0; k < 37; k++) { if (outputArray[i, j, k] == '\0') { continue; } aminoAcidList.Add(ModificationAminoAcids[outputArray[i, j, k]].ToString()); modificationList.Add(ModificationName[outputArray[i, j, k]]); startList.Add(peaks[i]); endList.Add(peaks[j]); } } } stopwatch.Stop(); Console.WriteLine("GPU Generation: " + stopwatch.Elapsed); // PTM Shortlisting stopwatch.Restart(); foreach (var protein in candidateProteinsList) { var sequence = protein.Sequence.ToCharArray(); var hopI = 0; var thrI = 0; var shortlistedAminoAcid = new List <string>(); var shortlistedModification = new List <string>(); var shortlistedEnd = new List <double>(); var shortlistedStart = new List <double>(); var shortlistedIndex = new List <int>(); while (true) { try { if (startList.Count > 0) { if (shortlistedStart.Count > 0) { if (shortlistedEnd[shortlistedEnd.Count - 1] > startList[hopI]) { hopI = hopI + 1; if (hopI == startList.Count) { break; } continue; } } var diff = startList[hopI] - protein.InsilicoDetails.InsilicoMassLeft[thrI]; if (diff <= userHopThreshold && diff >= -userHopThreshold) { if (aminoAcidList[hopI] == sequence[thrI + 2].ToString()) { var temproray = modificationList[hopI].Split('_'); var modMass = AminoAcids.ModificationTable(temproray[0]); //var modMass = AminoAcids.ModTable(modificationList[hopI]); diff = Math.Abs(endList[hopI] - (protein.InsilicoDetails.InsilicoMassLeft[thrI + 1 ] + modMass)); if (string.Compare(pepUnit, "ppm", StringComparison.Ordinal) == 0) { diff = (diff / molW) * 1000000; } else if (string.Compare(pepUnit, "%", StringComparison.Ordinal) == 0) { diff = (diff / molW) * 100; } if (diff < pepTol) { for (var i = thrI + 1; i < protein.InsilicoDetails.InsilicoMassLeft.Count; i++) { protein.InsilicoDetails.InsilicoMassLeft[i] = protein.InsilicoDetails.InsilicoMassLeft[i] + modMass; } protein.Mw = protein.Mw + modMass; shortlistedAminoAcid.Add(aminoAcidList[hopI]); shortlistedModification.Add(modificationList[hopI]); shortlistedEnd.Add(endList[hopI]); shortlistedStart.Add(startList[hopI]); shortlistedIndex.Add(thrI); } } } else if (diff > userHopThreshold) { thrI = thrI + 1; if (thrI == protein.InsilicoDetails.InsilicoMassLeft.Count - 1) { break; } continue; } else if (diff < -userHopThreshold) { hopI = hopI + 1; if (hopI == startList.Count) { break; } continue; } hopI = hopI + 1; if (hopI == startList.Count) { break; } } } catch (Exception exception) { Debug.WriteLine(exception.Message); } } for (var hopIndex = 0; hopIndex < shortlistedStart.Count; hopIndex++) { var site = new PostTranslationModificationsSiteDto { Index = shortlistedIndex[hopIndex], ModName = shortlistedModification[hopIndex], ModWeight = AminoAcids.ModificationTable(shortlistedModification[hopIndex]), Site = Convert.ToChar(shortlistedAminoAcid[hopIndex]) }; protein.PtmParticulars.Add(site); } var massError = Math.Abs(molW - protein.Mw); protein.MwScore = Math.Abs(massError) < 0 ? 1 : Math.Pow(massError, 0.5); } stopwatch.Stop(); Console.WriteLine("Shortlisting :" + stopwatch.Elapsed); }
public static void BlindPTM(List <double> experimentalSpectrum, double molW, List <ProteinDto> candidateProteinsList, double pepTol, double userHopThreshold, string pepUnit) { var stopwatch = new Stopwatch(); // Data Preperation stopwatch.Start(); var peaks = new List <double>(); foreach (var peak in experimentalSpectrum) { peaks.Add(peak + 1.00727647); peaks.Add(molW - (peak + 1.00727647)); //peaks.Add(peak); //peaks.Add(molW - (peak)); } peaks.Sort(); stopwatch.Stop(); Console.WriteLine("Data Preperation: " + stopwatch.Elapsed); // PTM Extraction stopwatch.Restart(); var aminoAcidList = new List <string>(); var modificationList = new List <string>(); var startList = new List <double>(); var endList = new List <double>(); for (var expI = 0; expI < peaks.Count; expI++) { for (var expJ = expI + 1; expJ < peaks.Count; expJ++) { var peakDiff = peaks[expJ] - peaks[expI]; var modification = AminoAcids.GetModifiedAminoAcid(peakDiff, userHopThreshold); foreach (var mod in modification) { var temproray = mod.Split('_'); if (temproray.Length <= 1) { continue; } aminoAcidList.Add(temproray[1]); modificationList.Add(temproray[0]); startList.Add(peaks[expI]); endList.Add(peaks[expJ]); } } } stopwatch.Stop(); Console.WriteLine("Generation: " + stopwatch.Elapsed); // PTM Shortlisting stopwatch.Restart(); foreach (var protein in candidateProteinsList) { var sequence = protein.Sequence; var hopIndex = 0; var thrI = 0; var shortlistedAminoAcid = new List <string>(); var shortlistedModification = new List <string>(); var shortlistedEnd = new List <double>(); var shortlistedStart = new List <double>(); var shortlistedIndex = new List <int>(); while (true) { try { if (startList.Count > 0) { if (shortlistedStart.Count > 0) { if (shortlistedEnd[shortlistedEnd.Count - 1] > startList[hopIndex]) { hopIndex = hopIndex + 1; if (hopIndex == startList.Count) { break; } continue; } } var diff = startList[hopIndex] - protein.InsilicoDetails.InsilicoMassLeft[thrI]; if (diff <= userHopThreshold && diff >= -userHopThreshold) { if (aminoAcidList[hopIndex] == sequence[thrI + 2].ToString()) { var modMass = AminoAcids.ModificationTable(modificationList[hopIndex]); diff = Math.Abs(endList[hopIndex] - (protein.InsilicoDetails.InsilicoMassLeft[thrI + 1 ] + modMass)); if (string.Compare(pepUnit, "ppm", StringComparison.Ordinal) == 0) { diff = (diff / molW) * 1000000; } else if (string.Compare(pepUnit, "%", StringComparison.Ordinal) == 0) { diff = (diff / molW) * 100; } if (diff < pepTol) { for (var i = thrI + 1; i < protein.InsilicoDetails.InsilicoMassLeft.Count; i++) { protein.InsilicoDetails.InsilicoMassLeft[i] = protein.InsilicoDetails.InsilicoMassLeft[i] + modMass; } protein.Mw = protein.Mw + modMass; shortlistedAminoAcid.Add(aminoAcidList[hopIndex]); shortlistedModification.Add(modificationList[hopIndex]); shortlistedEnd.Add(endList[hopIndex]); shortlistedStart.Add(startList[hopIndex]); shortlistedIndex.Add(thrI); } } } else if (diff > userHopThreshold) { thrI = thrI + 1; if (thrI == protein.InsilicoDetails.InsilicoMassLeft.Count - 1) { break; } continue; } else if (diff < -userHopThreshold) { hopIndex = hopIndex + 1; if (hopIndex == startList.Count) { break; } continue; } hopIndex = hopIndex + 1; if (hopIndex == startList.Count) { break; } } } catch (Exception exception) { Debug.WriteLine(exception.Message); } } for (var hopIter = 0; hopIter < shortlistedStart.Count; hopIter++) { var site = new PostTranslationModificationsSiteDto { Index = shortlistedIndex[hopIter], ModName = shortlistedModification[hopIter], ModWeight = AminoAcids.ModificationTable(shortlistedModification[hopIter]), Site = Convert.ToChar(shortlistedAminoAcid[hopIter]) }; protein.PtmParticulars.Add(site); } var massError = Math.Abs(molW - protein.Mw); protein.MwScore = Math.Abs(massError) < 0 ? 1 : Math.Pow(massError, 0.5); } stopwatch.Stop(); Console.WriteLine("Shortlisting :" + stopwatch.Elapsed); }