[Bioperl-l] extract and write a pdb chain
Joan Segura Mora
umjsm at leeds.ac.uk
Mon Dec 14 16:58:03 UTC 2009
Hi again,
To extract a pdb chain in a file, I have had to do it adding atom by
atom to a new structure.
use Bio::Structure::IO;
use strict;
my $structio = Bio::Structure::IO->new(-file => "101m.pdb",'-format' =>
'pdb');
my $struc = $structio->next_structure;
my $new_struct = Bio::Structure::Entry->new( -id => 'structure_id');
for my $model ($struc->get_models){
$new_struct->add_model($model);
for my $chain ($struc->get_chains) {
$new_struct->add_chain($model,$chain);
if($chain->id eq "A"){
foreach my $res ($struc->get_residues($chain)){
$new_struct->add_residue($chain,$res);
foreach my $atom ($struc->get_atoms($res)){
$new_struct->add_atom($res,$atom);
}
}
}
last;
}
last;
}
my $out = Bio::Structure::IO->new(-file => ">out.pdb",'-format' =>
'pdb');
$out->write_structure($new_struct);
I suppose that there should be a more elegant way to do it.
If someone knows it and can explain it I will be very grateful.
kind regards,
Joan
On Mon, 2009-12-14 at 10:39 +0000, Joan Segura Mora wrote:
> Hi Brian,
>
> I am not calling the method add_chain, I am calling the method chain
>
> http://doc.bioperl.org/releases/bioperl-1.0.1/Bio/Structure/Entry.html#POD6
>
> and if I don't use as an argument an object of type
>
> Bio::Structure::Chain
>
> I get an error like this (-->depends of the argument<--)
>
> ------------- EXCEPTION: Bio::Root::Exception -------------
> MSG: Supplied a -->Bio::Structure::Residue=HASH(0x11be6a0)<-- to chain,
> we want a Bio::Structure::Chain or a list of these
>
> STACK: Error::throw
> STACK:
> Bio::Root::Root::throw /usr/local/share/perl/5.8.8/Bio/Root/Root.pm:368
> STACK:
> Bio::Structure::Entry::chain /usr/local/share/perl/5.8.8/Bio/Structure/Entry.pm:314
> STACK: read_pdb.pl:11
> -----------------------------------------------------------
>
>
> And if I use a Chain object I get the error that I told you.
>
> I have try this code:
>
> use Bio::Structure::IO;
> use strict;
>
> my $structio = Bio::Structure::IO->new(-file => "101m.pdb",'-format' =>
> 'pdb');
> my $struc = $structio->next_structure;
> my $new_entry = Bio::Structure::Entry->new( -id => 'structure_id');
> my $model = Bio::Structure::Model->new( -id => '0');
>
> for my $chain ($struc->get_chains) {
> if($chain->id eq "A"){
> $new_entry->add_chain($model,$chain);
>
> last;
> }
> }
> $new_entry->add_model($model);
> my $out = Bio::Structure::IO->new(-file => ">out.pdb",'-format' =>
> 'pdb');
> $out->write_structure($new_entry);
>
>
> But I get an empty pdb
>
> HEADER DEFAULT CLASSIFICATION 24-JAN-70
> stru
> REMARK
> 1
> TER 1 A
> 0
> MASTER
> END
>
> I am trying a lot of combinations, but I can't write a single chain into
> a file. I don't know what I am doing wrong.
>
> Thanks for helping
>
> regards,
> Joan
>
>
> On Fri, 2009-12-11 at 15:37 -0500, Brian Osborne wrote:
> > Joan,
> >
> > It looks to me like the first argument to the add_chain() method has
> > to be a Model object, the second is the Chain itself. See Structure/
> > Entry.pm, for example. However if you're seeing some documentation
> > that says something else then tell us where, it needs to be corrected.
> >
> > In Bio::Structure an Entry consists of one or Models, each of which
> > has one or more Chains. This allows you to build macromolecular
> > complexes (an Entry), which could have more than one defined proteins
> > or protein complexes (Models).
> >
> > Brian O.
> >
> > On Dec 11, 2009, at 11:44 AM, Joan Segura Mora wrote:
> >
> > > Hello,
> > >
> > > I am trying to do a very easy think but I don't get it. I want to
> > > write
> > > in a file a chain of a pdb. I have try a lot of thinks but what I
> > > think
> > > that it should work is the next script:
> > >
> > > use Bio::Structure::IO;
> > > use strict;
> > >
> > > my $structio = Bio::Structure::IO->new(-file => "101m.pdb",'-format'
> > > =>
> > > 'pdb');
> > > my $struc = $structio->next_structure;
> > >
> > > my $new_entry = Bio::Structure::Entry->new( -id => 'structure_id');
> > >
> > > for my $chain ($struc->get_chains) {
> > > if($chain->id eq "A"){
> > > $new_entry->chain($chain);
> > > last;
> > > }
> > > }
> > >
> > > my $out = Bio::Structure::IO->new(-file => ">out.pdb",'-format' =>
> > > 'pdb');#
> > > $out->write_structure($new_entry);
> > >
> > > it doesn't. I get the next error:
> > >
> > > ------------- EXCEPTION: Bio::Root::Exception -------------
> > > MSG: add_chain: first argument needs to be a Model object ()
> > >
> > > STACK: Error::throw
> > > STACK:
> > > Bio::Root::Root::throw /usr/local/share/perl/5.8.8/Bio/Root/Root.pm:
> > > 368
> > > STACK:
> > > Bio::Structure::Entry::add_chain /usr/local/share/perl/5.8.8/Bio/
> > > Structure/Entry.pm:335
> > > STACK:
> > > Bio::Structure::Entry::get_chains /usr/local/share/perl/5.8.8/Bio/
> > > Structure/Entry.pm:391
> > > STACK:
> > > Bio::Structure::Entry::chain /usr/local/share/perl/5.8.8/Bio/
> > > Structure/Entry.pm:304
> > > STACK: read_pdb.pl:10
> > > -----------------------------------------------------------
> > >
> > > As far I understand the documentation, the method chain of the object
> > > Bio::Structure::Entry requires an as input an object of type Chain.
> > >
> > > Any solution will be very welcome.
> > >
> > > best regards,
> > > Joan
> > >
> > > _______________________________________________
> > > Bioperl-l mailing list
> > > Bioperl-l at lists.open-bio.org
> > > http://lists.open-bio.org/mailman/listinfo/bioperl-l
> >
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
More information about the Bioperl-l
mailing list