private void GetActiveScoredValues(IPeakScoringModel peakScoringModel, LinearModelParams scoringParams, LinearModelParams calculatorParams, out List <double> targetScores, out List <double> activeDecoyScores) { targetScores = new List <double>(TargetCount); List <double> decoyScores = peakScoringModel.UsesDecoys ? new List <double>(DecoyCount) : null; List <double> secondBestScores = peakScoringModel.UsesSecondBest ? new List <double>(TargetCount) : null; GetScores(scoringParams, calculatorParams, targetScores, decoyScores, secondBestScores); if (peakScoringModel.UsesDecoys && !peakScoringModel.UsesSecondBest) { activeDecoyScores = decoyScores; } else if (peakScoringModel.UsesSecondBest && !peakScoringModel.UsesDecoys) { activeDecoyScores = secondBestScores; } else { activeDecoyScores = new List <double>(); if (decoyScores != null) { activeDecoyScores.AddRange(decoyScores); } if (secondBestScores != null) { activeDecoyScores.AddRange(secondBestScores); } } }
public TargetDecoyGenerator(SrmDocument document, IPeakScoringModel scoringModel, IFeatureScoreProvider scoreProvider, IProgressMonitor progressMonitor) : this(scoringModel, scoreProvider != null ? scoreProvider.GetFeatureScores(document, scoringModel, progressMonitor) : document.GetPeakFeatures(scoringModel.PeakFeatureCalculators, progressMonitor)) { }
public PeakCalculatorWeight[] GetPeakCalculatorWeights(IPeakScoringModel peakScoringModel, IProgressMonitor progressMonitor) { IProgressStatus status = new ProgressStatus(Resources.EditPeakScoringModelDlg_TrainModel_Calculating_score_contributions); var peakCalculatorWeights = new PeakCalculatorWeight[peakScoringModel.PeakFeatureCalculators.Count]; int seenContributingScores = 0; int totalContributingScores = peakScoringModel.IsTrained ? peakScoringModel.Parameters.Weights.Count(w => !double.IsNaN(w)) : 1; // Should never get used, but just in case, avoid divide by zero ParallelEx.For(0, peakCalculatorWeights.Length, i => { bool isNanWeight = !peakScoringModel.IsTrained || double.IsNaN(peakScoringModel.Parameters.Weights[i]); var name = peakScoringModel.PeakFeatureCalculators[i].Name; double?weight = null, normalWeight = null; if (!isNanWeight) { progressMonitor.UpdateProgress(status = status.ChangePercentComplete(seenContributingScores * 100 / totalContributingScores)); weight = peakScoringModel.Parameters.Weights[i]; normalWeight = GetPercentContribution(peakScoringModel, i); Interlocked.Increment(ref seenContributingScores); progressMonitor.UpdateProgress(status = status.ChangePercentComplete(seenContributingScores * 100 / totalContributingScores)); } // If the score is not eligible (e.g. has unknown values), definitely don't enable it // If it is eligible, enable if untrained or if trained and not nan bool enabled = EligibleScores[i] && (!peakScoringModel.IsTrained || !double.IsNaN(peakScoringModel.Parameters.Weights[i])); peakCalculatorWeights[i] = new PeakCalculatorWeight(name, weight, normalWeight, enabled); }); return(peakCalculatorWeights); }
public double?GetPercentContribution(IPeakScoringModel peakScoringModel, int index) { if (double.IsNaN(peakScoringModel.Parameters.Weights[index])) { return(null); } List <double> targetScores; List <double> activeDecoyScores; List <double> targetScoresAll; List <double> activeDecoyScoresAll; var scoringParameters = peakScoringModel.Parameters; var calculatorParameters = CreateParametersSelect(peakScoringModel, index); GetActiveScoredValues(peakScoringModel, scoringParameters, calculatorParameters, out targetScores, out activeDecoyScores); GetActiveScoredValues(peakScoringModel, scoringParameters, scoringParameters, out targetScoresAll, out activeDecoyScoresAll); if (targetScores.Count == 0 || activeDecoyScores.Count == 0 || targetScoresAll.Count == 0 || activeDecoyScoresAll.Count == 0) { return(null); } double meanDiffAll = targetScoresAll.Average() - activeDecoyScoresAll.Average(); double meanDiff = targetScores.Average() - activeDecoyScores.Average(); double meanWeightedDiff = meanDiff * peakScoringModel.Parameters.Weights[index]; if (meanDiffAll == 0 || double.IsNaN(meanDiffAll) || double.IsNaN(meanDiff)) { return(null); } return(meanWeightedDiff / meanDiffAll); }
public ReintegrateDlgSettings(IPeakScoringModel peakScoringModel, bool reintegrateAll, bool reintegrateQCutoff, double?cutoff, bool overwriteManualIntegration) { PeakScoringModel = peakScoringModel; ReintegrateAll = reintegrateAll; ReintegrateQCutoff = reintegrateQCutoff; Cutoff = cutoff; OverwriteManualIntegration = overwriteManualIntegration; }
public TargetDecoyGenerator(IPeakScoringModel scoringModel, PeakTransitionGroupFeatureSet featureScores) { // Determine which calculators will be used to score peaks in this document. FeatureCalculators = scoringModel.PeakFeatureCalculators.ToArray(); _peakTransitionGroupFeaturesList = featureScores; PopulateDictionary(); EligibleScores = new bool[FeatureCalculators.Count]; // Disable calculators that have only a single score value or any unknown scores. ParallelEx.For(0, FeatureCalculators.Count, i => EligibleScores[i] = IsValidCalculator(i)); }
/// <summary> /// Create parameter object in which the given index will have a value of 1, all the others /// will have a value of NaN, and the bias is zero. /// </summary> public static LinearModelParams CreateParametersSelect(IPeakScoringModel _peakScoringModel, int index) { var weights = new double[_peakScoringModel.PeakFeatureCalculators.Count]; for (int i = 0; i < weights.Length; i++) { weights[i] = double.NaN; } weights[index] = 1; return(new LinearModelParams(weights)); }
public PeakTransitionGroupFeatureSet GetFeatureScores(SrmDocument document, IPeakScoringModel scoringModel, IProgressMonitor progressMonitor) { if (!ReferenceEquals(document, _document) || !ArrayUtil.EqualsDeep(_cacheCalculators, scoringModel.PeakFeatureCalculators)) { _document = document; _cacheCalculators = scoringModel.PeakFeatureCalculators; _cachedFeatureScores = document.GetPeakFeatures(_cacheCalculators, progressMonitor); } return(_cachedFeatureScores); }
public TargetDecoyGenerator(SrmDocument document, IPeakScoringModel scoringModel, IProgressMonitor progressMonitor = null) { // Determine which calculators will be used to score peaks in this document. FeatureCalculators = scoringModel.PeakFeatureCalculators.ToArray(); _peakTransitionGroupFeaturesList = document.GetPeakFeatures(FeatureCalculators, progressMonitor); PopulateDictionary(); EligibleScores = new bool[FeatureCalculators.Count]; // Disable calculators that have only a single score value or any unknown scores. for (int i = 0; i < FeatureCalculators.Count; i++) EligibleScores[i] = IsValidCalculator(i); }
public LinearModelParams CalculatePercentContributions(IPeakScoringModel model, TargetDecoyGenerator targetDecoyGenerator) { var percentContributions = new double[_percentContributions.Count]; for (var i = 0; i < _percentContributions.Count; ++i) { percentContributions[i] = (targetDecoyGenerator != null ? targetDecoyGenerator.GetPercentContribution(model, i) : null) ?? double.NaN; } return(ChangeProp(ImClone(this), im => { im.PercentContributions = percentContributions; })); }
public TargetDecoyGenerator(SrmDocument document, IPeakScoringModel scoringModel, IProgressMonitor progressMonitor = null) { // Determine which calculators will be used to score peaks in this document. FeatureCalculators = scoringModel.PeakFeatureCalculators.ToArray(); _peakTransitionGroupFeaturesList = document.GetPeakFeatures(FeatureCalculators, progressMonitor); PopulateDictionary(); EligibleScores = new bool[FeatureCalculators.Count]; // Disable calculators that have only a single score value or any unknown scores. for (int i = 0; i < FeatureCalculators.Count; i++) { EligibleScores[i] = IsValidCalculator(i); } }
public void OkDialog() { using (var dlg = new SaveFileDialog { Title = Resources.MProphetFeaturesDlg_OkDialog_Export_mProphet_Features, OverwritePrompt = true, DefaultExt = EXT, Filter = TextUtil.FileDialogFilterAll(Resources.MProphetFeaturesDlg_OkDialog_mProphet_Feature_Files, EXT), }) { if (!string.IsNullOrEmpty(DocumentFilePath)) { dlg.InitialDirectory = Path.GetDirectoryName(DocumentFilePath); dlg.FileName = Path.GetFileNameWithoutExtension(DocumentFilePath) + EXT; } if (dlg.ShowDialog(this) == DialogResult.Cancel) { return; } var displayCalcs = new List <IPeakFeatureCalculator>(); displayCalcs.AddRange(from object calcName in checkedListVars.CheckedItems select GetCalcFromName(calcName.ToString())); IPeakScoringModel currentPeakScoringModel = Document.Settings.PeptideSettings.Integration.PeakScoringModel; var mProphetScoringModel = currentPeakScoringModel as MProphetPeakScoringModel; // if (mProphetScoringModel == null) // { // MessageDlg.Show(this, Resources.MProphetFeaturesDlg_OkDialog_To_export_MProphet_features_first_train_an_MProphet_model_); // return; // } var resultsHandler = new MProphetResultsHandler(Document, mProphetScoringModel); using (var longWaitDlg = new LongWaitDlg { Text = Resources.SkylineWindow_OpenSharedFile_Extracting_Files, }) { try { longWaitDlg.PerformWork(this, 1000, b => WriteFeatures(dlg.FileName, resultsHandler, displayCalcs, LocalizationHelper.CurrentCulture, checkBoxBestOnly.Checked, !checkBoxTargetsOnly.Checked, b)); if (longWaitDlg.IsCanceled) { return; } } catch (Exception x) { var message = TextUtil.LineSeparate(string.Format(Resources.MProphetFeaturesDlg_OkDialog_Failed_attempting_to_save_mProphet_features_to__0__, dlg.FileName), x.Message); MessageDlg.ShowWithException(this, message, x); } } } DialogResult = DialogResult.OK; }