private static List <string> ProcessLine(ShowBy showBy, PredictorCollection predictorCollection, string line, MerLength merLength, int?dOfCenter, HlaSetSpecification hlaSetSpecification, bool modelOnly) { try { string hlaOrSupertypeOrNull; string inputPeptide = ExtractInputs(hlaSetSpecification, line, predictorCollection, out hlaOrSupertypeOrNull); List <string> output = new List <string>(); foreach (List <Prediction> predictionList in predictorCollection.MaxProbabilityPredictions(showBy, inputPeptide, merLength, dOfCenter, hlaSetSpecification, hlaOrSupertypeOrNull, modelOnly).Values) { string outputLine = InsertMaterial(line, hlaSetSpecification.InputHeaderCollection().Length, Prediction.CollectionToString(predictionList, false, hlaSetSpecification.IncludeHlaInOutput())); output.Add(outputLine); } return(output); } catch (Exception exception) { string errorString = SpecialFunctions.CreateTabString( line, string.Format("Error: {0}{1}", exception.Message, exception.InnerException == null ? "" : string.Format(" ({0})", exception.InnerException))); List <string> output = new List <string>(); output.Add(errorString); return(output); } }
/// <summary> /// Returns a list with one item per unique "GroupBy" key (e.g. each hla, each length, etc). Each item is a list of the predictions /// that tie for maximum probability. /// /// Most of the inputs are the same as for PredictionEnumeration. /// </summary> /// <param name="showBy"></param> /// <param name="inputPeptide"></param> /// <param name="merLength"></param> /// <param name="hlaSetSpecification"></param> /// <param name="hlaOrSupertypeOrNull"></param> /// <param name="modelOnly"></param> /// <returns></returns> public Dictionary <object, List <Prediction> > MaxProbabilityPredictions(ShowBy showBy, string inputPeptide, MerLength merLength, int?dOfCenter, HlaSetSpecification hlaSetSpecification, string hlaOrSupertypeOrNull, bool modelOnly) { Dictionary <object, BestSoFarWithTies <double, Prediction> > keyToBest = ForEachKeyFindTheBestResults(showBy, inputPeptide, merLength, dOfCenter, hlaSetSpecification, hlaOrSupertypeOrNull, modelOnly); Dictionary <object, List <Prediction> > maxProbabilityPredictionsPerKey = FindResultsPerKey(keyToBest); return(maxProbabilityPredictionsPerKey); }
private Dictionary <object, BestSoFarWithTies <double, Prediction> > ForEachKeyFindTheBestResults( ShowBy showBy, string inputPeptide, MerLength merLength, int?dOfCenter, HlaSetSpecification hlaSetSpecification, string hlaOrSupertypeOrNull, bool modelOnly) { Dictionary <object, BestSoFarWithTies <double, Prediction> > keyToBest = new Dictionary <object, BestSoFarWithTies <double, Prediction> >(); foreach (Prediction prediction in PredictionEnumeration(inputPeptide, merLength, dOfCenter, hlaSetSpecification, hlaOrSupertypeOrNull, modelOnly)) { object key = prediction.GroupByKey(showBy); //!!!would be nice if this were typed, rather than just using 'string' BestSoFarWithTies <double, Prediction> bestSoFarWithTies = SpecialFunctions.GetValueOrDefault(keyToBest, key, BestSoFarWithTies <double, Prediction> .GetInstance(SpecialFunctions.DoubleGreaterThan)); bestSoFarWithTies.Compare(prediction.WeightOfEvidence, prediction); } return(keyToBest); }
public static void Main(string[] args) { try { // Parse arguments ArgCollection argCollection = ArgCollection.GetInstance(args); if (argCollection.ExtractOptionalFlag("Help")) { Console.WriteLine(HelpString); return; } string modelName = argCollection.ExtractOptional("model", "LANLIEDB03062007"); bool modelOnly = argCollection.ExtractOptionalFlag("modelOnly"); bool inputHasHeader = argCollection.ExtractOptionalFlag("inputHasHeader"); MerLength merLength = argCollection.ExtractOptional <MerLength>("merLength", MerLength.scan); int? dOfCenter = argCollection.ExtractOptional <int?>("withinDOfCenter", null); ShowBy showBy = argCollection.ExtractOptional <ShowBy>("showBy", ShowBy.all); string hlaSetName = argCollection.ExtractOptional <string>("hlaSet", "singleton"); HlaSetSpecification hlaSetSpecification = HlaSetSpecification.GetInstance(hlaSetName); argCollection.CheckNoMoreOptions(); string inputFileName = argCollection.ExtractNext <string>("inputFile"); string outputFileName = argCollection.ExtractNext <string>("outputFile"); argCollection.CheckThatEmpty(); ReadInputCreatingOutput(showBy, modelName, inputHasHeader, merLength, dOfCenter, hlaSetSpecification, modelOnly, inputFileName, outputFileName); } catch (Exception exception) { Console.WriteLine(""); Console.WriteLine(exception.Message); if (exception.InnerException != null) { Console.WriteLine(exception.InnerException.Message); } Console.Error.WriteLine(""); Console.Error.WriteLine(@"For more help: Epipred -help"); System.Environment.Exit(-1); } }
internal object GroupByKey(ShowBy showBy) { switch (showBy) { case ShowBy.all: return("all"); case ShowBy.hla: return(Hla); case ShowBy.length: return(NEC.E.Length); case ShowBy.hlaAndLength: return(new Pair <Hla, int>(Hla, NEC.E.Length)); case ShowBy.doNotGroup: return(this); default: SpecialFunctions.CheckCondition(false, "Don't know how to showBy " + showBy.ToString()); return(null); } }
private static void ReadInputCreatingOutput(ShowBy showBy, string modelName, bool inputHasHeader, MerLength merLength, int?dOfCenter, HlaSetSpecification hlaSetSpecification, bool modelOnly, string inputFileName, string outputFileName) { using (TextReader textReader = File.OpenText(inputFileName)) { using (TextWriter textWriter = File.CreateText(outputFileName)) { string header = CreateHeader(hlaSetSpecification, textReader, inputHasHeader); textWriter.WriteLine(header); PredictorCollection predictorCollection = PredictorCollection.GetInstance(modelName); foreach (string line in SpecialFunctions.ReadEachLine(textReader)) { foreach (string outputLine in ProcessLine(showBy, predictorCollection, line, merLength, dOfCenter, hlaSetSpecification, modelOnly)) { textWriter.WriteLine(outputLine); textWriter.Flush(); } } } } }
/// <summary> /// Displays the show by. /// </summary> /// <param name="showBy">The show by.</param> private void DisplayShowBy(ShowBy showBy) { hfShowBy.Value = showBy.ConvertToInt().ToString(); pnlChart.Visible = showBy == ShowBy.Chart; pnlDetails.Visible = showBy == ShowBy.Attendees; }
/// <summary> /// Loads the attendance reporting settings from user preferences. /// </summary> private void LoadSettingsFromUserPreferences() { string keyPrefix = string.Format("giving-analytics-{0}-", this.BlockId); string slidingDateRangeSettings = this.GetUserPreference(keyPrefix + "SlidingDateRange"); if (string.IsNullOrWhiteSpace(slidingDateRangeSettings)) { // default to current year drpSlidingDateRange.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.Current; drpSlidingDateRange.TimeUnit = SlidingDateRangePicker.TimeUnitType.Year; } else { drpSlidingDateRange.DelimitedValues = slidingDateRangeSettings; } hfGroupBy.Value = this.GetUserPreference(keyPrefix + "GroupBy"); nreAmount.DelimitedValues = this.GetUserPreference(keyPrefix + "AmountRange"); var currencyTypeIdList = this.GetUserPreference(keyPrefix + "CurrencyTypeIds").Split(',').ToList(); cblCurrencyTypes.SetValues(currencyTypeIdList); var sourceIdList = this.GetUserPreference(keyPrefix + "SourceIds").Split(',').ToList(); cblTransactionSource.SetValues(sourceIdList); var accountIdList = this.GetUserPreference(keyPrefix + "AccountIds").Split(',').ToList(); foreach (var cblAccounts in phAccounts.Controls.OfType <RockCheckBoxList>()) { cblAccounts.SetValues(accountIdList); } dvpDataView.SetValue(this.GetUserPreference(keyPrefix + "DataView")); HideShowDataViewResultOption(); rblDataViewAction.SetValue(this.GetUserPreference(keyPrefix + "DataViewAction")); hfGraphBy.Value = this.GetUserPreference(keyPrefix + "GraphBy"); ShowBy showBy = this.GetUserPreference(keyPrefix + "ShowBy").ConvertToEnumOrNull <ShowBy>() ?? ShowBy.Chart; DisplayShowBy(showBy); GiversViewBy viewBy = this.GetUserPreference(keyPrefix + "ViewBy").ConvertToEnumOrNull <GiversViewBy>() ?? GiversViewBy.Giver; hfViewBy.Value = viewBy.ConvertToInt().ToString(); GiversFilterBy giversFilterby = this.GetUserPreference(keyPrefix + "GiversFilterByType").ConvertToEnumOrNull <GiversFilterBy>() ?? GiversFilterBy.All; switch (giversFilterby) { case GiversFilterBy.FirstTime: radFirstTime.Checked = true; break; case GiversFilterBy.Pattern: radByPattern.Checked = true; break; default: radAllGivers.Checked = true; break; } string attendeesFilterByPattern = this.GetUserPreference(keyPrefix + "GiversFilterByPattern"); string[] attendeesFilterByPatternValues = attendeesFilterByPattern.Split('|'); if (attendeesFilterByPatternValues.Length == 3) { tbPatternXTimes.Text = attendeesFilterByPatternValues[0]; cbPatternAndMissed.Checked = attendeesFilterByPatternValues[1].AsBooleanOrNull() ?? false; drpPatternDateRange.DelimitedValues = attendeesFilterByPatternValues[2]; } }
/// <summary> /// Displays the show by. /// </summary> /// <param name="showBy">The show by.</param> private void DisplayShowBy( ShowBy showBy ) { hfShowBy.Value = showBy.ConvertToInt().ToString(); pnlShowByChart.Visible = showBy == ShowBy.Chart; pnlShowByAttendees.Visible = showBy == ShowBy.Attendees; }
/// <summary> /// Displays the show by. /// </summary> /// <param name="showBy">The show by.</param> private void DisplayShowBy( ShowBy showBy ) { hfShowBy.Value = showBy.ConvertToInt().ToString(); pnlChart.Visible = showBy == ShowBy.Chart; pnlDetails.Visible = showBy == ShowBy.Details; }