Exemple #1
0
        public ILoopsCollection Search(IPdb Pdb)
        {
            ILoopsCollection LoopsCollection = new ILoopsCollection();
            ILoopCriteria    LoopCriteria    = new ILoopCriteria(true);

            //Try some LINQ on this beast
            var Chains = (from p in Pdb.Atoms select p.Chain).Distinct();

            foreach (string ChainName in Chains)
            {
                //Get all the atoms in the chain
                var        Chain        = (from p in Pdb.Atoms where p.Chain == ChainName select p);
                IResidue[] AtomsInChain = Chain.ToArray();

                //Set the chain length if it is not explicitly set (full length here)
                if (LoopCriteria.Start == -1)
                {
                    LoopCriteria.Start = 0;
                }
                if (LoopCriteria.End == -1)
                {
                    LoopCriteria.End = AtomsInChain.Count();
                }

                //Search for the loops
                if (LoopCriteria.Length > AtomsInChain.Count())
                {
                    continue;
                }
                for (int i = LoopCriteria.Start; i < LoopCriteria.End - LoopCriteria.Length - 1; i++)
                {
                    //Check for the terminal distances
                    double eDistance = EuclideanDistance(AtomsInChain[i], AtomsInChain[i + LoopCriteria.Length]);
                    if (eDistance < LoopCriteria.TerminiDistanceThreshold)
                    {
                        //Passes the Distance Test

                        //Check for the solvent accessible regions
                        if (LoopCriteria.SolventAccessible)
                        {
                            List <IResidue> LoopResidues = new List <IResidue>();
                            for (int j = i; j < i + LoopCriteria.Length; j++)
                            {
                                LoopResidues.Add(AtomsInChain[j]);
                            }
                            IResidue ApexResidue = IsLoopVectorSolventAccessible(Pdb.Atoms, LoopResidues, 4, LoopCriteria);
                            //IResidue ApexResidue = IsLoopSolventAccessible(Pdb.Atoms, LoopResidues, LoopCriteria);
                            if (ApexResidue != null)
                            {
                                //Passes the solvent test, add it to the loop collection
                                ILoop Loop = new ILoop();
                                Loop.NTermAtom   = AtomsInChain[i];
                                Loop.NTermAtomP1 = AtomsInChain[i + 1];
                                Loop.NTermAtomP2 = AtomsInChain[i + 2];
                                Loop.CTermAtom   = AtomsInChain[i + LoopCriteria.Length];
                                Loop.CTermAtomP1 = AtomsInChain[i + LoopCriteria.Length - 1];
                                Loop.CTermAtomP2 = AtomsInChain[i + LoopCriteria.Length - 2];
                                Loop.LoopLength  = LoopCriteria.Length;
                                Loop.PdbCode     = Pdb.PdbCode;
                                Loop.Chain       = ChainName;
                                Loop.ApexAtom    = ApexResidue;


                                Loop.UnitVector = new Vector3D(((Loop.NTermAtomP2.X + Loop.CTermAtomP2.X) / 2) - ((Loop.NTermAtom.X + Loop.CTermAtom.X) / 2),
                                                               ((Loop.NTermAtomP2.Y + Loop.CTermAtomP2.Y) / 2) - ((Loop.NTermAtom.Y + Loop.CTermAtom.Y) / 2),
                                                               ((Loop.NTermAtomP2.X + Loop.CTermAtomP2.X) / 2) - ((Loop.NTermAtom.X + Loop.CTermAtom.X) / 2));

                                //Ensure Beta-Loop-Beta
                                if (EuclideanDistance(Loop.NTermAtom, Loop.CTermAtom) < LoopCriteria.TerminiDistanceThreshold &&
                                    EuclideanDistance(Loop.NTermAtomP1, Loop.CTermAtomP1) < LoopCriteria.TerminiDistanceThreshold &&
                                    EuclideanDistance(Loop.NTermAtomP2, Loop.CTermAtomP2) < LoopCriteria.TerminiDistanceThreshold)
                                {
                                    LoopsCollection.Add(Loop);
                                }
                            }
                        }
                    }
                }
                LoopCriteria.End   = -1;
                LoopCriteria.Start = -1;
            }

            //Cleanup
            LoopCriteria = null;

            //Return
            return(CleanupLoops(LoopsCollection));
        }
Exemple #2
0
        static void Main(string[] args)
        {
            #region Argument Parameters

            string OutputFilename;
            string PdbDirectory         = @"C:\PDB\Monomer";
            string PdbMultimerDirectory = @"C:\Archives\Biounits";
            string PdbFile       = @"C:\PDB\Monomer\pdb1rcv.ent.gz";
            bool   useMultimeric = false;

            #endregion

            ILoopCriteria LoopCriteria = new ILoopCriteria();

            Arguments CommandLine = new Arguments(args);
            if (CommandLine["directory"] != null)
            {
                PdbDirectory = CommandLine["directory"];
            }

            if (CommandLine["multimeric"] != null)
            {
                useMultimeric = true;
            }

            if (CommandLine["searchfortrimer"] != null)
            {
                LoopCriteria.SearchForTrimer    = true;
                LoopCriteria.SearchForLoopPairs = false;
            }

            if (CommandLine["file"] != null)
            {
                PdbFile = CommandLine["file"];
            }

            if (CommandLine["match"] != null)
            {
                LoopCriteria.SearchForLoopPairs = true;
                if (CommandLine["lower"] != null)
                {
                    LoopCriteria.LoopPairDistanceLowerLimit = Convert.ToDouble(CommandLine["lower"]);
                }
                if (CommandLine["upper"] != null)
                {
                    LoopCriteria.LoopPairDistanceUpperLimit = Convert.ToDouble(CommandLine["upper"]);
                }
            }
            else
            {
                LoopCriteria.SearchForLoopPairs = false;
            }

            if (CommandLine["out"] != null)
            {
                OutputFilename = CommandLine["out"];
            }
            else
            {
                OutputFilename = "ScaffoldFinderLog_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
            }



            string     LogFilename = @"c:\Archives\Output\" + OutputFilename;
            FileStream LogStream   = File.Open(LogFilename,
                                               FileMode.CreateNew,
                                               FileAccess.Write);
            StreamWriter LogFile = new StreamWriter(LogStream, Encoding.UTF8);


            //Write the lof file header
            if (LoopCriteria.SearchForLoopPairs)
            {
                LogFile.WriteLine("PDB,ChainA,NTermLoopA,CTermLoopA,Length,ChainB,NTermLoopB,CTermLoopB,LengthB,Size");
            }
            else if (LoopCriteria.SearchForTrimer)
            {
                LogFile.WriteLine("PDB,ChainA,NTermLoopA,CTermLoopA,Length,ChainB,NTermLoopB,CTermLoopB,LengthB,ChainC,NTermLoopC,CTermLoopC,LengthC");
            }
            else
            {
                LogFile.WriteLine("PDB,Chain,NTerm,CTerm,Length");
            }


            //Loop through the directory to get the PDBs
            DirectoryInfo Directory;
            if (useMultimeric)
            {
                Directory = new DirectoryInfo(PdbMultimerDirectory);
            }
            else
            {
                Directory = new DirectoryInfo(PdbDirectory);
            }

            int FileCounter = 0;
            int FileTotals  = Directory.GetFiles().Count();
            foreach (FileInfo file in Directory.GetFiles())
            {
                FileCounter++;
                if (FileCounter % 500 == 0)
                {
                    Console.WriteLine("[" + FileCounter + "/" + FileTotals + "]: " + file.FullName);
                }
                //Console.SetCursorPosition(0, Console.CursorTop);

                //Console.WriteLine("Filename: " + file.Name + "  Size: " + file.Length);
                if (file.Length > 500000)
                {
                    continue;
                }
                IPdb             Pdb             = new IPdb(file.FullName, useMultimeric);
                ILoopsCollection LoopsCollection = new ILoopsCollection();
                if (Pdb.Atoms.Count() != 0)   // Implies Nucleic Acid
                {
                    FindLoops findLoops = new FindLoops();
                    LoopsCollection = findLoops.Search(Pdb);
                    //LoopsCollection = FindLoops.Search(Pdb);
                    findLoops = null;
                }
                else
                {
                    continue;
                }

                //Search for three loops that match the trimer constraints
                if (LoopCriteria.SearchForTrimer)
                {
                    FindLoops          findLoops  = new FindLoops();
                    List <ILoopTrimer> LoopTrimer = findLoops.FindTrimerLoops(LoopsCollection, LoopCriteria);

                    foreach (ILoopTrimer Loops in LoopTrimer)
                    {
                        LogFile.WriteLine(Loops.LoopA.PdbCode + "," +
                                          Loops.LoopA.Chain + "," +
                                          Loops.LoopA.NTermAtom.ResidueNumber + Loops.LoopA.NTermAtom.ResidueExtension + "," +
                                          Loops.LoopA.CTermAtom.ResidueNumber + Loops.LoopA.CTermAtom.ResidueExtension + "," +
                                          Loops.LoopA.LoopLength + "," +
                                          Loops.LoopB.Chain + "," +
                                          Loops.LoopB.NTermAtom.ResidueNumber + Loops.LoopB.NTermAtom.ResidueExtension + "," +
                                          Loops.LoopB.CTermAtom.ResidueNumber + Loops.LoopB.CTermAtom.ResidueExtension + "," +
                                          Loops.LoopB.LoopLength + "," +
                                          Loops.LoopC.Chain + "," +
                                          Loops.LoopC.NTermAtom.ResidueNumber + Loops.LoopC.NTermAtom.ResidueExtension + "," +
                                          Loops.LoopC.CTermAtom.ResidueNumber + Loops.LoopC.CTermAtom.ResidueExtension + "," +
                                          Loops.LoopC.LoopLength);
                    }

                    LoopTrimer = null;
                    findLoops  = null;
                }

                else if (LoopCriteria.SearchForLoopPairs)
                {
                    FindLoops        findLoops = new FindLoops();
                    List <ILoopPair> LoopPairs = findLoops.FindMatchedLoops(LoopsCollection, LoopCriteria);
                    foreach (ILoopPair LoopPair in LoopPairs)
                    {
                        Console.WriteLine("Found: " + LoopPair.LoopA.PdbCode);
                        LogFile.WriteLine(LoopPair.LoopA.PdbCode + "," +
                                          LoopPair.LoopA.Chain + "," +
                                          LoopPair.LoopA.NTermAtom.ResidueNumber + LoopPair.LoopA.NTermAtom.ResidueExtension + "," +
                                          LoopPair.LoopA.CTermAtom.ResidueNumber + LoopPair.LoopA.CTermAtom.ResidueExtension + "," +
                                          LoopPair.LoopA.LoopLength + "," +
                                          LoopPair.LoopB.Chain + "," +
                                          LoopPair.LoopB.NTermAtom.ResidueNumber + LoopPair.LoopB.NTermAtom.ResidueExtension + "," +
                                          LoopPair.LoopB.CTermAtom.ResidueNumber + LoopPair.LoopB.CTermAtom.ResidueExtension + "," +
                                          LoopPair.LoopB.LoopLength + "," +
                                          Pdb.Atoms.Count());
                    }
                    LoopPairs = null;
                    findLoops = null;
                }

                else
                {
                    foreach (ILoop Loop in LoopsCollection.Loops)
                    {
                        LogFile.WriteLine(Loop.PdbCode + "," +
                                          Loop.Chain + "," +
                                          Loop.NTermAtom.ResidueNumber + Loop.NTermAtom.ResidueExtension + "," +
                                          Loop.CTermAtom.ResidueNumber + Loop.CTermAtom.ResidueExtension + "," +
                                          Loop.LoopLength);
                    }
                    //Cleanup
                }
            }

            LogFile.Close();
            LogStream.Close();


            // Console.ReadLine();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            #region Argument Parameters

            string OutputFilename;
            string PdbDirectory = @"C:\PDB\Monomer";
            string PdbMultimerDirectory = @"C:\Archives\Biounits";
            string PdbFile = @"C:\PDB\Monomer\pdb1rcv.ent.gz";
            bool useMultimeric = false;

            #endregion

            ILoopCriteria LoopCriteria = new ILoopCriteria();

            Arguments CommandLine = new Arguments(args);
            if (CommandLine["directory"] != null) {
                PdbDirectory = CommandLine["directory"];
            }

            if (CommandLine["multimeric"] != null) {
                useMultimeric = true;
            }

            if (CommandLine["searchfortrimer"] != null)
            {
                LoopCriteria.SearchForTrimer = true;
                LoopCriteria.SearchForLoopPairs = false;
            }

            if (CommandLine["file"] != null) {
                PdbFile = CommandLine["file"];
            }

            if (CommandLine["match"] != null) {
                LoopCriteria.SearchForLoopPairs = true;
                if (CommandLine["lower"] != null) {
                    LoopCriteria.LoopPairDistanceLowerLimit = Convert.ToDouble(CommandLine["lower"]);
                }
                if (CommandLine["upper"] != null) {
                    LoopCriteria.LoopPairDistanceUpperLimit = Convert.ToDouble(CommandLine["upper"]);
                }
            }
            else {
                LoopCriteria.SearchForLoopPairs = false;
            }

            if (CommandLine["out"] != null) {
                OutputFilename = CommandLine["out"];
            }
            else {
                OutputFilename = "ScaffoldFinderLog_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
            }

            string LogFilename = @"c:\Archives\Output\" + OutputFilename;
            FileStream LogStream = File.Open(LogFilename,
                                    FileMode.CreateNew,
                                    FileAccess.Write);
            StreamWriter LogFile = new StreamWriter(LogStream, Encoding.UTF8);

            //Write the lof file header
            if (LoopCriteria.SearchForLoopPairs) {
                LogFile.WriteLine("PDB,ChainA,NTermLoopA,CTermLoopA,Length,ChainB,NTermLoopB,CTermLoopB,LengthB,Size");
            }
            else if (LoopCriteria.SearchForTrimer)
            {
                LogFile.WriteLine("PDB,ChainA,NTermLoopA,CTermLoopA,Length,ChainB,NTermLoopB,CTermLoopB,LengthB,ChainC,NTermLoopC,CTermLoopC,LengthC");
            }
            else
            {
                LogFile.WriteLine("PDB,Chain,NTerm,CTerm,Length");
            }

            //Loop through the directory to get the PDBs
            DirectoryInfo Directory;
            if (useMultimeric) {
                Directory = new DirectoryInfo(PdbMultimerDirectory);

            }
            else {
                Directory = new DirectoryInfo(PdbDirectory);
            }

            int FileCounter = 0;
            int FileTotals = Directory.GetFiles().Count();
            foreach (FileInfo file in Directory.GetFiles())
            {
                FileCounter++;
                if (FileCounter % 500 == 0) {
                    Console.WriteLine("[" + FileCounter + "/" + FileTotals + "]: " + file.FullName);
                }
                //Console.SetCursorPosition(0, Console.CursorTop);

                //Console.WriteLine("Filename: " + file.Name + "  Size: " + file.Length);
                if (file.Length > 500000)
                {
                    continue;
                }
                IPdb Pdb = new IPdb(file.FullName, useMultimeric);
                ILoopsCollection LoopsCollection = new ILoopsCollection();
                if (Pdb.Atoms.Count() != 0) { // Implies Nucleic Acid
                    FindLoops findLoops = new FindLoops();
                    LoopsCollection = findLoops.Search(Pdb);
                    //LoopsCollection = FindLoops.Search(Pdb);
                    findLoops = null;

                }
                else {
                    continue;
                }

                //Search for three loops that match the trimer constraints
                if(LoopCriteria.SearchForTrimer) {
                    FindLoops findLoops = new FindLoops();
                    List<ILoopTrimer> LoopTrimer = findLoops.FindTrimerLoops(LoopsCollection, LoopCriteria);

                    foreach (ILoopTrimer Loops in LoopTrimer)
                    {
                        LogFile.WriteLine(Loops.LoopA.PdbCode + "," +
                                          Loops.LoopA.Chain + "," +
                                          Loops.LoopA.NTermAtom.ResidueNumber + Loops.LoopA.NTermAtom.ResidueExtension + "," +
                                          Loops.LoopA.CTermAtom.ResidueNumber + Loops.LoopA.CTermAtom.ResidueExtension + "," +
                                          Loops.LoopA.LoopLength + "," +
                                          Loops.LoopB.Chain + "," +
                                          Loops.LoopB.NTermAtom.ResidueNumber + Loops.LoopB.NTermAtom.ResidueExtension + "," +
                                          Loops.LoopB.CTermAtom.ResidueNumber + Loops.LoopB.CTermAtom.ResidueExtension + "," +
                                          Loops.LoopB.LoopLength + "," +
                                          Loops.LoopC.Chain + "," +
                                          Loops.LoopC.NTermAtom.ResidueNumber + Loops.LoopC.NTermAtom.ResidueExtension + "," +
                                          Loops.LoopC.CTermAtom.ResidueNumber + Loops.LoopC.CTermAtom.ResidueExtension + "," +
                                          Loops.LoopC.LoopLength);
                    }

                    LoopTrimer = null;
                    findLoops = null;
                }

                else if (LoopCriteria.SearchForLoopPairs) {
                    FindLoops findLoops = new FindLoops();
                    List<ILoopPair> LoopPairs = findLoops.FindMatchedLoops(LoopsCollection, LoopCriteria);
                    foreach (ILoopPair LoopPair in LoopPairs)
                    {
                        Console.WriteLine("Found: " + LoopPair.LoopA.PdbCode);
                        LogFile.WriteLine(LoopPair.LoopA.PdbCode + "," +
                                          LoopPair.LoopA.Chain + "," +
                                          LoopPair.LoopA.NTermAtom.ResidueNumber + LoopPair.LoopA.NTermAtom.ResidueExtension + "," +
                                          LoopPair.LoopA.CTermAtom.ResidueNumber + LoopPair.LoopA.CTermAtom.ResidueExtension + "," +
                                          LoopPair.LoopA.LoopLength + "," +
                                          LoopPair.LoopB.Chain + "," +
                                          LoopPair.LoopB.NTermAtom.ResidueNumber + LoopPair.LoopB.NTermAtom.ResidueExtension + "," +
                                          LoopPair.LoopB.CTermAtom.ResidueNumber + LoopPair.LoopB.CTermAtom.ResidueExtension + "," +
                                          LoopPair.LoopB.LoopLength + "," +
                                          Pdb.Atoms.Count()) ;
                    }
                    LoopPairs = null;
                    findLoops = null;

                }

                else
                {

                    foreach (ILoop Loop in LoopsCollection.Loops)
                    {

                        LogFile.WriteLine(Loop.PdbCode + "," +
                                          Loop.Chain + "," +
                                          Loop.NTermAtom.ResidueNumber + Loop.NTermAtom.ResidueExtension + "," +
                                          Loop.CTermAtom.ResidueNumber + Loop.CTermAtom.ResidueExtension + "," +
                                          Loop.LoopLength);

                    }
                    //Cleanup

                }
            }

            LogFile.Close();
            LogStream.Close();

               // Console.ReadLine();
        }
        public ILoopsCollection Search(IPdb Pdb)
        {
            ILoopsCollection LoopsCollection = new ILoopsCollection();
            ILoopCriteria LoopCriteria = new ILoopCriteria(true);

            //Try some LINQ on this beast
            var Chains = (from p in Pdb.Atoms select p.Chain).Distinct();

            foreach (string ChainName in Chains)
            {
                //Get all the atoms in the chain
                var Chain = (from p in Pdb.Atoms where p.Chain == ChainName select p);
                IResidue[] AtomsInChain = Chain.ToArray();

                //Set the chain length if it is not explicitly set (full length here)
                if(LoopCriteria.Start == -1) { LoopCriteria.Start = 0; }
                if(LoopCriteria.End == -1) { LoopCriteria.End = AtomsInChain.Count(); }

                //Search for the loops
                if (LoopCriteria.Length > AtomsInChain.Count()) { continue; }
                for (int i = LoopCriteria.Start; i < LoopCriteria.End - LoopCriteria.Length-1; i++)
                {
                    //Check for the terminal distances
                    double eDistance = EuclideanDistance(AtomsInChain[i], AtomsInChain[i + LoopCriteria.Length]);
                    if (eDistance < LoopCriteria.TerminiDistanceThreshold) {
                        //Passes the Distance Test

                        //Check for the solvent accessible regions
                        if (LoopCriteria.SolventAccessible) {
                            List<IResidue> LoopResidues = new List<IResidue>();
                            for (int j = i; j < i + LoopCriteria.Length; j++) { LoopResidues.Add(AtomsInChain[j]); }
                            IResidue ApexResidue = IsLoopVectorSolventAccessible(Pdb.Atoms, LoopResidues, 4, LoopCriteria);
                            //IResidue ApexResidue = IsLoopSolventAccessible(Pdb.Atoms, LoopResidues, LoopCriteria);
                            if (ApexResidue!=null) {
                                //Passes the solvent test, add it to the loop collection
                                ILoop Loop = new ILoop();
                                Loop.NTermAtom = AtomsInChain[i];
                                Loop.NTermAtomP1 = AtomsInChain[i + 1];
                                Loop.NTermAtomP2 = AtomsInChain[i + 2];
                                Loop.CTermAtom = AtomsInChain[i + LoopCriteria.Length];
                                Loop.CTermAtomP1 = AtomsInChain[i + LoopCriteria.Length - 1];
                                Loop.CTermAtomP2 = AtomsInChain[i + LoopCriteria.Length - 2];
                                Loop.LoopLength = LoopCriteria.Length;
                                Loop.PdbCode = Pdb.PdbCode;
                                Loop.Chain = ChainName;
                                Loop.ApexAtom = ApexResidue;

                                Loop.UnitVector = new Vector3D(((Loop.NTermAtomP2.X + Loop.CTermAtomP2.X) / 2) - ((Loop.NTermAtom.X + Loop.CTermAtom.X) / 2),
                                    ((Loop.NTermAtomP2.Y + Loop.CTermAtomP2.Y) / 2) - ((Loop.NTermAtom.Y + Loop.CTermAtom.Y) / 2),
                                    ((Loop.NTermAtomP2.X + Loop.CTermAtomP2.X) / 2) - ((Loop.NTermAtom.X + Loop.CTermAtom.X) / 2));

                                //Ensure Beta-Loop-Beta
                                if (EuclideanDistance(Loop.NTermAtom, Loop.CTermAtom) < LoopCriteria.TerminiDistanceThreshold &&
                                    EuclideanDistance(Loop.NTermAtomP1, Loop.CTermAtomP1) < LoopCriteria.TerminiDistanceThreshold &&
                                    EuclideanDistance(Loop.NTermAtomP2, Loop.CTermAtomP2) < LoopCriteria.TerminiDistanceThreshold)
                                {
                                    LoopsCollection.Add(Loop);
                                }
                            }
                        }
                    }

                }
                LoopCriteria.End = -1;
                LoopCriteria.Start = -1;

            }

            //Cleanup
            LoopCriteria = null;

            //Return
            return CleanupLoops(LoopsCollection);
        }