Exemple #1
0
        private static PdbModel ConstructModel(
            IList <string> modelLines,
            IList <string> annotationLines,
            PdbReaderOptions options)
        {
            var chainIds = ExtractChainIds(modelLines);
            var chains   = new List <Peptide>();

            foreach (var chainId in chainIds)
            {
                try
                {
                    var chain = ExtractChain(modelLines, annotationLines, chainId, options);
                    if (!chain.AminoAcids.Any())
                    {
                        continue;
                    }
                    chains.Add(chain);
                }
                catch (ChemistryException chemException)
                {
                    // TODO: Log
                }
                catch
                {
                    chains.ForEach(chain => chain.Dispose());
                    throw;
                }
            }
            return(new PdbModel(chains.ToArray()));
        }
Exemple #2
0
        private static Peptide ExtractChain(
            IList <string> modelLines,
            IList <string> annotationLines,
            char chainId,
            PdbReaderOptions options)
        {
            var aminoAcidSequence = ExtractSequence(modelLines, chainId);

            if (!aminoAcidSequence.Any())
            {
                return(new Peptide(new MoleculeReference(new Molecule()), new List <AminoAcidReference>()));
            }
            var peptide = PeptideBuilder.PeptideFromSequence(aminoAcidSequence, new PeptideBuilderOptions {
                BuildMolecule = options.BuildMolecule
            });

            peptide.ChainId = chainId;
            var annotations = ExtractAnnotations(annotationLines, chainId, peptide);

            peptide.Annotations.AddRange(annotations);
            if (options.BuildMolecule)
            {
                ReadAtomPositions(modelLines, chainId, peptide);
            }
            return(peptide);
        }
Exemple #3
0
        public static PdbReaderResult ReadFile(string filename, PdbReaderOptions options = null)
        {
            if (options == null)
            {
                options = new PdbReaderOptions();
            }
            var lines  = File.ReadAllLines(filename);
            var models = ExtractModels(lines, options);

            return(new PdbReaderResult(models));
        }
Exemple #4
0
        private static PdbModel[] ExtractModels(
            string[] lines,
            PdbReaderOptions options)
        {
            var annotationLines = GetAnnotationLines(lines);
            var models          = new List <PdbModel>();
            var modelLines      = new List <string>();
            var modelStarted    = false;

            try
            {
                foreach (var line in lines)
                {
                    if (!modelStarted && ReadLineCode(line).InSet("MODEL", "ATOM"))
                    {
                        modelStarted = true;
                    }
                    if (!modelStarted)
                    {
                        continue;
                    }
                    modelLines.Add(line);
                    if (ReadLineCode(line) == "ENDMDL")
                    {
                        models.Add(ConstructModel(modelLines, annotationLines, options));
                        modelStarted = false;
                        modelLines.Clear();
                        if (options.MaximumModelCount.HasValue && models.Count >= options.MaximumModelCount.Value)
                        {
                            break;
                        }
                    }
                }
                if (modelStarted)
                {
                    models.Add(ConstructModel(modelLines, annotationLines, options));
                }
            }
            catch
            {
                models.ForEach(model => model.Dispose());
                throw;
            }

            return(models.ToArray());
        }