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); } }
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(); } } } } }
static public string ExtractInputs(HlaSetSpecification hlaSetSpecification, string line, PredictorCollection predictorCollection, out string hlaOrSupertypeOrNull) { List <string> fieldCollection = SpecialFunctions.Split(line, '\t'); int inputLength = hlaSetSpecification.InputHeaderCollection().Length; SpecialFunctions.CheckCondition(inputLength <= fieldCollection.Count, string.Format("Expected input to have at least {0} columns", inputLength)); string inputPeptide = fieldCollection[0]; hlaOrSupertypeOrNull = (inputLength > 1) ? fieldCollection[1] : null; return(inputPeptide); }