9 use base qw(Root Read);
13 Object to hold some of the information found in a DSSP file.
15 =head2 my $dssp = DSSP->new;
17 Creates new object. Any accessor method is valid to use as an argument in a hash key/value set of pairs.
19 =head2 $dssp->read($string);
21 Reads in the DSSP file contained within the $string. Returns true if it there is information in the file, otherwise false.
26 my ($self, $data) = @_;
28 defined $data or croak "No filehandle passed\n";
30 my $flag = 0; # Test to see if there's any information in the file
33 if (/^ # RESIDUE AA STRUCTURE/) {
39 my $aa_pri = substr($_, 13, 1);
41 # Chain break, has to come here in order to remember what the
53 # If there isn't a chain break, continue as normal
54 my $aa_sec = substr($_, 16, 1);
55 my $aa_acc = substr($_, 35, 3);
56 $chain = substr($_, 11, 1);
58 # Field is six wide to include alternatives, but I'm ignoring
60 my $pos = substr($_, 5, 6);
61 my $seq_pos = substr($_, 0, 5);
63 # Replace empty chain defn with NULL
64 $chain = 'NULL' if $chain eq ' ';
66 # Replace lower case letters (cystine
67 # bridge pairs) with 'c'
68 $aa_pri =~ tr/[a-z]/c/;
72 # Remove any padding whitespace
73 for ($aa_pri, $aa_sec, $aa_acc, $chain, $pos, $seq_pos) {
94 =head2 $dssp->add_position($DSSP::Position);
96 Adds a position object.
101 my ($self, $pos) = @_;
103 unless (defined $pos and isa $pos, 'DSSP::Position') {
104 croak "No object passed"
107 my ($chain, $offset);
109 defined($chain = $pos->chain) or croak "Chain not set\n";
110 unless ($pos->break) {
111 defined($offset = $pos->off) or croak "Offset not set\n";
114 # Use a stack based system now
115 push @{ $self->{__PACKAGE__."pos"}{$chain} }, $pos;
117 # This is for backwards compatibility, shudder, also required changes in
118 # get_position() and position()
119 unless ($pos->break) {
120 $self->{__PACKAGE__."offset_compat"}{offset}{$chain}{$offset} = \$self->{__PACKAGE__."pos"}{$chain}->[ -1 ];
122 if (exists $self->{__PACKAGE__."pos"}{offset}{$chain}{$offset}) {
123 my $out = "Overwriting DSSP position $offset in chain $chain";
124 $out .= $self->path ? " for file ".$self->path."\n" : "\n";
129 # Add the chain if not already present
130 my @chains = grep { defined } $self->chains;
131 unless (grep { $chain eq $_ } @chains) {
132 $self->chains(@chains, $chain);
136 =head2 $DSSP::Position = $dssp->get_chain_defs($chain)
138 New method to replace get_position() and positions(). Returns all of the DSSP::Position objects for a particular chain in the order they are seen in the DSSP file. Then you have to decide what to do with them.
143 my ($self, $chain) = @_;
145 croak "Chain not recognised" unless grep { $_ eq $chain } $self->chains;
147 return @{ $self->{__PACKAGE__."pos"}{$chain} };
150 =head2 $DSSP::Position = $dssp->get_position($chain, $offset)
152 Depricated! Don't use this methods as it's broken, it's available for backwards compatibility.
154 Returns the position object for a particular location.
159 my ($self, $chain, $offset) = @_;
161 unless (defined $chain) { croak "No chain given" }
162 unless (defined $offset) { croak "No offset given" }
164 confess("No such chain '$chain'") and return unless exists $self->{__PACKAGE__."pos"}{$chain};
166 confess("No such offset $offset in chain $chain") and return
167 #unless exists $self->{__PACKAGE__."pos"}{$chain};
168 unless exists $self->{__PACKAGE__."offset_compat"}{offset}{$chain}{$offset};
170 return ${ $self->{__PACKAGE__."offset_compat"}{offset}{$chain}{$offset} };
173 =head2 $DSSP::Position = $dssp->positions($chain);
175 Depricated! Don't use this methods as it's broken, it's available for backwards compatibility.
177 Returns all the offsets that are available for a particular chain, sorted by offset.
182 my ($self, $chain) = @_;
184 unless (defined $chain) { croak "No chain given" }
186 croak "No such chain $chain" unless exists $self->{__PACKAGE__."pos"}{$chain};
190 map { join "", @{$_} }
191 sort { $a->[0] <=> $b->[0] || $a->[1] cmp $b->[1] }
192 map { [ /^(-?\d+)(\D+)?$/ ] }
193 #keys %{$self->{__PACKAGE__."pos"}{$chain}};
194 keys %{$self->{__PACKAGE__."offset_compat"}{offset}{$chain}};
197 =head2 @chains = $dssp->chains;
199 Finds the chains in the structure, or alters them, but don't do that. Returns an empty list if no chains have been found.
204 my ($self, @chains) = @_;
205 if (@chains) { @{$self->{__PACKAGE__."chains"}} = @chains }
206 elsif ($self->{__PACKAGE__."chains"}) {
207 return @{ $self->{__PACKAGE__."chains"} };
214 =head1 DSSP::Position
216 Object to hold information on each position of a DSSP output.
218 =head2 my $dssp_pos = DSSP::Position->new;
232 Holds the primary structre.
236 Holds the secondary structre.
240 Holds the solvent structre.
244 Holds the position in the PDB structure.
250 use Class::Struct "DSSP::Position" => {