示例#1
0
        public static Dictionary <string, protInfo> RearangeColumnOrder(Dictionary <string, protInfo> dic, string fileName)
        {
            Dictionary <string, protInfo> res = new Dictionary <string, protInfo>();
            List <string> keys = new List <string>(dic.Keys);
            StreamReader  f    = new StreamReader(fileName);

            string line = f.ReadLine();

            f.Close();

            string[] aux   = line.Split();
            int[]    index = new int[aux.Length];
            for (int i = 0; i < aux.Length; i++)
            {
                index[i] = Convert.ToInt32(aux[i]);
            }

            for (int j = 0; j < keys.Count; j++)
            {
                protInfo    xx         = dic[keys[j]];
                List <byte> newProfile = new List <byte>();
                for (int i = 0; i < xx.profile.Count; i++)
                {
                    newProfile.Add(xx.profile[index[i]]);
                }

                xx.profile = newProfile;
                res.Add(keys[j], xx);
            }
            return(res);
        }
示例#2
0
        public static Dictionary <string, protInfo> RearangeColumnOrder(Dictionary <string, protInfo> dic)
        {
            Dictionary <string, protInfo> res = new Dictionary <string, protInfo>();

            List <double> sumColumn = new List <double>();

            List <string> keys = new List <string>(dic.Keys);

            for (int i = 0; i < dic[keys[0]].profile.Count; i++)
            {
                double sum = 0;
                foreach (var item in keys)
                {
                    if (dic[item].profile[i] > 0)
                    {
                        sum += dic[item].profile[i];
                    }
                }
                //sum++;

                sumColumn.Add(sum);
            }
            int[] index = Enumerable.Range(0, sumColumn.Count).ToArray <int>();

            Array.Sort <int>(index, (b, a) => sumColumn[a].CompareTo(sumColumn[b]));

            for (int j = 0; j < keys.Count; j++)
            {
                protInfo    xx         = dic[keys[j]];
                List <byte> newProfile = new List <byte>();
                for (int i = 0; i < xx.profile.Count; i++)
                {
                    newProfile.Add(xx.profile[index[i]]);
                }

                xx.profile = newProfile;
                res.Add(keys[j], xx);
            }
            return(res);
        }
示例#3
0
        public override Dictionary <string, protInfo> GetProfile(profileNode node, string listFile, DCDFile dcd = null)
        {
            Dictionary <string, protInfo> res = base.GetProfile(node, listFile, dcd);

            /*            StreamReader r = new StreamReader("sekw");
             *          string line = r.ReadLine();
             *          int []index = new int[399];
             *          int counter = 0;
             *          while (line != null)
             *          {
             *              index[counter] = Convert.ToInt32(line);
             *              line = r.ReadLine();
             *              counter++;
             *          }*/
            int[] index = new int[20] {
                0, 74, 57, 375, 343, 174, 33, 371, 227, 330, 9, 327, 141, 160, 256, 216, 138, 385, 51, 268
            };                                                                                                                      // for proteins
            // int[] index = new int[29] { 21, 64, 29, 2, 33, 57, 77, 84, 14, 44, 81, 0, 90, 74, 30, 71, 76, 8, 48, 61,86,41,3,7,15,20,23,25,51};//for rna
            List <string> keys = new List <string>(res.Keys);

            foreach (var item in keys)
            {
                List <byte> newProfile = new List <byte>();
                for (int i = 0; i < index.Length; i++)
                {
                    newProfile.Add(res[item].profile[index[i]]);
                }
                protInfo xx = res[item];
                xx.profile = newProfile;
                res[item]  = xx;
            }
            //res = RearangeColumnOrder(res);
            // res = RearangeColumnOrder(res, "C:\\Projects\\listIndex");
            res = ProfileStat.RearangeStates(res, 0.51);
            return(res);
        }
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        private void AlignProfile(string protName,string profileName,List<byte>prof)
        {
            int m = 0;
            string alignProfile = align[protName];
            List<byte> ll = new List<byte>(alignProfile.Length);
            for (int i = 0; i < alignProfile.Length; i++)
            {
                if (alignProfile[i] == '-')
                {
                    ll.Add(0);
                    continue;
                }
                if (m < prof.Count)
                    ll.Add(prof[m++]);
                else
                    ErrorBase.AddErrors("Profile " + profileName + " for " + protName + " seems to be incorect");

            }
            protInfo tmp = new protInfo();
            if (r.profiles[profileName].ContainsKey(protName))
            {
                tmp = r.profiles[profileName][protName];
                tmp.alignment = ll;
                r.profiles[profileName][protName] = tmp;
            }
           

        }
示例#9
0
        public void AddStructureToAlignment(string protName,string profileName,ref protInfo profile)
        {
           
                MAlignment al = new MAlignment(refSeq.Length);
                string resSeq = (al.Align(refSeq, profile.sequence)).seq2;

                if (!align.ContainsKey(protName))
                    align.Add(protName, resSeq);
                if(!r.profiles[profileName].ContainsKey(protName))
                    r.profiles[profileName].Add(protName,profile);
                
            
            AlignProfile(protName, profileName, profile.profile);
            profile.alignment = r.profiles[profileName][protName].alignment;
          
        }
示例#10
0
        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);
        }
示例#11
0
        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;

        }