예제 #1
0
        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);
        }
예제 #2
0
        public string AddPDB(string fileName, PDBMODE flag, CHAIN_MODE flagChain = CHAIN_MODE.SINGLE)
        {
            string name = Path.GetFileName(fileName);

            if (molDic != null && molDic.ContainsKey(name))
            {
                return(name);
            }
            try
            {
                MolData molD = new MolData(fileName, flag, mode, flagChain);
                if ((molD.mol == null || molD.mol.Chains == null || molD.mol.Chains.Count == 0))
                {
                    ErrorBase.AddErrors("PDB reading: file " + fileName + " is removed from consideration it looks that it has wrong format");
                    return(null);
                }
                molDic.Add(name, molD);

                return(name);
            }
            catch (IncorrectSideChainException ex)
            {
                ErrorBase.AddErrors("PDB reading: file " + fileName + " is removed from consideration because\n" + ex.Message);
            }
            catch (Exception ee)
            {
                ErrorBase.AddErrors("PDB reading: file " + fileName + " is removed from consideration because\n" + ee.Message);
            }
            return(null);
        }
예제 #3
0
        //Flag true only CA will be readed
        public MolData(string fileName, PDBMODE flag, INPUTMODE mode, CHAIN_MODE chainFlag = CHAIN_MODE.SINGLE)
        {
            using (StreamReader rr = new StreamReader(fileName))            {
                switch (mode)
                {
                case INPUTMODE.PROTEIN:
                    mol = new Molecule(flag, chainFlag);
                    break;

                case INPUTMODE.RNA:
                    mol = new MoleculeRNA(flag);
                    break;
                }

                bool res = mol.ReadMolecule(rr);
                if (!res)
                {
                    return;
                }
                if (mol.Chains.Count == 0)
                {
                    ErrorBase.AddErrors("Error in reading file: " + fileName + "\nCannot find residues, file will not be considered!");
                    rr.Close();
                    return;
                }
                molLength = mol.Chains[0].chainSequence.Length;
            }
            //CenterMol();
        }
예제 #4
0
        /*  public override bool ReadMolecule()
         * {
         *    return this.ReadAtoms(pdbStream);
         * }*/
        internal override bool ReadAtoms(StreamReader pdbStream)
        {
            this.atoms = new List <Atom>();

//            using (StreamReader pdbReader = new StreamReader(pdbStream))
//          {
            string pdbLine = pdbStream.ReadLine();

            while (pdbLine != null)
            {
                if (pdbLine.StartsWith("ENDMDL") || pdbLine.StartsWith("TER") || pdbLine.StartsWith("END"))
                {
                    break;
                }

                if (pdbLine.StartsWith("ATOM"))
                {
                    if (pdbLine.Contains("\t"))
                    {
                        ErrorBase.AddErrors("ATOM line containes tab what is not allowed");
                        return(false);
                    }
                    AtomRNA atom  = new AtomRNA();
                    string  error = atom.ParseAtomLine(this, pdbLine, flag);
                    if (error == null)
                    {
                        if (flag == PDBMODE.ONLY_P || flag == PDBMODE.ONLY_P_AND_C4)
                        {
                            if (atom.AtomName == "P")
                            {
                                this.atoms.Add(atom);
                            }
                            if (atom.AtomName == "C4*" || atom.AtomName == "C4'")
                            {
                                this.atoms.Add(atom);
                            }
                        }
                        else
                        {
                            this.atoms.Add(atom);
                        }
                    }
                    else
                    {
                        ErrorBase.AddErrors("Error in file: " + ((FileStream)pdbStream.BaseStream).Name + " " + error);
                    }
                }

                pdbLine = pdbStream.ReadLine();
            }
            //        }
            return(true);
        }
예제 #5
0
        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);
        }
예제 #6
0
        private void PDBSAlign(object o)
        {
            Params        p        = (Params)o;
            List <string> toRemove = new List <string>();
            MAlignment    align    = new MAlignment(refSeq.Length);

            DebugClass.WriteMessage("Started");



            foreach (var item in auxFiles[p.k])
            {
                molDic[item].indexMol = new int[refSeq.Length];
                MAlignment.alignSeq alignRes = align.Align(refSeq, molDic[item].mol.Chains[0].chainSequence);


                if (alignRes.seq1.Contains('-'))
                {
                    ErrorBase.AddErrors("Reference structure " + refStuctName + " cannot be used as reference to " + item + " structure because after alignment gaps to referense structure must be added what is not allowed");
                    toRemove.Add(item);
                    continue;
                }
                //string ss = align.Align(molDic[refStuctName].mol.Chains[0].chainSequence, molDic[item].mol.Chains[0].chainSequence).seq2;
                string ss = alignRes.seq2;
                for (int j = 0, count = 0; j < ss.Length; j++)
                {
                    if (ss[j] != '-')
                    {
                        molDic[item].indexMol[j] = count++;
                    }
                    else
                    {
                        molDic[item].indexMol[j] = -1;
                    }
                }
            }
            DebugClass.WriteMessage("Almost done");
            foreach (var item in toRemove)
            {
                molDic.Remove(item);
            }

            resetEvents[p.k].Set();
        }
예제 #7
0
        public string AddPDB(MemoryStream stream, PDBMODE flag, string modelName)
        {
            try
            {
                MolData molD = new MolData();
                if (!molD.ReadMolData(stream, flag, modelName))
                {
                    return(null);
                }
                molDic.Add(modelName, molD);

                return(modelName);
            }
            catch (IncorrectSideChainException ex)
            {
                ErrorBase.AddErrors("PDB reading: file " + modelName + " is removed from consideration because\n" + ex.Message);
            }
            return(null);
        }
예제 #8
0
        private void CreateResidues()
        {
            List <Residue> auxRes     = new List <Residue>();
            List <Atom>    localAtoms = new List <Atom>();
            //this.residues = new List<Residue>();

            Residue residue = null;

            foreach (Atom atom in this.atoms)
            {
                //if (residue == null ||  atom.ResidueSequenceNumber != residue.ResidueSequenceNumber||
                if (residue == null || atom.tabParam[2] != residue.ResidueSequenceNumber ||
                    atom.tabParam[1] != residue.ChainIdentifier)
                //atom.ChainIdentifier != residue.ChainIdentifier)
                {
                    residue = new Residue(this, atom, flag);
                    auxRes.Add(residue);
                }
                else
                {
                    bool test = false;
                    foreach (var item in residue.Atoms)
                    {
                        if (atom.AtomName == item.AtomName)
                        {
                            ErrorBase.AddErrors("Residue " + residue.ResidueName + " has two the same atoms " + atom.AtomName);
                            test = true;
                        }
                    }
                    if (!test)
                    {
                        residue.Atoms.Add(atom);
                    }
                    //residue.AddAtom(atom);
                }
                atom.tabParam = null;
            }
            this.residues = new List <Residue>(auxRes);
            auxRes        = null;
        }
예제 #9
0
        public bool ReadMolData(MemoryStream stream, PDBMODE flag, string modelName)
        {
            StreamReader rr = new StreamReader(stream);

            mol = new Molecule(flag);
            bool res = mol.ReadMolecule(rr);

            if (!res)
            {
                return(false);
            }

            if (mol.Chains.Count == 0)
            {
                ErrorBase.AddErrors("Error in reading file: " + modelName + "\nCannot find residues, file will not be considered!");
                return(false);
            }
            molLength = mol.Chains[0].chainSequence.Length;

            return(true);
            //CenterMol();
        }
예제 #10
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);
        }
예제 #11
0
        public override int Run(object processParams)
        {
            string[] aux;

            System.OperatingSystem osinfo = System.Environment.OSVersion;

            if (osinfo.VersionString.Contains("Win"))
            {
                if (!Environment.Is64BitOperatingSystem)
                {
                    this.ex = new Exception("Dssp profile is not working on 32 bit windows system!");
                    return(0);
                }
            }
            string       currentDir = Directory.GetCurrentDirectory();
            StreamWriter wr;

            wr = new StreamWriter(((ThreadFiles)processParams).fileName);

            if (wr == null)
            {
                this.ex = new Exception("Cannot open file: " + ((ThreadFiles)processParams).fileName);
                return(0);
            }

            List <string> auxFiles = threadingList[((ThreadFiles)processParams).threadNumber];

            try
            {
                foreach (var item in auxFiles)
                {
                    //  wrapper.timeSp = 0;

                    if (!File.Exists(item))
                    {
                        ErrorBase.AddErrors("File " + item + "does not exist");
                        continue;
                    }

                    //wrapper.Run(item,item.Length);
                    //timeSp += wrapper.timeSp;
                    IntPtr pSS   = IntPtr.Zero;
                    IntPtr pSEQ  = IntPtr.Zero;
                    IntPtr pLW   = IntPtr.Zero;
                    string SS    = "";
                    string SEQ   = "";
                    string LW    = "";
                    int    error = 0;

                    IntPtr ptr      = RNAProfiles(item);
                    int    errorNum = 0;
                    if (errorNum > 0)
                    {
                        ErrorBase.AddErrors(item + ": " + RNAViewErrors(error));
                        continue;
                    }
                    pSS  = GetSS(ptr);
                    pLW  = GetLW(ptr);
                    pSEQ = GetSEQ(ptr);
                    if (pSS == IntPtr.Zero || pLW == IntPtr.Zero || pSEQ == IntPtr.Zero)
                    {
                        ErrorBase.AddErrors("Could not create profile for: " + item + " structure");
                        RNAFree(ptr);
                        continue;
                    }
                    DebugClass.WriteMessage("PDB:" + item);
                    SS  = Marshal.PtrToStringAnsi(pSS);
                    SEQ = Marshal.PtrToStringAnsi(pSEQ);
                    LW  = Marshal.PtrToStringAnsi(pLW);
                    aux = item.Split(Path.DirectorySeparatorChar);
                    if (SS != null && SS.Length > 0)
                    {
                        wr.WriteLine(">" + aux[aux.Length - 1]);
                        wr.WriteLine(SSprofile + SS);
                        wr.WriteLine(LWprofile + LW);
                        wr.WriteLine(SEQprofile + SEQ);
                    }
                    RNAFree(ptr);
                    Interlocked.Increment(ref currentProgress);
                }

                wr.Close();
            }
            catch (Exception ex)
            {
                this.ex = ex;
            }
            //currentV = maxV;
            Directory.SetCurrentDirectory(currentDir);
            return(0);
        }
예제 #12
0
        public override int Run(object processParams)
        {
            string[] aux;

            System.OperatingSystem osinfo = System.Environment.OSVersion;

            if (osinfo.VersionString.Contains("Win"))
            {
                if (!Environment.Is64BitOperatingSystem)
                {
                    this.ex = new Exception("Dssp profile is not working on 32 bit windows system!");
                    return(0);
                }
            }

            StreamWriter wr;

            wr = new StreamWriter((( ThreadFiles)processParams).fileName);

            if (wr == null)
            {
                this.ex = new Exception("Cannot open file: " + ((ThreadFiles)processParams).fileName);
                return(0);
            }

            List <string> auxFiles = threadingList[(( ThreadFiles)processParams).threadNumber];

            try
            {
                foreach (var item in auxFiles)
                {
                    //  wrapper.timeSp = 0;

                    if (!File.Exists(item))
                    {
                        ErrorBase.AddErrors("File " + item + "does not exist");
                        continue;
                    }

                    //wrapper.Run(item,item.Length);
                    //timeSp += wrapper.timeSp;
                    IntPtr dsspExt = IntPtr.Zero;
                    IntPtr pSS     = IntPtr.Zero;
                    IntPtr pSA     = IntPtr.Zero;
                    IntPtr pSEQ    = IntPtr.Zero;
                    string SS      = "";
                    string SA      = "";
                    string SEQ     = "";
                    int    error   = 0;


                    dsspExt = PrepProtein();
                    DebugClass.WriteMessage("PDB:" + item);
                    error = ReadProt(item, dsspExt);
                    if (error == 0)
                    {
                        pSS  = GetSS(dsspExt);
                        pSA  = GetSA(dsspExt);
                        pSEQ = GetSEQ(dsspExt);
                        SS   = Marshal.PtrToStringAnsi(pSS);
                        SA   = Marshal.PtrToStringAnsi(pSA);
                        SEQ  = Marshal.PtrToStringAnsi(pSEQ);
                        aux  = item.Split(Path.DirectorySeparatorChar);
                        if (SS != null && SS.Length > 0)
                        {
                            wr.WriteLine(">" + aux[aux.Length - 1]);
                            wr.WriteLine(SSprofile + SS);
                            wr.WriteLine(SAprofile + ConvertSAProfile(SA, SEQ));
                            //wr.WriteLine(PSIprofile + wrapper.PSI);
                            //wr.WriteLine(PHIprofile + wrapper.PHI);
                            wr.WriteLine(SEQprofile + SEQ);
                        }
                    }
                    else
                    {
                        ErrorBase.AddErrors(item + ": " + DSSPErrors(error));
                    }
                    if (dsspExt != IntPtr.Zero)
                    {
                        DisposeMProtein(dsspExt);
                    }
                    if (pSS != IntPtr.Zero)
                    {
                        DisposeBuffor(pSS);
                    }
                    if (pSA != IntPtr.Zero)
                    {
                        DisposeBuffor(pSA);
                    }
                    if (pSEQ != IntPtr.Zero)
                    {
                        DisposeBuffor(pSEQ);
                    }

                    Interlocked.Increment(ref currentProgress);
                }

                wr.Close();
            }
            catch (Exception ex)
            {
                this.ex = ex;
            }
            //currentV = maxV;
            return(0);
        }
예제 #13
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);
        }
예제 #14
0
        internal virtual bool ReadAtoms(StreamReader pdbStream)
        {
            List <Atom> auxList = new List <Atom>();
            //using (StreamReader pdbReader = new StreamReader(pdbStream))
            //{
            string pdbLine = pdbStream.ReadLine();

            while (pdbLine != null)
            {
                if (pdbLine.StartsWith("ENDMDL") /*|| pdbLine.StartsWith("TER") */ || pdbLine.StartsWith("END"))
                {
                    break;
                }
                if (flagChain == CHAIN_MODE.SINGLE)
                {
                    if (pdbLine.StartsWith("TER"))
                    {
                        break;
                    }
                }
                if (pdbLine.StartsWith("ATOM") || pdbLine.StartsWith("HETATM"))
                {
                    if (pdbLine.Contains("\t"))
                    {
                        ErrorBase.AddErrors("Error in file: " + ((FileStream)pdbStream.BaseStream).Name + " " + "ATOM line containes tab what is not allowed");
                        return(false);
                    }
                    Atom   atom  = new Atom();
                    string error = atom.ParseAtomLine(this, pdbLine, flag);
                    if (error == null)
                    {
                        //Check if the atom already exists!!
                        if (flag == PDBMODE.ONLY_CA || flag == PDBMODE.CA_CB || flag == PDBMODE.ONLY_CB || flag == PDBMODE.ONLY_SEQ)
                        {
                            if (flag == PDBMODE.ONLY_CA || flag == PDBMODE.CA_CB || flag == PDBMODE.ONLY_SEQ)
                            {
                                if (atom.AtomName == "CA")
                                {
                                    auxList.Add(atom);
                                }
                            }


                            if (flag == PDBMODE.ONLY_CB || flag == PDBMODE.CA_CB)     //|| (atom.ResidueName=='G' && flag==PDBMODE.ONLY_CA))
                            {
                                if (atom.AtomName == "CB")
                                {
                                    auxList.Add(atom);
                                }
                            }
                        }
                        else
                        {
                            auxList.Add(atom);
                        }
                    }
                    else
                    {
                        ErrorBase.AddErrors("Error in file: " + ((FileStream)pdbStream.BaseStream).Name + " " + error);
                    }
                }

                pdbLine = pdbStream.ReadLine();
            }
            this.atoms = new List <Atom>(auxList);
            //  }
            return(true);
        }