bin/bp_biofetch_genbank_proxy: move to Bio-DB-NCBIHelper
[bioperl-live.git] / bin / bp_aacomp
blob2bb816d1fa750a49cff9febf6498690ea518f628
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Carp;
6 use Bio::SeqIO;
7 use Getopt::Long;
8 use Bio::SeqUtils;
9 use Bio::Tools::IUPAC;
11 my $table = new Bio::SeqUtils;
12 my @BASES = $table->valid_aa(0);
13 my %all = $table->valid_aa(2);
14 my ($file,$format,$help) = ( undef, 'fasta');
15 GetOptions(
16 'i|in:s' => \$file,
17 'f|format:s' => \$format,
18 'h|help|?' => \$help,
21 my $USAGE = "usage: aacomp [-f format] filename\n\tdefault format is fasta\n";
22 $file = shift unless $file;
24 die $USAGE if $help;
26 my $seqin;
27 if( defined $file ) {
28 print "Could not open file [$file]\n$USAGE" and exit unless -e $file;
29 $seqin = new Bio::SeqIO(-format => $format,
30 -file => $file);
31 } else {
32 $seqin = new Bio::SeqIO(-format => $format,
33 -fh => \*STDIN);
36 my %composition;
37 my $total;
38 foreach my $base ( @BASES ) {
39 $composition{$base} = 0;
41 while ( my $seq = $seqin->next_seq ) {
42 if( $seq->alphabet ne 'protein' ) {
43 confess("Must only provide amino acid sequences to aacomp...skipping this seq");
44 next;
46 foreach my $base ( split(//,$seq->seq()) ) {
47 $composition{uc $base}++;
48 $total++;
52 printf("%d aa\n",$total);
53 printf("%5s %4s\n", 'aa', '#' );
54 my $ct = 0;
55 foreach my $base ( @BASES ) {
56 printf(" %s %s %3d\n", $base, $all{$base}, $composition{$base} );
57 $ct += $composition{$base};
59 printf( "%6s %s\n", '','-'x5);
60 printf( "%6s %3d\n", '',$ct);
63 __END__
66 =head1 NAME
68 bp_aacomp - amino acid composition of protein sequences
70 =head1 SYNOPSIS
72 bp_aacomp [-f/--format FORMAT] [-h/--help] filename
74 bp_aacomp [-f/--format FORMAT] < filename
76 bp_aacomp [-f/--format FORMAT] -i filename
78 =head1 DESCRIPTION
80 This scripts prints out the count of amino acids over all protein
81 sequences from the input file.
83 =head1 OPTIONS
85 The default sequence format is fasta.
87 The sequence input can be provided using any of the three methods:
89 =over 3
91 =item unnamed argument
93 bp_aacomp filename
95 =item named argument
97 bp_aacomp -i filename
99 =item standard input
101 bp_aacomp < filename
103 =back
105 =head1 FEEDBACK
107 =head2 Mailing Lists
109 User feedback is an integral part of the evolution of this and other
110 Bioperl modules. Send your comments and suggestions preferably to
111 the Bioperl mailing list. Your participation is much appreciated.
113 bioperl-l@bioperl.org - General discussion
114 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
116 =head2 Reporting Bugs
118 Report bugs to the Bioperl bug tracking system to help us keep track
119 of the bugs and their resolution. Bug reports can be submitted via the
120 web:
122 https://github.com/bioperl/bioperl-live/issues
124 =head1 AUTHOR - Jason Stajich
126 Email jason@bioperl.org
128 =head1 HISTORY
130 Based on aacomp.c from an old version of EMBOSS
132 =cut