public string Parse(Dictionary<string, string> parameters) { var message = CheckIsValid(parameters); if (message != null) return message; var specFilePath = parameters["-s"]; if (Directory.Exists(specFilePath)) // Directory { SpecFilePaths = Directory.GetFiles(specFilePath, "*.raw"); } else { SpecFilePaths = new[] {specFilePath}; } DatabaseFilePath = parameters["-d"]; var outputDir = parameters["-o"] ?? Environment.CurrentDirectory; if (!Directory.Exists(outputDir)) { if (File.Exists(outputDir) && !File.GetAttributes(outputDir).HasFlag(FileAttributes.Directory)) { return "OutputDir " + outputDir + " is not a directory!"; } Directory.CreateDirectory(outputDir); } OutputDir = outputDir; var modFilePath = parameters["-mod"]; if (modFilePath != null) { var parser = new ModFileParser(modFilePath); _searchModifications = parser.SearchModifications; _maxNumDynModsPerSequence = parser.MaxNumDynModsPerSequence; if (_searchModifications == null) return "Error while parsing " + modFilePath + "!"; AminoAcidSet = new AminoAcidSet(_searchModifications, _maxNumDynModsPerSequence); } else { AminoAcidSet = new AminoAcidSet(); _searchModifications = new SearchModification[0]; } var enzymeId = Convert.ToInt32(parameters["-e"]); Enzyme enzyme; switch (enzymeId) { case 0: enzyme = Enzyme.UnspecificCleavage; break; case 1: enzyme = Enzyme.Trypsin; break; case 2: enzyme = Enzyme.Chymotrypsin; break; case 3: enzyme = Enzyme.LysC; break; case 4: enzyme = Enzyme.LysN; break; case 5: enzyme = Enzyme.GluC; break; case 6: enzyme = Enzyme.ArgC; break; case 7: enzyme = Enzyme.AspN; break; case 8: enzyme = Enzyme.Alp; break; case 9: enzyme = Enzyme.NoCleavage; break; default: return "Invalid enzyme ID (" + enzymeId + ") for parameter -e"; } Enzyme = enzyme; NumTolerableTermini = Convert.ToInt32(parameters["-ntt"]); if (NumTolerableTermini < 0 || NumTolerableTermini > 2) { return "Invalid value (" + NumTolerableTermini + ") for parameter -m"; } PrecursorIonTolerancePpm = Convert.ToDouble(parameters["-t"]); ProductIonTolerancePpm = Convert.ToDouble(parameters["-f"]); var tdaVal = Convert.ToInt32(parameters["-tda"]); if (tdaVal != 0 && tdaVal != 1) { return "Invalid value (" + tdaVal + ") for parameter -tda"; } TdaBool = (tdaVal == 1); MinSequenceLength = Convert.ToInt32(parameters["-minLength"]); MaxSequenceLength = Convert.ToInt32(parameters["-maxLength"]); if (MinSequenceLength > MaxSequenceLength) { return "MinSequenceLength (" + MinSequenceLength + ") is larger than MaxSequenceLength (" + MaxSequenceLength + ")!"; } MinPrecursorIonCharge = Convert.ToInt32(parameters["-minCharge"]); MaxPrecursorIonCharge = Convert.ToInt32(parameters["-maxCharge"]); if (MinSequenceLength > MaxSequenceLength) { return "MinPrecursorCharge (" + MinPrecursorIonCharge + ") is larger than MaxPrecursorCharge (" + MaxPrecursorIonCharge + ")!"; } MinProductIonCharge = Convert.ToInt32(parameters["-minFragCharge"]); MaxProductIonCharge = Convert.ToInt32(parameters["-maxFragCharge"]); if (MinSequenceLength > MaxSequenceLength) { return "MinFragmentCharge (" + MinProductIonCharge + ") is larger than MaxFragmentCharge (" + MaxProductIonCharge + ")!"; } return null; }
public void TestReadingModFile() { var methodName = MethodBase.GetCurrentMethod().Name; TestUtils.ShowStarting(methodName); const string modFilePath = @"..\..\..\TestFiles\Mods.txt"; if (!File.Exists(modFilePath)) { Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, modFilePath); } var modFileParser = new ModFileParser(modFilePath); Console.WriteLine("MaxNumDynModsPerSequence: {0}", modFileParser.MaxNumDynModsPerSequence); foreach (var searhMod in modFileParser.SearchModifications) { Console.WriteLine("{0}\t{1}\t{2}\t{3}", searhMod.TargetResidue, searhMod.Location, searhMod.IsFixedModification, searhMod.Modification); } var aaSet = new AminoAcidSet(modFilePath); aaSet.Display(); }
private AminoAcidSet(ModFileParser modFileParser) : this(modFileParser.SearchModifications, modFileParser.MaxNumDynModsPerSequence) { }
private AminoAcidSet(ModFileParser modFileParser) : this(modFileParser.SearchModifications, modFileParser.MaxNumDynModsPerSequence) { }
public string Parse(Dictionary<string, string> parameters) { var message = CheckIsValid(parameters); if (message != null) return message; try { var specFilePath = parameters["-s"]; SpecFilePaths = Directory.Exists(specFilePath) ? Directory.GetFiles(specFilePath, "*.raw") : new[] { specFilePath }; } catch (Exception ex) { Console.WriteLine("Exception parsing the file path for parameter -s: " + ex.Message); throw; } DatabaseFilePath = parameters["-d"]; try { var outputDir = parameters["-o"] ?? Environment.CurrentDirectory; if (!Directory.Exists(outputDir)) { if (File.Exists(outputDir) && !File.GetAttributes(outputDir).HasFlag(FileAttributes.Directory)) { return "OutputDir is not a directory: " + outputDir; } Directory.CreateDirectory(outputDir); } OutputDir = outputDir; } catch (Exception ex) { Console.WriteLine("Exception validating the path for parameter -o: " + ex.Message); throw; } try { var modFilePath = parameters["-mod"]; if (modFilePath != null) { var parser = new ModFileParser(modFilePath); _searchModifications = parser.SearchModifications; _maxNumDynModsPerSequence = parser.MaxNumDynModsPerSequence; if (_searchModifications == null) return "Error while parsing " + modFilePath; AminoAcidSet = new AminoAcidSet(_searchModifications, _maxNumDynModsPerSequence); } else { AminoAcidSet = new AminoAcidSet(); _searchModifications = new SearchModification[0]; } } catch (Exception ex) { Console.WriteLine("Exception parsing the path for parameter -mod: " + ex.Message); throw; } var currentParameter = string.Empty; try { currentParameter = "-feature"; FeatureFilePath = parameters["-feature"]; currentParameter = "-m"; var searchMode = Convert.ToInt32(parameters["-m"]); if (searchMode < 0 || searchMode > 2) { return "Invalid value (" + searchMode + ") for parameter -m"; } SearchModeInt = searchMode; currentParameter = "-t"; PrecursorIonTolerancePpm = Convert.ToDouble(parameters["-t"]); currentParameter = "-f"; ProductIonTolerancePpm = Convert.ToDouble(parameters["-f"]); currentParameter = "-tda"; var tdaVal = Convert.ToInt32(parameters["-tda"]); if (tdaVal != 0 && tdaVal != 1 && tdaVal != -1) { return "Invalid value (" + tdaVal + ") for parameter -tda"; } if (tdaVal == 1) { Tda = DatabaseSearchMode.Both; } else if (tdaVal == -1) { Tda = DatabaseSearchMode.Decoy; } else { Tda = DatabaseSearchMode.Target; } currentParameter = "-minLength"; MinSequenceLength = Convert.ToInt32(parameters["-minLength"]); currentParameter = "-maxLength"; MaxSequenceLength = Convert.ToInt32(parameters["-maxLength"]); if (MinSequenceLength > MaxSequenceLength) { return "MinSequenceLength (" + MinSequenceLength + ") is larger than MaxSequenceLength (" + MaxSequenceLength + ")!"; } currentParameter = "-feature"; MinPrecursorIonCharge = Convert.ToInt32(parameters["-minCharge"]); currentParameter = "-feature"; MaxPrecursorIonCharge = Convert.ToInt32(parameters["-maxCharge"]); if (MinSequenceLength > MaxSequenceLength) { return "MinPrecursorCharge (" + MinPrecursorIonCharge + ") is larger than MaxPrecursorCharge (" + MaxPrecursorIonCharge + ")!"; } currentParameter = "-minFragCharge"; MinProductIonCharge = Convert.ToInt32(parameters["-minFragCharge"]); currentParameter = "-maxFragCharge"; MaxProductIonCharge = Convert.ToInt32(parameters["-maxFragCharge"]); if (MinSequenceLength > MaxSequenceLength) { return "MinFragmentCharge (" + MinProductIonCharge + ") is larger than MaxFragmentCharge (" + MaxProductIonCharge + ")!"; } currentParameter = "-minMass"; MinSequenceMass = Convert.ToDouble(parameters["-minMass"]); currentParameter = "-maxMass"; MaxSequenceMass = Convert.ToDouble(parameters["-maxMass"]); if (MinSequenceMass > MaxSequenceMass) { return "MinSequenceMassInDa (" + MinSequenceMass + ") is larger than MaxSequenceMassInDa (" + MaxSequenceMass + ")!"; } currentParameter = "-threads"; MaxNumThreads = Convert.ToInt32(parameters["-threads"]); MaxNumThreads = GetOptimalMaxThreads(MaxNumThreads); currentParameter = "-tagSearch"; TagBasedSearch = Convert.ToInt32(parameters["-tagSearch"]) == 1; } catch (Exception ex) { Console.WriteLine("Exception parsing parameter '" + currentParameter + "': " + ex.Message); throw; } return null; }