private string LoadModsFile(string modFilePath) { if (string.IsNullOrWhiteSpace(modFilePath)) { AminoAcidSet = new AminoAcidSet(); Modifications = new List <SearchModification>(); return(string.Empty); } if (!File.Exists(modFilePath)) { return("-mod file not found: " + modFilePath); } var parser = new ModFileParser(modFilePath); Modifications = parser.SearchModifications.ToList(); MaxDynamicModificationsPerSequence = parser.MaxNumDynModsPerSequence; if (Modifications == null) { return("Error while parsing " + modFilePath); } AminoAcidSet = new AminoAcidSet(Modifications, MaxDynamicModificationsPerSequence); return(string.Empty); }
public void HandleHandshakeReplyReceivedMessage(HandshakeReplyMsgData data) { HandshakeReply reply; string reason; var modFileData = ""; try { reply = data.Response; reason = data.Reason; //If we handshook successfully, the mod data will be available to read. if (reply == HandshakeReply.HANDSHOOK_SUCCESSFULLY) { ModSystem.Singleton.ModControl = data.ModControlMode; if (ModSystem.Singleton.ModControl != ModControlMode.DISABLED) { modFileData = Encoding.UTF8.GetString(data.ModFileData); } } } catch (Exception e) { Debug.LogError($"[LMP]: Error handling HANDSHAKE_REPLY Message, exception: {e}"); reply = HandshakeReply.MALFORMED_HANDSHAKE; reason = "Incompatible HANDSHAKE_REPLY Message"; } switch (reply) { case HandshakeReply.HANDSHOOK_SUCCESSFULLY: { if (ModFileParser.ParseModFile(modFileData)) { Debug.Log("[LMP]: Handshake successful"); MainSystem.Singleton.NetworkState = ClientState.AUTHENTICATED; } else { Debug.LogError("[LMP]: Failed to pass mod validation"); NetworkConnection.Disconnect("[LMP]: Failed mod validation"); } } break; default: var disconnectReason = "Handshake failure: " + reason; //If it's a protocol mismatch, append the client/server version. if (reply == HandshakeReply.PROTOCOL_MISMATCH) { disconnectReason += "\nClient: " + VersionInfo.VersionNumber + ", Server: " + data.Version; } Debug.Log(disconnectReason); NetworkConnection.Disconnect(disconnectReason); break; } }
public void HandleHandshakeReplyReceivedMessage(HandshakeReplyMsgData data) { HandshakeReply reply; string reason; var modFileData = ""; try { reply = data.Response; reason = data.Reason; //If we handshook successfully, the mod data will be available to read. if (reply == HandshakeReply.HandshookSuccessfully) { SystemsContainer.Get <ModSystem>().ModControl = data.ModControlMode; if (SystemsContainer.Get <ModSystem>().ModControl != ModControlMode.Disabled) { modFileData = Encoding.UTF8.GetString(data.ModFileData); } } } catch (Exception e) { LunaLog.LogError($"[LMP]: Error handling HANDSHAKE_REPLY Message, exception: {e}"); reply = HandshakeReply.MalformedHandshake; reason = "Incompatible HANDSHAKE_REPLY Message"; } switch (reply) { case HandshakeReply.HandshookSuccessfully: { if (ModFileParser.ParseModFile(modFileData)) { LunaLog.Log("[LMP]: Handshake successful"); MainSystem.NetworkState = ClientState.Authenticated; } else { LunaLog.LogError("[LMP]: Failed to pass mod validation"); NetworkConnection.Disconnect("[LMP]: Failed mod validation"); } } break; default: var disconnectReason = $"Handshake failure: {reason}"; //If it's a protocol mismatch, append the client/server version. if (reply == HandshakeReply.ProtocolMismatch) { disconnectReason += $"\nClient: {VersionInfo.VersionNumber}, Server: {data.Version}"; } LunaLog.Log(disconnectReason); NetworkConnection.Disconnect(disconnectReason); break; } }
public static void LoadModProjects() { CreateExampleModProject(); // 获取所有得 mod 项目文件夹 DirectoryInfo[] directoryInfos = new DirectoryInfo(ModGlobalData.MOD_PATH_ROOT).GetDirectories(); foreach (DirectoryInfo directoryInfo in directoryInfos) { if (File.Exists(directoryInfo.Parent.FullName + @"\" + directoryInfo.Name + ".mod")) { // 获取mod配置文件 FileInfo fileInfo = new FileInfo(directoryInfo.Parent.FullName + @"\" + directoryInfo.Name + ".mod"); ModFileParser modFileParser = new ModFileParser(); PdxMod pdxMod = modFileParser.ParseModFile(fileInfo.FullName); ModProjects.Add(pdxMod); } } }
public void TestReadingModFile() { var methodName = MethodBase.GetCurrentMethod().Name; Utils.ShowStarting(methodName); var modFilePath = Path.Combine(Utils.DEFAULT_TEST_FILE_FOLDER, @"TopDown\ProductionQCShew\Mods.txt"); var modFile = Utils.GetTestFile(methodName, modFilePath); var modFileParser = new ModFileParser(modFile.FullName); 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(modFile.FullName); aaSet.Display(); }
public void HandleHandshakeReplyReceivedMessage(HandshakeReplyMsgData data) { TimeSyncSystem.ServerStartTime = data.ServerStartTime; switch (data.Response) { case HandshakeReply.HandshookSuccessfully: ModSystem.Singleton.Clear(); ModSystem.Singleton.ModControl = data.ModControl; if (ModSystem.Singleton.ModControl) { if (ModSystem.Singleton.ModFileHandler.ParseModFile(ModFileParser.ReadModFileFromString(data.ModFileData))) { LunaLog.Log("[LMP]: Handshake successful"); MainSystem.NetworkState = ClientState.Handshaked; } else { LunaLog.LogError("[LMP]: Failed to pass mod validation"); NetworkConnection.Disconnect("[LMP]: Failed mod validation"); } } else { LunaLog.Log("[LMP]: Handshake successful"); MainSystem.NetworkState = ClientState.Handshaked; } break; default: var disconnectReason = $"Handshake failure: {data.Reason}"; LunaLog.Log(disconnectReason); NetworkConnection.Disconnect(disconnectReason); break; } }
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(); }
/// <summary> /// Opens parameter file from .PARAM file.. /// </summary> /// <param name="filePath">The path of the parameter file.</param> /// <returns> /// Parsed MSPathFinder parameters. Returns null if file does not exist. /// Throws exception if file is not formatted correctly. /// </returns> public static MsPfParameters Parse(string filePath) { if (!File.Exists(filePath)) { return(null); } var file = File.ReadAllLines(filePath); var param = new MsPfParameters(); foreach (var line in file) { var parts = line.Split('\t'); if (parts.Length < 2) { continue; } switch (parts[0]) { case "SpecFile": param.SpecFilePath = parts[1]; break; case "DatabaseFile": param.DatabaseFilePath = parts[1]; break; case "FeatureFile": param.FeatureFilePath = parts[1]; break; case "SearchMode": #pragma warning disable 618 param.SearchModeInt = Convert.ToInt32(parts[1]); #pragma warning restore 618 break; case "InternalCleavageMode": param.InternalCleavageMode = (InternalCleavageType)Enum.Parse(typeof(InternalCleavageType), parts[1]); break; case "Tda": int tda = 0; tda += Convert.ToInt32(parts[1].Contains("Target")); tda += Convert.ToInt32(parts[1].Contains("Decoy")) * 2; param.TargetDecoySearchMode = (DatabaseSearchMode)tda; break; case "PrecursorIonTolerancePpm": param.PrecursorIonTolerance = new Tolerance(Convert.ToDouble(parts[1]), ToleranceUnit.Ppm); break; case "ProductIonTolerancePpm": param.ProductIonTolerance = new Tolerance(Convert.ToDouble(parts[1]), ToleranceUnit.Ppm); break; case "MinSequenceLength": param.MinSequenceLength = Convert.ToInt32(parts[1]); break; case "MaxSequenceLength": param.MaxSequenceLength = Convert.ToInt32(parts[1]); break; case "MinPrecursorIonCharge": param.MinPrecursorIonCharge = Convert.ToInt32(parts[1]); break; case "MaxPrecursorIonCharge": param.MaxPrecursorIonCharge = Convert.ToInt32(parts[1]); break; case "MinProductIonCharge": param.MinProductIonCharge = Convert.ToInt32(parts[1]); break; case "MaxProductIonCharge": param.MaxProductIonCharge = Convert.ToInt32(parts[1]); break; case "MinSequenceMass": param.MinSequenceMass = Convert.ToDouble(parts[1]); break; case "MaxSequenceMass": param.MaxSequenceMass = Convert.ToDouble(parts[1]); break; case "MinFeatureProbability": param.MinFeatureProbablility = Convert.ToDouble(parts[1]); break; case "MaxDynamicModificationsPerSequence": param.MaxDynamicModificationsPerSequence = Convert.ToInt32(parts[1]); break; case "Modification": param.Modifications.AddRange(ModFileParser.ParseModification(parts[1])); break; case "ActivationMethod": param.ActivationMethod = (ActivationMethod)Convert.ToInt32(parts[1]); break; } } if (param.PrecursorIonTolerance == null && param.ProductIonTolerance != null) { param.PrecursorIonTolerance = param.ProductIonTolerance; } if (param.PrecursorIonTolerance != null && param.ProductIonTolerance == null) { param.ProductIonTolerance = param.PrecursorIonTolerance; } return(param); }
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 (outputDir[outputDir.Length - 1] == Path.DirectorySeparatorChar) { outputDir = outputDir.Remove(outputDir.Length - 1); } 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"); } Tda = (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 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); }