Example #1
0
        private void AlignProfile(string protName, string profileName, List <byte> prof)
        {
            List <byte> ll = new List <byte>(prof.Count);
            int         m  = 0;

            if (align == null || align[profileName] == null || !align[profileName].ContainsKey(protName))
            {
                foreach (var item in prof)
                {
                    ll.Add(item);
                }
            }
            else
            {
                string alignProfile = align[profileName][protName];

                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;
            }
        }
Example #2
0
        public int GetProfileLength()
        {
            if (profiles == null || profiles.Count == 0)
            {
                return(0);
            }


            List <string> profName = new List <string>(profiles.Keys);
            List <string> protName = new List <string>(profiles[profName[0]].Keys);

            if (protName == null || protName.Count == 0)
            {
                return(0);
            }

            protInfo info = profiles[profName[0]][protName[0]];

            return(info.alignment.Count);
        }
Example #3
0
        public Dictionary <string, protInfo> ReadProfile(profileNode node)
        {
            string   line;
            bool     flag = false;
            protInfo profile;
            Dictionary <string, protInfo> profList = new Dictionary <string, protInfo>();
            string protName;

            if (File.Exists(node.OutFileName))
            {
                StreamReader file = null;
                try
                {
                    file = new StreamReader(node.OutFileName);
                    line = file.ReadLine();
                    while (line != null)
                    {
                        if (line.Contains(">"))
                        {
                            string[] profState;
                            profile = new protInfo();
                            flag    = true;
                            string [] nameTmp;
                            protName = line.Replace(">", "");

                            nameTmp          = protName.Split(new char [] { '/', '\\' });
                            protName         = nameTmp[nameTmp.Length - 1];
                            profile.sequence = file.ReadLine();
                            line             = file.ReadLine();
                            profState        = line.Split(' ');

                            profile.profile = new List <byte>(profState.Length);
                            foreach (var item in profState)
                            {
                                profile.profile.Add(node.GetCodedState(item));
                            }
                            if (profile.sequence.Length > 5 || profile.profile.Count != 0)
                            {
                                profList.Add(protName, profile);
                            }
                            line = file.ReadLine();
                        }
                        else
                        {
                            line = file.ReadLine();
                        }
                    }
                }
                finally
                {
                    if (file != null)
                    {
                        file.Close();
                    }
                }
                if (!flag)
                {
                    throw new Exception("Error: In the profile file: " + node.OutFileName + " could not find line that begins with > ");
                }
            }

            return(profList);
        }
Example #4
0
        public Dictionary <string, List <byte> > CombineProfiles(string protName, Dictionary <string, Dictionary <string, protInfo> > pr)
        {
            if (protCombineStates == null)
            {
                protCombineStates = new Dictionary <string, List <byte> >();
            }

            if (combine == profileCombination.JOIN_STATES)
            {
                List <string> profName = new List <string>(pr.Keys);
                List <string> states   = new List <string>(pr[profName[0]][protName].alignment.Count);
                protInfo      info     = pr[profName[0]][protName];

                for (int i = 0; i < info.alignment.Count; i++)
                {
                    string currentState = "";
                    foreach (var profileName in pr.Keys)
                    {
                        byte cc = pr[profileName][protName].alignment[i];
                        if (cc == 0)
                        {
                            currentState = "0";
                            break;
                        }
                        currentState += cc.ToString();
                    }
                    states.Add(currentState);
                }
                if (states.Count > 0)
                {
                    //return states;
                    if (protCombineStates.Count > 0)
                    {
                        List <string> keys = new List <string>(protCombineStates.Keys);
                        if (states.Count == protCombineStates[keys[0]].Count)
                        {
                            AddItemsCombineStates(protName, states);
                        }
                        else
                        {
                            ErrorBase.AddErrors("Wrong alignment: " + protName);
                        }
                    }
                    else
                    {
                        AddItemsCombineStates(protName, states);
                    }
                }
            }
            else
            {
                List <string> profNames = new List <string>(pr.Keys);

                for (int i = 0; i < profNames.Count; i++)
                {
                    List <string> codes = new List <string>();
                    foreach (var code in pr[profNames[i]][protName].alignment)
                    {
                        if (code != 0)
                        {
                            codes.Add(code.ToString() + "_" + i);
                        }
                        else
                        {
                            codes.Add("0");
                        }
                        AddItemsCombineStates(protName, codes);
                        codes.Clear();
                    }
                }
            }
            return(protCombineStates);
        }