source: branches/profile/PERL_SCRIPTS/ARBTOOLS/IFTHELP/format_dssp.pl

Last change on this file was 6345, checked in by westram, 14 years ago
  • fixed hard readable '} else {'
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6my $line = undef;
7my $titleline = undef;
8my $pdb_id = undef;
9my $header = undef;
10my $compnd = undef;
11my $source = undef;
12my $date = undef;
13my $author = undef;
14my $reference = undef;
15my @chains = (' ');
16my @sequences = ('');
17my @secstructs = ('');
18my $seqnum = 0;
19my $mode = 0;
20
21foreach $line (<STDIN>) {
22  chomp($line);
23  if ($mode==0) {
24    if ($line =~ /^(==== Secondary Structure Definition.+)\s+\.$/) {
25      $titleline = $1;
26    }
27    elsif ($line =~ /^REFERENCE\s+(.+);*\s+\.$/) {
28      $reference = $1;
29      $reference =~ s/(;*\s*$)//; # remove semicolon and whitespace at the end (if present)
30    }
31    elsif ($line =~ /^HEADER\s+(.+)\s+(\d\d-\w\w\w-\d\d)\s+(\w{4})\s+\.$/) {
32      $header = $1;
33      $date = $2;
34      $pdb_id = $3;
35      $header =~ s/(;*\s*$)//;  # remove semicolon and whitespace at the end (if present)
36    }
37    elsif ($line =~ /^COMPND\s+\d?\s+(.+);*\s+\.$/) {
38      $compnd = $1;
39      $compnd =~ s/(;*\s*$)//;  # remove semicolon and whitespace at the end (if present)
40    }
41    elsif ($line =~ /^SOURCE\s+\d?\s+(.+);*\s+\.$/) {
42      $source = $1;
43      $source =~ s/(;*\s*$)//;  # remove semicolon and whitespace at the end (if present)
44    }
45    elsif ($line =~ /^AUTHOR\s+(.+);*\s+\.$/) {
46      $author = $1;
47      $author =~ s/(;*\s*$)//;  # remove semicolon and whitespace at the end (if present)
48      $mode++;
49    }
50  }
51  elsif ($mode==1) {
52    if ($line =~ /RESIDUE AA/) {
53      $mode++;
54    }
55  }
56  elsif ($mode==2) {
57    if ($line =~ /^.{11}(.)\s([A-Z!])..([A-Z\s])/io) {
58      if ($2 eq '!') {          # chain break encountered (-> start new protein sequence)
59        $seqnum++;
60        $sequences[$seqnum] = '';
61        $secstructs[$seqnum] = '';
62        $chains[$seqnum] = ' ';
63      }
64      else {                    # append protein sequence and secondary structure
65        $sequences[$seqnum] .= $2;
66        $secstructs[$seqnum] .= $3 eq ' ' ? '-' : $3;
67        if ($1 ne $chains[$seqnum]) {
68          $chains[$seqnum] = $1;
69        }
70      }
71    }
72    else {
73      die "Can't parse '$line'";
74    }
75  }
76}
77
78if (not defined $titleline) { die "Could not find title line"; }
79if (not defined $pdb_id) { die "Could not extract PDB_ID entry from HEADER"; }
80if (not defined $header) { die "Could not find HEADER entry"; }
81if (not defined $compnd) { die "Could not find COMPND entry"; }
82if (not defined $source) { die "Could not find SOURCE entry"; }
83if (not defined $date) { die "Could not extract DATE entry from HEADER"; }
84if (not defined $author) { die "Could not find AUTHOR entry"; }
85if (not defined $reference) { die "Could not find REFERENCE entry"; }
86
87if ($mode!=2) { die "Unknown parse error"; }
88
89for (my $i = 0; $i <= $seqnum; $i++) {
90  print "$titleline\n";
91  print "REFERENCE $reference\n";
92  if ($chains[$i] ne ' ') {
93    print "PDB_ID    $pdb_id\_$chains[$i]\n";
94  }
95  else {
96    print "PDB_ID    $pdb_id\n";
97  }
98  print "DATE      $date\n";
99  print "HEADER    $header\n";
100  print "COMPND    $compnd\n";
101  print "SOURCE    $source\n";
102  print "AUTHOR    $author\n";
103  print "SECSTRUCT $secstructs[$i]\n";
104  print "SEQUENCE\n$sequences[$i]\n";
105}
Note: See TracBrowser for help on using the repository browser.