public override List <byte> CreateNewProfile(profileNode node, string[] profile) { List <byte> newProfile = new List <byte>(profile.Length); for (int i = 0; i < profile.Length; i++) { string state = profile[i]; if (node.ContainsState(state)) { if (Convert.ToInt32(state, System.Globalization.CultureInfo.InvariantCulture) > 255) { state = "255"; } } if (node.ContainsState(state)) { newProfile.Add(node.GetCodedState(node.states[state], true)); } else { ErrorBase.AddErrors("Unknow state " + state + " in " + node.profName + " profile!"); } } return(newProfile); }
public virtual List <byte> CreateNewProfile(profileNode node, string [] profile) { List <byte> newProfile = new List <byte>(profile.Length); for (int i = 0; i < profile.Length; i++) { string state = profile[i]; if (node.ContainsState(state)) { newProfile.Add(node.GetCodedState(node.states[state])); } else { ErrorBase.AddErrors("Unknow state " + state + " in " + node.profName + " profile!"); } } return(newProfile); }
public override Dictionary<string, protInfo> GetProfile(profileNode node, string fileName, DCDFile dcd) { Dictionary<string, protInfo> dic = new Dictionary<string, protInfo>(); StreamReader wr; DebugClass.WriteMessage("profile" + fileName); wr = new StreamReader(fileName); protInfo info; string line = wr.ReadLine(); string name = ""; string seq = ""; List<string> profile = new List<string>(); List<byte> newProfile = new List<byte>(); while (line != null) { if (line.Contains(">")) { if (name.Length > 0) { info = new protInfo(); info.sequence = null; info.profile = newProfile; dic.Add(name, info); } name = line.Replace(">", ""); line = wr.ReadLine(); } if (line.Contains(node.profName+" ")) { string cLine=line.Remove(0, (node.profName+" profile ").Length); cLine = Regex.Replace(cLine, @"\s+", " "); cLine = cLine.Trim(); string[] aux; if (cLine.Contains(' ')) aux = cLine.Split(' '); else { char[] charArray = cLine.ToCharArray(); aux = cLine.Select(x => x.ToString()).ToArray(); } profile.Clear(); foreach (var item in aux) profile.Add(item); newProfile = new List<byte>(); for (int i = 0; i < profile.Count; i++) if (node.ContainsState(profile[i].ToString())) newProfile.Add(node.GetCodedState(node.states[profile[i].ToString()])); else if(profile[i].ToString()!="-" && profile[i].ToString()!="X") throw new Exception("Unknow state " + profile[i].ToString() + " in "+ node.profName + " profile!"); else newProfile.Add(0); } line = wr.ReadLine(); } info = new protInfo(); info.sequence = seq; info.profile = newProfile; dic.Add(name, info); DebugClass.WriteMessage("number of profiles " + dic.Keys.Count); wr.Close(); return dic; }
public override Dictionary <string, protInfo> GetProfile(profileNode node, string fileName, DCDFile dcd) { Dictionary <string, protInfo> dic = new Dictionary <string, protInfo>(); StreamReader wr; DebugClass.WriteMessage("profile" + fileName); wr = new StreamReader(fileName); protInfo info; string line = wr.ReadLine(); string name = ""; string seq = ""; List <string> profile = new List <string>(); List <byte> newProfile = new List <byte>(); while (line != null) { if (line.Contains(">")) { if (name.Length > 0) { info = new protInfo(); info.sequence = null; info.profile = newProfile; if (dic.ContainsKey(name)) { wr.Close(); throw new Exception("The nameof profile must be unique, name: " + name + " already exists in " + fileName); } dic.Add(name, info); } newProfile = new List <byte>(); name = line.Replace(">", ""); line = wr.ReadLine(); } if (line != null && line.Contains(" profile ")) { int index = line.IndexOf(" profile "); if (index == -1) { wr.Close(); throw new Exception("Incorrect file format you have to have 'profile' word!"); } string cLine = line.Remove(0, " profile ".Length + index); cLine = Regex.Replace(cLine, @"\s+", " "); if (line.Length == 0) { continue; } cLine = cLine.Trim(); string[] aux; if (cLine.Contains(' ')) { aux = cLine.Split(' '); } else { char[] charArray = cLine.ToCharArray(); aux = cLine.Select(x => x.ToString()).ToArray(); } profile.Clear(); foreach (var item in aux) { profile.Add(item); } newProfile = new List <byte>(); for (int i = 0; i < profile.Count; i++) { if (node.ContainsState(profile[i].ToString())) { newProfile.Add(node.GetCodedState(node.states[profile[i].ToString()])); } else if (profile[i].ToString() != "-" && profile[i].ToString() != "X") { throw new Exception("Unknow state " + profile[i].ToString() + " in " + node.profName + " profile!"); } else { newProfile.Add(0); } } } line = wr.ReadLine(); } if (newProfile.Count > 0) { info = new protInfo(); info.sequence = seq; info.profile = newProfile; dic.Add(name, info); } DebugClass.WriteMessage("number of profiles " + dic.Keys.Count); wr.Close(); return(dic); }
public override Dictionary <string, protInfo> GetProfile(profileNode node, string fileName, DCDFile dcd) { Dictionary <string, protInfo> dic = new Dictionary <string, protInfo>(); StreamReader wr; DebugClass.WriteMessage("profile" + fileName); wr = new StreamReader(fileName); protInfo info; string line = wr.ReadLine(); string name = ""; string seq = ""; List <string> profile = new List <string>(); List <byte> newProfile = new List <byte>(); while (line != null) { if (line.Contains(">")) { if (name.Length > 0) { info = new protInfo(); info.sequence = null; info.profile = newProfile; dic.Add(name, info); } name = line.Replace(">", ""); line = wr.ReadLine(); } if (line.Contains(" profile ")) //if (line.Contains(node.profName+" ")) { string[] aux; aux = line.Split(' '); node.profName = aux[0]; string cLine = line.Remove(0, (node.profName + " profile ").Length); cLine = Regex.Replace(cLine, @"\s+", " "); cLine = cLine.Trim(); if (cLine.Contains(' ')) { aux = cLine.Split(' '); } else { char[] charArray = cLine.ToCharArray(); aux = cLine.Select(x => x.ToString()).ToArray(); } profile.Clear(); foreach (var item in aux) { profile.Add(item); } newProfile = new List <byte>(); for (int i = 0; i < profile.Count; i++) { if (node.ContainsState(profile[i].ToString())) { newProfile.Add(node.GetCodedState(node.states[profile[i].ToString()])); } else if (profile[i].ToString() != "-" && profile[i].ToString() != "X") { throw new Exception("Unknow state " + profile[i].ToString() + " in " + node.profName + " profile!"); } else { newProfile.Add(0); } } } line = wr.ReadLine(); } info = new protInfo(); info.sequence = seq; info.profile = newProfile; dic.Add(name, info); DebugClass.WriteMessage("number of profiles " + dic.Keys.Count); wr.Close(); return(dic); }
public override Dictionary <string, protInfo> GetProfile(profileNode node, string fileName, DCDFile dcd = null) { Dictionary <string, protInfo> dic = new Dictionary <string, protInfo>(); currentProgress = 0; if (!File.Exists(GetProfileFileName(fileName))) { throw new Exception("Profile rnaSS does not exists!"); } string profileName; if (node.ContainsState("+")) { profileName = LWprofile; } else { profileName = SSprofile; } StreamReader wr = new StreamReader(GetProfileFileName(fileName)); List <string> files = GetFileList(fileName); maxV = files.Count; Dictionary <string, int> dicFile = new Dictionary <string, int>(); foreach (var item in files) { string[] aux = item.Split(Path.DirectorySeparatorChar); if (!dicFile.ContainsKey(aux[aux.Length - 1])) { dicFile.Add(aux[aux.Length - 1], 0); } } protInfo info; string line = wr.ReadLine(); string name = ""; string seq = ""; List <string> profile = new List <string>(); List <byte> newProfile = new List <byte>(); while (line != null) { if (line.Contains('>')) { if (name.Length > 0) { info = new protInfo(); info.sequence = seq; info.profile = newProfile; if (dicFile.ContainsKey(name)) { if (!dic.ContainsKey(name)) { dic.Add(name, info); } else { ErrorBase.AddErrors("There are two the same names " + name + " in the profile file " + GetProfileFileName(fileName)); } } currentProgress++; } name = line.Remove(0, 1); } if (line.Contains(SEQprofile)) { seq = line.Remove(0, SEQprofile.Length); } if (line.Contains(profileName)) { string tmp = line.Remove(0, profileName.Length); string[] aux; profile.Clear(); if (tmp.Contains(" ")) { tmp = tmp.TrimEnd(); aux = tmp.Split(' '); foreach (var item in aux) { profile.Add(item); } } else { for (int i = 0; i < tmp.Length; i++) { profile.Add(tmp[i].ToString()); } } newProfile = new List <byte>(); for (int i = 0; i < profile.Count; i++) { if (node.ContainsState(profile[i].ToString())) { newProfile.Add(node.GetCodedState(node.states[profile[i].ToString()])); } else if (profile[i].ToString() != "-" && profile[i].ToString() != "X") { throw new Exception("Unknow state: " + profile[i].ToString() + " in structure " + name + " in profile " + node.profName + " profile!"); } else { newProfile.Add(0); } } } line = wr.ReadLine(); } info = new protInfo(); info.sequence = seq; info.profile = newProfile; if (!dic.ContainsKey(name)) { dic.Add(name, info); } else { ErrorBase.AddErrors("There are two the same names " + name + " in the profile file " + GetProfileFileName(fileName)); } wr.Close(); currentProgress = maxV; return(dic); }
public override Dictionary <string, protInfo> GetProfile(profileNode node, string listFile, DCDFile dcd = null) { Dictionary <string, protInfo> dic = null; StreamReader wr; DebugClass.WriteMessage("start reading file" + listFile); string useFile = listFile; List <string> names = GetFileList(listFile); if (names == null) { DebugClass.WriteMessage("After GetFileList null"); } else { DebugClass.WriteMessage("After GetFileList " + names.Count); } maxV = names.Count; Dictionary <string, int> dicNames = new Dictionary <string, int>(names.Count); foreach (var item in names) { string[] aux = item.Split(Path.DirectorySeparatorChar); if (!dicNames.ContainsKey(aux[aux.Length - 1])) { dicNames.Add(aux[aux.Length - 1], 0); } } DebugClass.WriteMessage("After loop"); string[] dotFlag = names[0].Split('|'); bool flag = false; if (dotFlag.Length == 2) { flag = true; } DebugClass.WriteMessage("Before profile"); if (dcd == null) { wr = new StreamReader(GetProfileFileName(listFile)); } else { wr = new StreamReader(GetProfileFileName(dcd)); } DebugClass.WriteMessage("start ddd reading"); protInfo info; string line = wr.ReadLine(); string name = ""; string seq = ""; List <string> profile;; List <byte> newProfile = null; string profileName; if (node.ContainsState("H")) { profileName = ssProfile; } else { profileName = contactProfile; } //Check number of elements in file int lineLength = 0; while (line != null) { if (lineLength < line.Length) { lineLength = line.Length; } line = wr.ReadLine(); } wr.BaseStream.Position = 0; wr.DiscardBufferedData(); profile = new List <string>(lineLength); dic = new Dictionary <string, protInfo>(names.Count); line = wr.ReadLine(); string remName = ""; DebugClass.WriteMessage("Starrrrr"); while (line != null) { if (line[0] == '>') { if (name.Length > 0) { if (dicNames.ContainsKey(name)) { info = new protInfo(); info.sequence = seq; info.profile = newProfile; //string newName = line; //newName = newName.Remove(0, 1); if (!dic.ContainsKey(remName)) { dic.Add(remName, info); } else { ErrorBase.AddErrors("!!In the generated profile file structure " + remName + " exists more then once!!!\nOnly the first profile will be considered!"); } currentProgress++; } } name = line.Remove(0, 1); remName = name; if (name.Contains("|") && !flag) { string[] tmp = name.Split('|'); name = tmp[0]; } } if (dicNames.ContainsKey(name)) { if (line.Contains(SEQprofile)) { seq = line.Remove(0, SEQprofile.Length); } else if (line.Contains(profileName)) { //StringBuilder tmp = new StringBuilder(line); line = line.Remove(0, profileName.Length); //tmp = tmp.Remove(0, profileName.Length); //StringBuilder tmp = new StringBuilder (line.Remove(0, profileName.Length)); string[] aux; if (line.Contains(' ')) { aux = line.Split(' '); } else { aux = new string[line.Length]; for (int i = 0; i < line.Length; i++) { aux[i] = line[i].ToString(); } } newProfile = CreateNewProfile(node, aux); } } line = wr.ReadLine(); } if (dicNames.ContainsKey(name)) { info = new protInfo(); info.sequence = seq; info.profile = newProfile; dic.Add(remName, info); } wr.Close(); DebugClass.WriteMessage("Reading finished"); return(dic); }
public override Dictionary<string, protInfo> GetProfile(profileNode node, string listFile,DCDFile dcd=null) { Dictionary<string, protInfo> dic = null; StreamReader wr; DebugClass.WriteMessage("start reading file" + listFile); string useFile = listFile; List<string> names = GetFileList(listFile); if(names==null) DebugClass.WriteMessage("After GetFileList null"); else DebugClass.WriteMessage("After GetFileList "+names.Count); maxV = names.Count; Dictionary<string, int> dicNames = new Dictionary<string, int>(names.Count); foreach (var item in names) { string[] aux = item.Split(Path.DirectorySeparatorChar); if(!dicNames.ContainsKey(aux[aux.Length-1])) dicNames.Add(aux[aux.Length-1], 0); } DebugClass.WriteMessage("After loop"); string[] dotFlag = names[0].Split('|'); bool flag = false; if (dotFlag.Length == 2) flag = true; DebugClass.WriteMessage("Before profile"); if (dcd == null) { wr = new StreamReader(GetProfileFileName(listFile)); } else wr = new StreamReader(GetProfileFileName(dcd)); DebugClass.WriteMessage("start ddd reading"); protInfo info; string line = wr.ReadLine(); string name=""; string seq=""; List<string> profile; ; List<byte> newProfile = null; string profileName; if (node.ContainsState("H")) profileName = ssProfile; else profileName = contactProfile; //Check number of elements in file int lineLength=0; while (line != null) { if (lineLength < line.Length) lineLength = line.Length; line=wr.ReadLine(); } wr.BaseStream.Position = 0; wr.DiscardBufferedData(); profile = new List<string>(lineLength); dic = new Dictionary<string, protInfo>(names.Count); line=wr.ReadLine(); string remName=""; DebugClass.WriteMessage("Starrrrr"); while (line != null) { if (line[0]=='>') { if (name.Length > 0) { if (dicNames.ContainsKey(name)) { info = new protInfo(); info.sequence = seq; info.profile = newProfile; //string newName = line; //newName = newName.Remove(0, 1); if (!dic.ContainsKey(remName)) dic.Add(remName, info); else ErrorBase.AddErrors("!!In the generated profile file structure " + remName + " exists more then once!!!\nOnly the first profile will be considered!"); currentProgress++; } } name = line.Remove(0, 1); remName = name; if(name.Contains("|") && !flag) { string[] tmp = name.Split('|'); name = tmp[0]; } } if (dicNames.ContainsKey(name)) { if (line.Contains(SEQprofile)) seq = line.Remove(0, SEQprofile.Length); else if (line.Contains(profileName)) { //StringBuilder tmp = new StringBuilder(line); line=line.Remove(0,profileName.Length); //tmp = tmp.Remove(0, profileName.Length); //StringBuilder tmp = new StringBuilder (line.Remove(0, profileName.Length)); string[] aux; if(line.Contains(' ')) aux = line.Split(' '); else { aux = new string[line.Length]; for (int i = 0; i < line.Length; i++) aux[i] = line[i].ToString(); } newProfile = CreateNewProfile(node, aux); } } line = wr.ReadLine(); } if (dicNames.ContainsKey(name)) { info = new protInfo(); info.sequence = seq; info.profile = newProfile; dic.Add(remName, info); } wr.Close(); DebugClass.WriteMessage("Reading finished"); return dic; }
public virtual List<byte> CreateNewProfile(profileNode node,string [] profile) { List <byte>newProfile = new List<byte>(profile.Length); for (int i = 0; i < profile.Length; i++) { string state = profile[i]; if (node.ContainsState(state)) newProfile.Add(node.GetCodedState(node.states[state])); else ErrorBase.AddErrors("Unknow state " + state + " in " + node.profName + " profile!"); } return newProfile; }