private void ValidateIon() { if (IonAddButton is null || ionTable is null) { return; } if (IonNameTextbox.Text == "") { Message("Invalid Ion", "Ion name cannot be blank"); return; } bool userEnteredIonNameIsValid = ionTable.Lookup(IonNameTextbox.Text).isValid; IonLoadButton.IsEnabled = userEnteredIonNameIsValid; Ion ion = GetIonFromUserValues(); if (ion != null && ion.isValid) { // modify gui to indicate ion is valid IonMobilityTextbox.Text = Math.Round(ion.mu * 1e-11, 4).ToString(); IonAddButton.IsEnabled = true; ValidateIonSet(); } else { IonAddButton.IsEnabled = false; IonMobilityTextbox.Text = ""; } }
public IEnumerable <int> GetMatchingMs2ScanNums(double sequenceMass) { var sequenceMassBinNum = ProductScorerBasedOnDeconvolutedSpectra.GetBinNumber(sequenceMass); IList <int> ms2ScanNums; if (_sequenceMassBinToScanNumsMap.TryGetValue(sequenceMassBinNum, out ms2ScanNums)) { return(ms2ScanNums); } ms2ScanNums = new List <int>(); var averagineEnvelope = Averagine.GetIsotopomerEnvelope(sequenceMass); var mostAbundantIsotopeIndex = averagineEnvelope.MostAbundantIsotopeIndex; for (var precursorCharge = _minCharge; precursorCharge <= _maxCharge; precursorCharge++) { var mostAbundantIsotopeMz = Ion.GetIsotopeMz(sequenceMass, precursorCharge, mostAbundantIsotopeIndex); var binNumber = ProductScorerBasedOnDeconvolutedSpectra.GetBinNumber(mostAbundantIsotopeMz); IList <ChargeAndScanNum> chargeAndScanNumList; if (!_mostAbundantIsotopeMzIndexToChargeAndScanNums.TryGetValue(binNumber, out chargeAndScanNumList)) { continue; } foreach (var chargeAndScanNum in chargeAndScanNumList) { if (chargeAndScanNum.Charge == precursorCharge) { ms2ScanNums.Add(chargeAndScanNum.ScanNum); } } } _sequenceMassBinToScanNumsMap.Add(sequenceMassBinNum, ms2ScanNums); return(ms2ScanNums); }
public void GetIsoProfile() { var methodName = MethodBase.GetCurrentMethod().Name; Utils.ShowStarting(methodName); const string protSequence = "AIPQSVEGQSIPSLAPMLERTTPAVVSVAVSGTHVSKQRVPDVFRYFFGPNAPQEQVQERPFRGLGSGVIIDADKGYIVTNNHVIDGADDIQVGLHDGREVKAKLIGTDSESDIALLQIEAKNLVAIKTSDSDELRVGDFAVAIGNPFGLGQTVTSGIVSALGRSGLGIEMLENFIQTDAAINSGNSGGALVNLKGELIGINTAIVAPNGGNVGIGFAIPANMVKNLIAQIAEHGEVRRGVLGIAGRDLDSQLAQGFGLDTQHGGFVNEVSAGSAAEKAGIKAGDIIVSVDGRAIKSFQELRAKVATMGAGAKVELGLIRDGDKKTVNVTLGEANQTTEKAAGAVHPMLQGASLENASKGVEITDVAQGSPAAMSGLQKGDLIVGINRTAVKDLKSLKELLKDQEGAVALKIVRGKSMLYLVLR"; //const string annotation = "_." + protSequence + "._"; var seqGraph = SequenceGraph.CreateGraph(new AminoAcidSet(), AminoAcid.ProteinNTerm, protSequence, AminoAcid.ProteinCTerm); if (seqGraph == null) { return; } seqGraph.SetSink(0); var neutral = seqGraph.GetSinkSequenceCompositionWithH2O() - Composition.Hydrogen; //Console.WriteLine(neutral); for (var charge = 22; charge <= 60; charge++) { var ion = new Ion(neutral, charge); Console.WriteLine("{0}\t{1}", charge, ion.GetMostAbundantIsotopeMz()); } var ion27 = new Ion(neutral, 29); var isotopes = ion27.GetIsotopes(0.1); foreach (var isotope in isotopes) { Console.WriteLine("{0}\t{1}", ion27.GetIsotopeMz(isotope.Index), isotope.Ratio); } }
// Feature, precursorScore, totalScore public Tuple<Feature, double, double> GetBestFeatureAndScore(int precursorCharge) { var precursorIon = new Ion(_sequenceComposition + Composition.H2O, precursorCharge); var imsScorer = _imsScorerFactory.GetImsScorer(_imsData, precursorIon); var precursorFeatureSet = _imsData.GetPrecursorFeatures(precursorIon.GetMz()); var bestPrecursorScore = double.NegativeInfinity; var bestScore = double.NegativeInfinity; Feature bestFeature = null; foreach (var precursorFeature in precursorFeatureSet) { var precursorScore = imsScorer.GetPrecursorScore(precursorFeature); if (precursorScore < PrecursorScoreThreshold) continue; var productScore = GetProductIonScore(imsScorer, precursorFeature); var curFeatureScore = precursorScore + productScore; if (curFeatureScore > bestScore) { bestPrecursorScore = precursorScore; bestScore = curFeatureScore; bestFeature = precursorFeature; } } return new Tuple<Feature, double, double>(bestFeature, bestPrecursorScore, bestScore); }
private Ion GetIonFromUserValues() { try { int charge = int.Parse(IonChargeTextbox.Text); if (charge == 0) { Message("Invalid Ion", "Ion charge cannot be zero"); return(null); } double conductivity = double.Parse(IonConductivityTextbox.Text) * 1e-4; if (conductivity <= 0) { Message("Invalid Ion", "Conductivity must be greater than zero"); return(null); } double c0 = double.Parse(IonC0Textbox.Text); if (c0 < 0) { Message("Invalid Ion", "Concentrations must be greater than zero"); return(null); } double cL = double.Parse(IonCLTextbox.Text); if (cL < 0) { Message("Invalid Ion", "Concentrations must be greater than zero"); return(null); } Ion ion = new Ion(IonNameTextbox.Text, charge, conductivity, c0, cL); return(ion); } catch { } return(null); }
public override double GetFragmentScore(Composition prefixFragmentComposition, Composition suffixFragmentComposition) { var score = 0.0; foreach (var baseIonType in BaseIonTypes) { var fragmentComposition = baseIonType.IsPrefix ? prefixFragmentComposition + baseIonType.OffsetComposition : suffixFragmentComposition + baseIonType.OffsetComposition; if (fragmentComposition.Mass < Ms2Spectrum.Peaks[0].Mz) { continue; } var chargeRange = GetMinMaxChargeRange(fragmentComposition); var containsIon = false; for (var charge = chargeRange.Min; charge <= chargeRange.Max; charge++) { var ion = new Ion(fragmentComposition, charge); if (Ms2Spectrum.GetCorrScore(ion, Tolerance) > _corrScoreThreshold) { containsIon = true; break; } } if (containsIon) { score += 1.0; } } return(score); }
/// <summary> /// Calculate M/Z error of peaks in isotope envelope. /// </summary> /// <param name="peaks">The peaks to calculate error for.</param> /// <param name="ion">The ion to calculate theoretical isotope envelope for.</param> /// <param name="relativeIntensityThreshold">Relative intensity threshold for calculating isotopes</param> /// <param name="deconvoluted"></param> /// <returns>Array of ppm errors for each peak.</returns> public static double?[] GetIsotopePpmError(Peak[] peaks, Ion ion, double relativeIntensityThreshold, bool deconvoluted = false) { double?[] ppmErrors; if (!deconvoluted) { var isotopes = ion.GetIsotopes(relativeIntensityThreshold).ToArray(); ppmErrors = new double?[isotopes.Max(i => i.Index) + 1]; foreach (var isotope in isotopes) { var isotopeIndex = isotope.Index; if (peaks[isotopeIndex] == null) { ppmErrors[isotopeIndex] = null; } else { ppmErrors[isotopeIndex] = GetPeakPpmError(peaks[isotopeIndex], ion.GetIsotopeMz(isotopeIndex)); } } } else { var mz = ion.Composition.Mass; ppmErrors = new double?[1]; ppmErrors[0] = GetPeakPpmError(peaks[0], mz); } return(ppmErrors); }
public void TestIsotopemerProfileByKyowon() // is faster and more accurate than IsotopicDistributionCalculator { var methodName = MethodBase.GetCurrentMethod().Name; ShowStarting(methodName); //C78H120N22O28S3 C150H120N220O28S30 //var additionalElements = new[] // { // new Tuple<Atom, short>(Atom.Get("P"), 1), // new Tuple<Atom, short>(Atom.Get("13C"), 3), // new Tuple<Atom, short>(Atom.Get("15N"), 1), // }; //var composition = new Composition(149, 244, 44, 57, 0, additionalElements); // var composition = new Composition(83, 136, 22, 24, 1); //var composition = new Composition(210, 323, 54, 61, 0); var composition = new Composition(419, 699, 119, 129, 1); const int charge = 14; var ion = new Ion(composition + Composition.H2O, charge); var ff = composition.GetIsotopomerEnvelopeRelativeIntensities(); var isotopeIndex = -1; foreach (var ii in ff) { ++isotopeIndex; Console.WriteLine("{0}: {1}\t{2}", isotopeIndex, ion.GetIsotopeMz(isotopeIndex), ii); } }
public void Test_BadOrder_FixedByAutoSort002() { /* Known to crash due to poor ion order https://github.com/swharden/LJPcalc/issues/9 */ // fixed by autoSort prior to calculation var ionSet = new Ion[] { new Ion("K", 145, 2.8), new Ion("Na", 13, 145), new Ion("Cl", 10, 148.8), new Ion("Gluconate", 145, 0), new Ion("Mg", 1, 2), new Ion("Ca", 0, 1), new Ion("HEPES", 5, 5), }; ionSet = IonLibrary.Lookup(ionSet); // it does not solve in this order LjpResult result = LjpCalculator.SolvePhisThenCalculateLjp(ionSet, autoSort: false, maxIterations: 123); Assert.That(result.Iterations, Is.EqualTo(123)); // but it does solve if allowed to auto-sort LjpResult result2 = LjpCalculator.SolvePhisThenCalculateLjp(ionSet, autoSort: true, maxIterations: 123); Assert.That(result2.LjpMillivolts, Is.EqualTo(16.3).Within(0.5)); }
private async Task showData(string pageName) { try { IonPage page = await Ion.getInstance(AppController.instance.ampConfig).getPageAsync(pageName); _allContent = DataConverters.convertContent(page.getContents()); // Load files for page content await Ion.getInstance(AppController.instance.ampConfig).loadContentFilesAsync(_allContent); //await Ion.getInstance( AppController.instance.ampConfig ).DownloadSearchDatabase(); //List<SearchResult> results = await Ion.getInstance( AppController.instance.ampConfig ).FullTextSearch("test", "de_DE"); // Set the data context of the lists imageContentList.DataContext = _allContent.imageContent; textContentList.DataContext = _allContent.textContent; colorContentList.DataContext = _allContent.colorContent; flagContentList.DataContext = _allContent.flagContent; fileContentList.DataContext = _allContent.fileContent; mediaContentList.DataContext = _allContent.mediaContent; dateTimeContentList.DataContext = _allContent.dateTimeContent; optionContentList.DataContext = _allContent.optionContent; } catch (Exception exception) { // Error handling, if no data could be loaded Debug.WriteLine("Error loading page: " + exception.Message); } setDataLoaded(); initPage(); }
private void CommandAdd(string suffix) { try { Ion ion = null; string[] parts = suffix.Split(' '); if (parts.Length == 3) { ion = new Ion(parts[0], double.Parse(parts[1]), double.Parse(parts[2])); ion = ionTable.Lookup(ion); } else if (parts.Length == 4) { ion = new Ion(parts[0], int.Parse(parts[1]), double.Parse(parts[2]), double.Parse(parts[3]), double.Parse(parts[4])); } if (ion is null) { throw new ArgumentException(); } Console.WriteLine($"Adding {ion}"); ionSet.Add(ion); } catch { CommandArgumentError(); } }
public static MassCalibrationResults RunMassCalibration(IEnumerable <Lipid> lipidList, LcMsRun lcmsRun, double hcdMassError, IProgress <int> progress = null) { var ppmErrorList = new List <double>(); var lipidsGroupedByTarget = lipidList.OrderBy(x => x.LipidTarget.Composition.Mass).GroupBy(x => x.LipidTarget).ToList(); foreach (var kvp in lipidsGroupedByTarget) { var target = kvp.Key; var spectrumSearchResultList = InformedWorkflow.RunInformedWorkflow(target, lcmsRun, hcdMassError, 500, scoreModel: null); if (spectrumSearchResultList.Any()) { var targetIon = new Ion(target.Composition - Composition.Hydrogen, 1); var targetMz = targetIon.GetMonoIsotopicMz(); var bestSpectrumSearchResult = spectrumSearchResultList.OrderBy(x => x.Score).First(); var massSpectrum = bestSpectrumSearchResult.PrecursorSpectrum.Peaks; var closestPeak = massSpectrum.OrderBy(x => Math.Abs(x.Mz - targetMz)).First(); var ppmError = LipidUtil.PpmError(targetMz, closestPeak.Mz); ppmErrorList.Add(ppmError); } } var ppmHistogram = QcUtil.CalculateHistogram(ppmErrorList, hcdMassError, 0.25); var massCalibrationResults = new MassCalibrationResults(ppmHistogram); return(massCalibrationResults); }
public void Test_BadOrder_FixedByAutoSort001() { /* Known to crash due to poor ion order https://github.com/swharden/LJPcalc/issues/9 */ // fixed by autoSort prior to calculation var ionSet = new Ion[] { new Ion("Zn", 9, .0284), new Ion("K", 0, 3), new Ion("Cl", 18, 3.062), new Ion("Mg", 5, 3), new Ion("Ag", 1, 1), }; ionSet = IonLibrary.Lookup(ionSet); // it does not solve in this order LjpResult result = LjpCalculator.SolvePhisThenCalculateLjp(ionSet, autoSort: false, maxIterations: 123); Assert.That(result.Iterations, Is.EqualTo(123)); // but it does solve if allowed to auto-sort LjpResult result2 = LjpCalculator.SolvePhisThenCalculateLjp(ionSet, autoSort: true, maxIterations: 123); Assert.That(result2.LjpMillivolts, Is.EqualTo(-11.9).Within(0.5)); }
public void Test_DifficultSet_Owen2013() { // This ion set came from https://www.nature.com/articles/nature12330 var ionSet = new Ion[] { new Ion("K", 50, 3), new Ion("Gluconate", 50, 0), new Ion("Cs", 70, 0), new Ion("HSO3", 70, 0), new Ion("TEA (TetraethylAmmonium)", 10, 10), new Ion("Cl", 12, 131.6), new Ion("Mg", 5, 1.3), new Ion("HEPES", 10, 0), new Ion("EGTA(2-)", .3, 0), new Ion("Tris", 10, 0), new Ion("ATP (Adenosine 5'-Triphosphate)", 4, 0), new Ion("Na", 0.3, 139.25), new Ion("HCO3", 0, 26), new Ion("H2PO4", 0, 1.25), new Ion("Ca", 0, 2), new Ion("4-AP (4-aminopyridine)", 0, 5), }; ionSet = IonLibrary.Lookup(ionSet); LjpResult ljp = LjpCalculator.SolvePhisThenCalculateLjp(ionSet, temperatureC: 33); Assert.That(ljp.LjpMillivolts, Is.EqualTo(15.1 - 3.3).Within(0.5)); }
public GroupParameter GetGroupParameter(Sequence annotation, int cutNumber) { var precursorIon = new Ion(annotation.Composition + Composition.H2O, Charge); var prefixComposition = annotation.GetComposition(0, cutNumber); return(new GroupParameter(prefixComposition, annotation[cutNumber - 1].Residue, annotation[cutNumber].Residue, precursorIon)); }
public override double GetFragmentScore(Composition prefixFragmentComposition, Composition suffixFragmentComposition, AminoAcid nTerminalResidue = null, AminoAcid cTerminalResidue = null) { var score = 0.0; foreach (var baseIonType in BaseIonTypes) { var fragmentComposition = baseIonType.IsPrefix ? prefixFragmentComposition + baseIonType.OffsetComposition : suffixFragmentComposition + baseIonType.OffsetComposition; var observedCharge = 0; var envelopeCorr = 0d; var envelopeDist = 0d; var mostAbundantIsotopeIndex = fragmentComposition.GetMostAbundantIsotopeZeroBasedIndex(); var observedPeaks = FindMostIntensePeak(fragmentComposition, CorrThreshold, DistThreshold, out observedCharge, out envelopeCorr, out envelopeDist); var fragmentIonMass = fragmentComposition.Mass; if (observedPeaks == null) { continue; } var observedMostAbuPeak = observedPeaks[mostAbundantIsotopeIndex]; var observedMass = Ion.GetMonoIsotopicMass(observedMostAbuPeak.Mz, observedCharge, mostAbundantIsotopeIndex); var massErrorPpm = (Math.Abs(observedMass - fragmentIonMass) / fragmentIonMass) * 1e6; score += 1; var intScore = (observedMostAbuPeak.Intensity / _refIntensity) * 10; var corrScore = (fragmentIonMass > 1300 & envelopeCorr > 0.7) ? (envelopeCorr - 0.7) : 0; var distScore = (fragmentIonMass > 1300 & envelopeDist < 0.07) ? 0.3 - 3.75 * envelopeDist : 0; score += intScore; score += corrScore; score += distScore; if (_includeMassErrorScore) { /*score += _model.GetNodeScore(Ms2Spectrum.ActivationMethod, baseIonType.IsPrefix, * fragmentIonMass, observedCharge, * envelopeCorr, envelopeDist, * observedMostAbuPeak.Intensity / _refIntensity, massErrorPpm); */ var massErrorScore = GetMassErrorScore(massErrorPpm); score += massErrorScore; } else { /*score += _model.GetNodeScoreWithoutMassError(Ms2Spectrum.ActivationMethod, baseIonType.IsPrefix, * fragmentIonMass, observedCharge, * envelopeCorr, envelopeDist, * observedMostAbuPeak.Intensity / _refIntensity); */ } //score += _model.GetScore(baseIonType, bestCorrScore, bestObsIntensity); } return(score); }
public override string ToString() { if (Equals(EMPTY)) { return(string.Empty); } return(Ion.ToTSV().Replace(TextUtil.SEPARATOR_TSV_STR, @" ") + @" " + Comment); }
private void AddIon(object sender, RoutedEventArgs e) { Ion ion = GetIonFromUserValues(); ionSet.Add(ion); dataGrid1.Items.Refresh(); ValidateIonSet(); }
public Salz(Kation kation, Anion anion) { Kation = kation; Anion = anion; (int anzahlKation, int anzahlAnionen)benoetigeMolekuehle = Ion.BerechneAnzahlMolekuele(kation, anion); Kation.Molekuel.Anzahl = benoetigeMolekuehle.anzahlKation; Anion.Molekuel.Anzahl = benoetigeMolekuehle.anzahlAnionen; if (Anion.Molekuel.Atombindung.IstElementbindung()) { if (!String.IsNullOrEmpty(Anion.Molekuel.Atombindung.ErhalteElement().Wurzel)) { Name = Kation.Molekuel.Atombindung.Name + Anion.Molekuel.Atombindung.ErhalteElement().Wurzel.ToLower() + "id"; } else { Name = Kation.Molekuel.Atombindung.Name + Anion.Molekuel.Atombindung.ErhalteElement().Name.ToLower() + "id"; } } else { Name = Kation.Molekuel.Atombindung.Name + Anion.Molekuel.Atombindung.Name.ToLower(); } if (Kation.Molekuel.Anzahl > 1) { if (Kation.Molekuel.Atombindung.IstElementbindung()) { ChemischeFormel += $"{Kation.Molekuel.Atombindung.ChemischeFormel}{UnicodeHelfer.GetSubscriptOfNumber(Kation.Molekuel.Anzahl)}"; } else { ChemischeFormel += $"({Kation.Molekuel.Atombindung.ChemischeFormel}){UnicodeHelfer.GetSubscriptOfNumber(Kation.Molekuel.Anzahl)}"; } } else { ChemischeFormel += $"{Kation.Molekuel.Atombindung.ChemischeFormel}"; } if (Anion.Molekuel.Anzahl > 1) { if (UnicodeHelfer.GetNumberOfSubscript(Anion.Molekuel.Atombindung.ChemischeFormel.Last()) != -1) { ChemischeFormel += $"({Anion.Molekuel.Atombindung.ChemischeFormel}){UnicodeHelfer.GetSubscriptOfNumber(Anion.Molekuel.Anzahl)}"; } else { ChemischeFormel += $"{Anion.Molekuel.Atombindung.ChemischeFormel}{UnicodeHelfer.GetSubscriptOfNumber(Anion.Molekuel.Anzahl)}"; } } else { ChemischeFormel += $"{Anion.Molekuel.Atombindung.ChemischeFormel}"; } }
private async void archiveDownloadButton_Click(object sender, RoutedEventArgs e) { Debug.WriteLine("Starting extraction"); archiveDownloadProgressRing.IsActive = true; await Ion.getInstance(_ampConfig).loadArchive("https://lookbook-dev.anfema.com/client/v1/de_DE/lookbook.tar?variation=default"); archiveDownloadProgressRing.IsActive = false; Debug.WriteLine("Extraction finished"); }
public override int GetHashCode() { unchecked { var hashCode = Ion.GetHashCode(); hashCode = (hashCode * 397) ^ (Comment != null ? Comment.GetHashCode() : 0); return(hashCode); } }
} // max index for _theoreticalIsotopomerEnvelope, not for this private IsotopomerFeatures(ImsDataCached imsData, Ion ion, Feature precursorFeature, bool isPrecurosr) { // BinningMultiplyFactor = 6; if (ion.Charge >= 3) { BinningMultiplyFactor = 1; } //else if (ion.Charge == 1) BinningMultiplyFactor = 6; //else if (ion.Charge == 2) BinningMultiplyFactor = 2; else { BinningMultiplyFactor = 2; } var te = ion.Composition.GetIsotopomerEnvelopeRelativeIntensities(); TheoreticalIsotopomerEnvelope = new double[(te.Length + FeatureNode.OffsetFromMonoIsotope) * BinningMultiplyFactor]; for (var i = FeatureNode.OffsetFromMonoIsotope; i < te.Length + FeatureNode.OffsetFromMonoIsotope; i++) { TheoreticalIsotopomerEnvelope[i * BinningMultiplyFactor] = te[i - FeatureNode.OffsetFromMonoIsotope]; } MaxIntensityIndex = GetMaximumIndex(TheoreticalIsotopomerEnvelope); // var start = -FeatureNode.OffsetFromMonoIsotope * BinningMultiplyFactor; for (var i = start; i < TheoreticalIsotopomerEnvelope.Length + start; i++) { var mz = ion.GetIsotopeMz((float)i / BinningMultiplyFactor); if (isPrecurosr) { if (mz > imsData.MaxPrecursorMz || mz < imsData.MinPrecursorMz) { Add(null); } else { Add(imsData.GetPrecursorFeature(mz, precursorFeature)); } } else { if (mz > imsData.MaxFragmentMz || mz < imsData.MinFragmentMz) { Add(null); } else { Add(imsData.GetFramentFeature(mz, precursorFeature)); } //var tt = imsData.GetFramentFeature(mz, precursorFeature); // if(mz == 361.198813765) // Console.WriteLine(mz + " " + (tt == null ? "NULL" : tt.GetHighestPoint().ToString())); } } }
public async Task <IActionResult> GetIon(int?skip, int?top, string columns, DateTime?DATEPRD, string WELL_BORE_CODE) { int s = (skip == null) ? 0 : skip.GetValueOrDefault(); int t = (top == null) ? 1000 : top.GetValueOrDefault(); if (s < 0) { return(BadRequest("Skip can't be a negative number")); } if (t < 1) { return(BadRequest("Top can't be less then 1")); } if (columns != null) { columns = columns.Replace(" ", ""); } /* This section is used to check the existence of columns suplied in the request, * and in the event of no columns being supplied finds a list of each column of the given model. */ Ion obj = new Ion(); var cols = obj.GetType().GetProperties().Select(e => e.Name.ToUpper()).ToArray(); if (columns == null) { columns = string.Join(",", cols); } else { string[] colSplit = columns.Split(','); foreach (string col in colSplit) { if (!cols.Contains(col.Trim().ToUpper())) { return(BadRequest(col + " is not a valid column")); } } } /* This section takes care of the db request. * Here Linq.Dynamic.Core is used to dynamically select specific columns. */ var result = _db.Ion .Where(e => (e.DATEPRD >= DATEPRD || DATEPRD == null) && (e.WELL_BORE_CODE == WELL_BORE_CODE || WELL_BORE_CODE == null) ) .Skip(s) .Take(t) .Select("new(" + columns + ")"); return(Ok(await result.ToDynamicListAsync())); }
private FlankingMassMatch GetBestMatchInTheGraph(ShiftedSequenceGraph seqGraph, ProductSpectrum spec, double?featureMass) { FlankingMassMatch match = null; var bestScore = double.NegativeInfinity; var protCompositions = seqGraph.GetSequenceCompositions(); for (var modIndex = 0; modIndex < protCompositions.Length; modIndex++) { seqGraph.SetSink(modIndex); var protCompositionWithH2O = seqGraph.GetSinkSequenceCompositionWithH2O(); var sequenceMass = protCompositionWithH2O.Mass; if (featureMass != null && !_tolerance.IsWithin(sequenceMass, (double)featureMass)) { continue; } var charge = (int) Math.Round(sequenceMass / (spec.IsolationWindow.IsolationWindowTargetMz - Constants.Proton)); var mostAbundantIsotopeMz = Ion.GetIsotopeMz(sequenceMass, charge, Averagine.GetIsotopomerEnvelope(sequenceMass).MostAbundantIsotopeIndex); if (!spec.IsolationWindow.Contains(mostAbundantIsotopeMz)) { continue; } //var feature = new TargetFeature(sequenceMass, charge, spec.ScanNum); if (_featureFinder != null) { var ms1Corr = _featureFinder.GetMs1EvidenceScore(spec.ScanNum, sequenceMass, charge); if (ms1Corr < Ms1CorrThreshold) { continue; } } var curScoreAndModifications = seqGraph.GetScoreAndModifications(_ms2Scorer); var curScore = curScoreAndModifications.Item1; // var curScore = seqGraph.GetFragmentScore(_ms2Scorer); if (curScore > bestScore) { match = new FlankingMassMatch(curScore, sequenceMass - Composition.H2O.Mass - seqGraph.ShiftMass, charge, curScoreAndModifications.Item2); //match = new FlankingMassMatch(curScore, // sequenceMass - Composition.H2O.Mass - seqGraph.ShiftMass, charge, new ModificationInstance[0]); bestScore = curScore; } } return(match); }
public void TestSumIsoProfilesAcrossDifferentCharges() { var methodName = MethodBase.GetCurrentMethod().Name; Utils.ShowStarting(methodName); if (!File.Exists(TestRawFilePath)) { Assert.Ignore(@"Skipping test " + methodName + @" since file not found: " + TestRawFilePath); } var run = PbfLcMsRun.GetLcMsRun(TestRawFilePath) as PbfLcMsRun; //var spec = run.GetSpectrum(46452); // 635.37 var spec = run.GetSummedMs1Spectrum(46437, 46466); var tolerance = new Tolerance(10); const string protSequence = "AIPQSVEGQSIPSLAPMLERTTPAVVSVAVSGTHVSKQRVPDVFRYFFGPNAPQEQVQERPFRGLGSGVIIDADKGYIVTNNHVIDGADDIQVGLHDGREVKAKLIGTDSESDIALLQIEAKNLVAIKTSDSDELRVGDFAVAIGNPFGLGQTVTSGIVSALGRSGLGIEMLENFIQTDAAINSGNSGGALVNLKGELIGINTAIVAPNGGNVGIGFAIPANMVKNLIAQIAEHGEVRRGVLGIAGRDLDSQLAQGFGLDTQHGGFVNEVSAGSAAEKAGIKAGDIIVSVDGRAIKSFQELRAKVATMGAGAKVELGLIRDGDKKTVNVTLGEANQTTEKAAGAVHPMLQGASLENASKGVEITDVAQGSPAAMSGLQKGDLIVGINRTAVKDLKSLKELLKDQEGAVALKIVRGKSMLYLVLR"; //const string annotation = "_." + protSequence + "._"; var seqGraph = SequenceGraph.CreateGraph(new AminoAcidSet(), AminoAcid.ProteinNTerm, protSequence, AminoAcid.ProteinCTerm); if (seqGraph == null) { return; } seqGraph.SetSink(0); var neutral = seqGraph.GetSinkSequenceCompositionWithH2O(); var theoProfile = neutral.GetIsotopomerEnvelopeRelativeIntensities(); var expProfile = new double[theoProfile.Length]; for (var charge = 22; charge <= 45; charge++) { var ion = new Ion(neutral, charge); var isotopePeaks = spec.GetAllIsotopePeaks(ion, tolerance, 0.1); if (isotopePeaks == null) { continue; } Assert.True(isotopePeaks.Length == theoProfile.Length); for (var i = 0; i < isotopePeaks.Length; i++) { if (isotopePeaks[i] != null) { expProfile[i] += isotopePeaks[i].Intensity; } } } for (var i = 0; i < theoProfile.Length; i++) { Console.WriteLine("{0}\t{1}\t{2}", neutral.GetIsotopeMass(i), theoProfile[i], expProfile[i] / expProfile.Max()); } Console.WriteLine("Corr: " + FitScoreCalculator.GetPearsonCorrelation(theoProfile, expProfile)); }
/// <summary> /// /// </summary> /// <param name="i"></param> /// <param name="maxIntensity"></param> /// <param name="startMZ"></param> /// <param name="FinishMZ"></param> /// <returns>A tuple with the mz and intensity mapped to the canvas</returns> private Tuple <double, double> ConvertMZToPixel(Ion i, double maxIntensity, double startMZ, double FinishMZ) { double compressionFactor = 0.80; double deltaMZ = FinishMZ - startMZ; double x = ((i.MZ - startMZ) / deltaMZ) * CanvasPeakDisplay.ActualWidth; double y = i.Intensity / maxIntensity * CanvasPeakDisplay.ActualHeight * compressionFactor; return(new Tuple <double, double>(x, y)); }
public void Test_LjpMathThrowsExceptionIf_MuIsZero() { var ionSet = new Ion[] { new Ion("A", charge: 1, conductivity: 7, c0: 3, cL: 3, phi: 6), new Ion("B", charge: 1, conductivity: 0, c0: 3, cL: 3, phi: 6), new Ion("C", charge: 1, conductivity: 7, c0: 3, cL: 3, phi: 6), }; Assert.Throws <ArgumentException>(() => LjpCalculator.SolvePhisThenCalculateLjp(ionSet)); }
public void TestFitScoreCalculationCid() { var methodName = MethodBase.GetCurrentMethod().Name; Utils.ShowStarting(methodName); if (!File.Exists(FilePaths.TestTopDownRawFilePathCid)) { Assert.Ignore(@"Skipping test " + methodName + @" since file not found: " + FilePaths.TestTopDownRawFilePathCid); } var run = InMemoryLcMsRun.GetLcMsRunScanRange(FilePaths.TestTopDownRawFilePathCid, 5743, 5743); var spec = run.GetSpectrum(5743); Assert.True(spec != null); const string protein = "MRIILLGAPGAGKGTQAQFIMEKYGIPQISTGDMLRAAVKSGSELGKQAKDIMDAGKLVTDELVIALVKERIAQEDCRNGFLLDGFPRTIPQADAMKEAGIVVDYVLEFDVPDELIVDRIVGRRVHAASGRVYHVKFNPPKVEGKDDVTGEDLTTRKDDQEETVRKRLVEYHQMTAPLIGYYQKEAEAGNTKYAKVDGTQAVADVRAALEKILG"; var protComp = new AminoAcidSet().GetComposition(protein) + Composition.H2O; Assert.True(protComp != null); Assert.True(protComp.C == 1035); Assert.True(protComp.H == 1683); Assert.True(protComp.N == 289); Assert.True(protComp.O == 318); Assert.True(protComp.P == 0); Assert.True(protComp.S == 7); Assert.True(Math.Abs(protComp.Mass - 23473.245267145) < 0.0000001); Assert.True(protComp.NominalMass == 23461); var ion = new Ion(protComp, 20); // ion.Composition.ComputeApproximateIsotopomerEnvelop(); var isotopomerEnvelope = ion.Composition.GetIsotopomerEnvelopeRelativeIntensities(); Console.WriteLine(@"MonoMz: {0}, MonoMass: {1}", ion.GetMonoIsotopicMz(), ion.Composition.Mass); var matchedPeaks = spec.GetAllIsotopePeaks(ion, new Tolerance(15), 0.1); for (var i = 0; i < matchedPeaks.Length; i++) { var intensity = matchedPeaks[i] == null ? 0 : matchedPeaks[i].Intensity; Console.WriteLine(@"{0,3} {1,10:F4} {2,10:F3} {3,10:F3}", i, ion.GetIsotopeMz(i), isotopomerEnvelope[i], intensity); } var fitScore = spec.GetFitScore(ion, new Tolerance(15), 0.1); var cosine = spec.GetConsineScore(ion, new Tolerance(15), 0.1); var corr = spec.GetCorrScore(ion, new Tolerance(15), 0.1); Console.WriteLine(@"FitScore: {0}", fitScore); Console.WriteLine(@"Cosine: {0}", cosine); Console.WriteLine(@"Corr: {0}", corr); Assert.True(Math.Abs(fitScore - 0.181194589537041) < 0.0001); Assert.True(Math.Abs(cosine - 0.917609346566222) < 0.0001); Assert.True(Math.Abs(corr - 0.808326778009839) < 0.0001); }
public Envelope(Ion startPeak, int z, List <Ion> peaks, double[] theoIsotDist, Ion highestPeak) { MonoisotPeak = startPeak; Charge = z; PeaksInEnvelope = peaks; TheoIsotDist = theoIsotDist; HighestPeakInRange = highestPeak; FractionQuantity = 1; CalcScore(); }
/// <summary> /// Calculate precursor mass-to-charge ratio of sequence. /// </summary> /// <param name="sequence">Sequence to calculate mass from.</param> /// <param name="charge">Charge state.</param> /// <returns>Mass-to-charge ratio of precursor ion for the sequence.</returns> public static double GetPrecursorMz(Sequence sequence, int charge) { if (sequence.Count == 0) { return(0.0); } var composition = sequence.Aggregate(Composition.Zero, (current, aa) => current + aa.Composition); var ion = new Ion(composition + Composition.H2O, charge); return(Math.Round(ion.GetMostAbundantIsotopeMz(), 2)); }
public async Task loadFile( Ion amp ) { this.storageFile = await amp.requestAsync( this.fileURL, checksum, this ); }