1 | #!/usr/bin/env perl |
---|
2 | # |
---|
3 | # bioperl_convert.pl v. 0.2 |
---|
4 | # 28.2.2008 |
---|
5 | # Heikki Lehvaslaiho, heikki a bioperl.org |
---|
6 | # |
---|
7 | # Run this in the same directory with the test files |
---|
8 | # and use grep and diff to analyse differences between |
---|
9 | # original and processed files |
---|
10 | # |
---|
11 | # e.g. |
---|
12 | # > bioperl_convert.pl aj224122 |
---|
13 | # # will work on embl, genbank and swissprot files.. |
---|
14 | # > diff aj224122.swiss aj224122-bioperl.swiss |
---|
15 | # > bioperl_convert.pl aj224122-bioperl |
---|
16 | # > diff aj224122-bioperl.swiss aj224122-bioperl-bioperl.swiss |
---|
17 | # |
---|
18 | |
---|
19 | use strict; |
---|
20 | use warnings; |
---|
21 | use Data::Dumper; |
---|
22 | |
---|
23 | sub conv ($$$); |
---|
24 | |
---|
25 | my $base = shift; |
---|
26 | die "Usage: convert.pl basename\n" unless $base; |
---|
27 | |
---|
28 | my @formats = qw( fasta embl genbank swiss); |
---|
29 | |
---|
30 | for my $f (@formats) { |
---|
31 | |
---|
32 | my $ext = $f; |
---|
33 | $ext = 'fa' if $f eq 'fasta'; |
---|
34 | $ext = 'gb' if $f eq 'genbank'; |
---|
35 | |
---|
36 | |
---|
37 | #`seqconvert.pl --from $f --to $f < $base.$ext > $base-bioperl.$ext`; |
---|
38 | conv($base, $ext, $f); |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | sub conv ($$$) { |
---|
43 | |
---|
44 | my ($base, $ext, $format) = @_; |
---|
45 | return unless -e "$base.$ext"; |
---|
46 | print STDERR "$format\n"; |
---|
47 | use Bio::SeqIO; |
---|
48 | my $in = Bio::SeqIO->new(-file => "$base.$ext", |
---|
49 | -format => $format); |
---|
50 | |
---|
51 | my $out = Bio::SeqIO->new(-file => ">$base-bioperl.$ext", |
---|
52 | -format => $format); |
---|
53 | my $seq = $in->next_seq(); |
---|
54 | |
---|
55 | # debugging print statements here |
---|
56 | # print Dumper $seq if $format eq 'embl'; |
---|
57 | print "----\n"; |
---|
58 | print ref($seq), "\n"; |
---|
59 | print $seq->display_id, "\n"; |
---|
60 | print $seq->version, "\n"; |
---|
61 | print $seq->accession_number, "\n"; |
---|
62 | print $seq->get_secondary_accessions , "\n" if $seq->isa('Bio::RichSeqI'); |
---|
63 | |
---|
64 | print "--------------------------------\n"; |
---|
65 | $out->write_seq($seq); |
---|
66 | } |
---|
67 | |
---|