blib/script/gffcds2seq.pl untested

filter: Statementstmt 0.0% 0 / 75 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod n/a totaltotal 0.0% 0 / 102 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 use warnings;
4 use strict;
5 use 5.010;
6  
7 use Pod::Usage;
8 use Getopt::Long qw(:config auto_help);
9 use Bio::Gonzales::Seq::IO qw(faslurp faspew);
10  
11 use Bio::Gonzales::Feat::IO::GFF3;
12 use List::Util qw/reduce/;
13 use List::MoreUtils qw/any all/;
14 use Bio::Perl qw/translate_as_string/;
15  
16 my @child_feat_type;
17 my $gene_model_type = 'mRNA';
18  
19 GetOptions( 'parent_feat=s' => \$gene_model_type, 'child_feat=s' => \@child_feat_type ) or pod2usage(2);
20 @child_feat_type = qw/CDS/ unless(@child_feat_type);
21 say STDERR "parent model feat: $gene_model_type";
22 say STDERR "child model feat: " . join( ", ", @child_feat_type );
23 my ( $gff_f, @scf_f ) = @ARGV;
24 for my $f ( $gff_f, @scf_f ) {
25 die "$f does not exist" unless ( -f $f );
26 }
27  
28 my $gffin = Bio::Gonzales::Feat::IO::GFF3->new(
29 file => $gff_f,
30 mode => '<',
31 );
32  
33 my %cds_feats;
34  
35 my %child_feat_type = map { $_ => 1 } @child_feat_type;
36 while ( my $feat = $gffin->next_feat ) {
37 if ( $child_feat_type{ $feat->type } ) {
38 #Bio::Gonzales::Seq::Feat
39 my $p = $feat->parent_id;
40  
41 $cds_feats{$p} //= [];
42 push @{ $cds_feats{$p} }, $feat;
43 }
44 }
45 $gffin->close;
46  
47 my %seqs;
48 for my $sf (@scf_f) {
49 my $seqs = faslurp($sf);
50 for my $s (@$seqs) {
51 die if ( $seqs{ $s->id } );
52 $seqs{ $s->id } = $s;
53 }
54 }
55  
56 my $out_fh = \*STDOUT;
57 for my $feat_set ( values %cds_feats ) {
58 my @ord = sort { $a->start <=> $b->start } @$feat_set;
59  
60 print STDERR ".";
61 print STDERR ";" x scalar grep { not exists( $seqs{ $_->seq_id } ) } @ord;
62  
63 @ord = grep { exists( $seqs{ $_->seq_id } ) } @ord;
64 next unless ( @ord > 0 );
65 # Bio::Gonzales::Seq
66 my $seq_string = reduce {
67 $a .= $seqs{ $b->seq_id }->subseq_as_string( [ $b->start, $b->end ] );
68 }
69 ( "", @ord );
70  
71 my $seq = Bio::Gonzales::Seq->new( id => $ord[0]->parent_id, seq => $seq_string );
72 $seq->revcom if ( $ord[0]->strand < 0 );
73  
74 faspew( $out_fh, $seq );
75 }
76 $out_fh->close;
77 __END__
78  
79 =head1 NAME
80  
81  
82  
83 =head1 SYNOPSIS
84  
85 #wenn export, dann hier im qw()
86  
87 =head1 DESCRIPTION
88  
89 =head1 OPTIONS
90  
91 =head1 SUBROUTINES
92 =head1 METHODS
93  
94 =head1 SEE ALSO
95  
96 =head1 AUTHOR
97  
98 jw bargsten, C<< <jwb at cpan dot org> >>
99  
100 =cut