~ubuntu-branches/ubuntu/trusty/bioperl/trusty

« back to all changes in this revision

Viewing changes to scripts/seq/unflatten_seq.PLS

  • Committer: Package Import Robot
  • Author(s): Charles Plessy
  • Date: 2013-09-22 13:39:48 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20130922133948-c6z62zegjyp7ztou
Tags: 1.6.922-1
* New upstream release.
* Replaces and Breaks grinder (<< 0.5.3-3~) because of overlaping contents.
  Closes: #722910
* Stop Replacing and Breaking bioperl ( << 1.6.9 ): not needed anymore. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!perl -w
2
 
use strict;
3
 
# Author Chris Mungall <cjm-at-bioperl.org>
4
 
 
5
 
=head1 NAME
6
 
 
7
 
unflatten_seq - unflatten a genbank or genbank-style feature file into
8
 
a nested SeqFeature hierarchy
9
 
 
10
 
=head1 SYNOPSIS
11
 
 
12
 
  unflatten_seq.PLS -e 3 -gff ~/cvs/bioperl-live/t/data/AE003644_Adh-genomic.gb
13
 
 
14
 
  unflatten_seq.PLS --detail ~/cvs/bioperl-live/t/data/AE003644_Adh-genomic.gb
15
 
 
16
 
  unflatten_seq.PLS -i foo.embl --from embl --to chadoxml -o out.chado.xml
17
 
 
18
 
  unflatten_seq.PLS --notypemap --detail --to asciitree -ethresh 2 AE003644_Adh-genomic.gb
19
 
 
20
 
=head1 DESCRIPTION 
21
 
 
22
 
This script will B<unflatten> a genbank or genbank-style file of
23
 
SeqFeatures into a nested hierarchy.
24
 
 
25
 
See L<Bio::SeqFeature::Tools::Unflattener>
26
 
 
27
 
In a GenBank/EMBL representation, features are 'flat' - for example,
28
 
there is no link between an mRNA and a CDS, other than implicit links
29
 
(eg via tags or via splice site coordinates) which may be hard to code
30
 
for.
31
 
 
32
 
This is most easily illustrated with the default output format,
33
 
B<asciitree>
34
 
 
35
 
An unflattened genbank feature set may look like this (AB077698)
36
 
 
37
 
  Seq: AB077698
38
 
    databank_entry                                   1..2701[+]
39
 
    gene                                             
40
 
      mRNA                                           
41
 
        CDS hCHCR-G                                  80..1144[+]
42
 
        exon                                         80..1144[+]
43
 
      five_prime_UTR                                 1..79[+]
44
 
      located_sequence_feature                       137..196[+]
45
 
      located_sequence_feature                       239..292[+]
46
 
      located_sequence_feature                       617..676[+]
47
 
      located_sequence_feature                       725..778[+]
48
 
      three_prime_UTR                                1145..2659[+]
49
 
      polyA_site                                     1606..1606[+]
50
 
      polyA_site                                     2660..2660[+]
51
 
 
52
 
Or like this (portion of AE003734)
53
 
 
54
 
 
55
 
  gene                                             
56
 
    mRNA CG3320-RA                                 
57
 
      CDS CG3320-PA                                53126..54971[-]
58
 
      exon                                         52204..53323[-]
59
 
      exon                                         53404..53631[-]
60
 
      exon                                         53688..53735[-]
61
 
      exon                                         53798..53918[-]
62
 
      exon                                         54949..55287[-]
63
 
    mRNA CG3320-RB                                 
64
 
      CDS CG3320-PB                                53383..54971[-]
65
 
      exon                                         52204..53631[-]
66
 
      exon                                         53688..53735[-]
67
 
      exon                                         53798..53918[-]
68
 
      exon                                         54949..55287[-]
69
 
 
70
 
The unflattening will also 'normalize' the containment hierarchy (in
71
 
the sense of standardising it - e.g. making sure there is always a
72
 
transcript record, even if genbank just specifies CDS and gene)
73
 
 
74
 
By default, the GenBank types will be mapped to SO types
75
 
 
76
 
See L<Bio::SeqFeature::Tools::TypeMapper>
77
 
 
78
 
=head1 COMMAND LINE ARGUMENTS
79
 
 
80
 
=over
81
 
 
82
 
=item -i|input FILE
83
 
 
84
 
input file (can also be specified as last argument)
85
 
 
86
 
=item -from FORMAT
87
 
 
88
 
input format (defaults to genbank)
89
 
 
90
 
probably doesnt make so much sense to use this for non-flat formats;
91
 
ie other than embl/genbank
92
 
 
93
 
=item -to FORMAT
94
 
 
95
 
output format (defaults to asciitree)
96
 
 
97
 
should really be a format that is nested SeqFeature aware; I think
98
 
this is only asciitree, chadoxml and gff3
99
 
 
100
 
=item -gff
101
 
 
102
 
with export to GFF3 format (pre-3 GFFs make no sense with unflattened
103
 
sequences, as they have no set way of representing feature graphs)
104
 
 
105
 
=item -o|output FILE
106
 
 
107
 
outfile defaults to STDOUT
108
 
 
109
 
=item -detail
110
 
 
111
 
show extra detail on features (asciitree mode only)
112
 
 
113
 
=item -e|ethresh INT
114
 
 
115
 
sets the error threshold on unflattening
116
 
 
117
 
by default this script will throw a wobbly if it encounters weird
118
 
stuff in the genbank file - raise the error threshold to signal these
119
 
to be ignored (and reported on STDERR)
120
 
 
121
 
=item -nomagic
122
 
 
123
 
suppress use_magic in unflattening (see
124
 
L<Bio::SeqFeature::Tools::Unflattener>
125
 
 
126
 
=item -notypemap
127
 
 
128
 
suppress type mapping (see
129
 
L<Bio::SeqFeature::Tools::TypeMapper>
130
 
 
131
 
 
132
 
=back
133
 
 
134
 
=head1 TODO
135
 
 
136
 
L<Bio::SeqFeature::Tools::Unflattener> allows fine-grained control
137
 
over the unflattening process - need to add more options to allow this
138
 
control at the command line
139
 
 
140
 
 
141
 
=head1 FEEDBACK
142
 
 
143
 
=head2 Mailing Lists
144
 
 
145
 
User feedback is an integral part of the evolution of this and other
146
 
Bioperl modules. Send your comments and suggestions preferably to
147
 
the Bioperl mailing list.  Your participation is much appreciated.
148
 
 
149
 
  bioperl-l@bioperl.org                  - General discussion
150
 
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists
151
 
 
152
 
=head2 Reporting Bugs
153
 
 
154
 
Report bugs to the Bioperl bug tracking system to help us keep track
155
 
of the bugs and their resolution. Bug reports can be submitted via
156
 
email or the web:
157
 
 
158
 
  https://redmine.open-bio.org/projects/bioperl/
159
 
 
160
 
=head1 AUTHOR
161
 
 
162
 
 Chris Mungall E<lt>cjm-at-bioperl.orgE<gt>
163
 
 
164
 
=cut
165
 
 
166
 
use Bio::SeqIO;
167
 
use Bio::SeqFeature::Tools::Unflattener;
168
 
use Bio::SeqFeature::Tools::TypeMapper;
169
 
use Bio::SeqFeature::Tools::IDHandler;
170
 
use Bio::Tools::GFF;
171
 
 
172
 
use Getopt::Long;
173
 
 
174
 
my ($input,$from,$to,$output,$verbosity,$ethresh,$nomagic,$group_tag,$detail,
175
 
    $notypemap);
176
 
$from = 'genbank';
177
 
$to = 'asciitree';
178
 
$ethresh = 3;
179
 
my $gff;
180
 
my @remove_types = ();
181
 
 
182
 
GetOptions(
183
 
           'i|input:s' => \$input,
184
 
           'from:s'  => \$from,
185
 
           'to:s'  => \$to,
186
 
           'o|output:s'=> \$output,
187
 
           "verbosity|v=s"=>\$verbosity,
188
 
           "ethresh|e=s"=>\$ethresh,
189
 
           "remove_type=s@"=>\@remove_types,
190
 
           "nomagic"=>\$nomagic,
191
 
           "notypemap"=>\$notypemap,
192
 
           "group_tag"=>\$group_tag,
193
 
           "detail"=>\$detail,
194
 
           "gff"=>\$gff,
195
 
           "h|help"=>sub {
196
 
               system("perldoc $0");
197
 
               exit 0;
198
 
           },
199
 
          );
200
 
                       
201
 
                       
202
 
if ($to =~ /^gff/i) {
203
 
    $gff = 1;
204
 
}
205
 
 
206
 
$input = $input || shift if @ARGV;
207
 
 
208
 
my $in = new Bio::SeqIO(-file => $input,
209
 
                        -format => $from);
210
 
my $out;
211
 
my @out_opt = $output ? (-file => ">$output") : ();
212
 
unless ($gff) {
213
 
    $out = new Bio::SeqIO(-format=>$to, @out_opt);
214
 
    $out->show_detail($detail) if $out->can("show_detail") && $detail;
215
 
}
216
 
 
217
 
my $unflattener = Bio::SeqFeature::Tools::Unflattener->new;
218
 
$unflattener->verbose($verbosity);
219
 
$unflattener->error_threshold($ethresh);
220
 
my $tm = Bio::SeqFeature::Tools::TypeMapper->new;
221
 
my $idhandler = Bio::SeqFeature::Tools::IDHandler->new;
222
 
 
223
 
while( my $seq = $in->next_seq ) {    
224
 
    $unflattener->remove_types(-seq=>$seq,
225
 
                               -types=>\@remove_types)
226
 
      if @remove_types;
227
 
 
228
 
    $unflattener->unflatten_seq(-seq=>$seq,
229
 
                                -use_magic=>!$nomagic,
230
 
                                -group_tag=>$group_tag,
231
 
                               );
232
 
    $unflattener->report_problems(\*STDERR);
233
 
    $tm->map_types_to_SO(-seq=>$seq) unless $notypemap;
234
 
 
235
 
    my @seq_args = ($seq);
236
 
    if ($to eq 'chadoxml') {
237
 
        @seq_args = (-seq=>$seq, -nounflatten=>1)
238
 
    }
239
 
    if ($gff) {
240
 
        my $gffio = Bio::Tools::GFF->new(@out_opt, -noparse=>1, -gff_version => 3);
241
 
        $idhandler->set_ParentIDs_from_hierarchy($seq);
242
 
        foreach my $feature ($seq->get_all_SeqFeatures) {
243
 
            $gffio->write_feature($feature);
244
 
        }
245
 
        $gffio->close();
246
 
    }
247
 
    else {
248
 
        $out->write_seq(@seq_args);
249
 
    }
250
 
 
251
 
}
252
 
 
253
 
__END__