6 # Author Jason Stajich <jason@bioperl.org>
10 bp_extract_feature_seq - extract the corresponding sequence for a specified feature type
14 bp_extract_feature_seq [--format FORMAT] [--feature CDS] [--output FILE] [--input] FILE
18 This script will extract the sequence for all the features you specify.
24 =item B<-i>, B<--input>
26 Specifies the sequence file to be read.
30 Format of the file specified by B<--input>. If not given, it will try to guess the
31 correct format from the file extension.
35 Feature to be extracted. By default, it extracts the CDS feature.
37 =item B<-o>, B<--output>
39 File where the extracted features will be saved. If not specified, STDOUT is used.
47 User feedback is an integral part of the evolution of this and other
48 Bioperl modules. Send your comments and suggestions preferably to
49 the Bioperl mailing list. Your participation is much appreciated.
51 L<bioperl-l@bioperl.org> - General discussion
52 L<http://bioperl.org/wiki/Mailing_lists> - About the mailing lists
56 Report bugs to the Bioperl bug tracking system to help us keep track
57 of the bugs and their resolution. Bug reports can be submitted via
60 L<https://github.com/bioperl/bioperl-live/issues>
64 Jason Stajich <jason-at-bioperl-dot-org>
68 my ($input,$format,$featuretype,$output);
71 'i|input:s' => \
$input,
72 'format:s' => \
$format,
73 'feature:s' => \
$featuretype,
74 'o|output:s'=> \
$output);
76 $input || shift if @ARGV;
78 my $in = new Bio
::SeqIO
(-file
=> $input,
82 $out = new Bio
::SeqIO
(-file
=> ">$output", -format
=> 'fasta');
84 $out = new Bio
::SeqIO
(-format
=> 'fasta'); # use STDOUT for output
88 while( my $seq = $in->next_seq ) {
89 foreach my $f ( grep { $_->primary_tag =~ /$featuretype/i }
90 $seq->get_SeqFeatures ) {
91 my $s = $f->spliced_seq;
92 if( $featuretype =~ /gene|CDS/ ) {
93 $s->display_id($f->has_tag('gene') ?
join(',',sort $f->each_tag_value('gene')) :
94 $f->has_tag('label') ?
join(',',$f->each_tag_value('label')):
97 $s->display_id(sprintf("%s_%s_%d",