script/tag-loc-ids.pl untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod n/a totaltotal 0.0% 0 / 91 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 # PODNAME: tag-loc-ids.pl
3 # ABSTRACT: Compute seq id organelle tags based on sequence identity
4 # CONTRIBUTOR: Mick VAN VLIERBERGHE <mvanvlierberghe@doct.uliege.be>
5  
6 use Modern::Perl '2011';
7 use autodie;
8  
9 use Path::Class qw(file);
10 use Smart::Comments;
11 use Getopt::Euclid qw(:vars);
12  
13 use Bio::MUST::Core;
14 use Bio::MUST::Core::Utils 'change_suffix';
15 use aliased 'Bio::MUST::Core::Ali';
16 use aliased 'Bio::MUST::Core::SeqId';
17 use aliased 'Bio::MUST::Core::IdList';
18 use aliased 'Bio::MUST::Core::IdMapper';
19 use aliased 'Bio::FastParsers::Blast::Table';
20  
21  
22 REPORT:
23 for my $infile (@ARGV_infiles) {
24  
25 my $fasta = $infile;
26 $fasta =~ s/$_//xms for @ARGV_in_strip;
27 $fasta = change_suffix($fasta, $ARGV_fasta_suffix);
28 my $ali = Ali->load($fasta);
29  
30 my %new_id_for;
31 my $org = join "_", (split "_", $infile)[0,1];
32  
33 my $report_file = file($infile);
34 my $report = Table->new( file => $report_file );
35  
36 HIT:
37 # loop through first hits for each query
38 while (my $hit = $report->next_query) {
39  
40 # consider only hits over percent_id threshold
41 next HIT if $hit->percent_identity < $ARGV_percent_id;
42  
43 # strict check of length unless percent_id filter only
44 unless ($ARGV_pid_only) {
45 next HIT
46 unless ( $hit->query_end - $hit->query_start )
47 == ( $hit->hit_end - $hit->hit_start )
48 ;
49 }
50  
51 my $seq_id = SeqId->new( full_id => $hit->hit_id );
52 my $query_id = $hit->query_id;
53 $query_id =~ s/_/ /xms;
54  
55 ### hitid: $hit->hit_id
56 ### fullid: $seq_id->full_id
57 ### tag: $seq_id->tag
58 my ($tag) = $hit->hit_id =~ m/([a-z]{2,3})\#/xms;
59 $new_id_for{$query_id}
60 = ($seq_id->tag ? $seq_id->tag : $tag) . '#' . $query_id;
61 }
62  
63 my @curr_ids = keys %new_id_for;
64 my @new_ids = map { $new_id_for{$_} } @curr_ids;
65  
66 my $idfile = change_suffix( $report_file, $ARGV_pruning
67 ? "$ARGV_loc.idl" : "$ARGV_loc.idm" );
68 if ($ARGV_pruning) {
69 ### Writing idl file...
70 my $idl = IdList->new(ids => \@curr_ids);
71 $idl->store($idfile);
72 next REPORT;
73 ### Done!
74 }
75 else {
76 ### Writing idm file...
77 my $idm = IdMapper->new(
78 long_ids => \@new_ids,
79 abbr_ids => \@curr_ids
80 );
81 $idm->store($idfile);
82 next REPORT;
83 ### Done!
84 }
85 }
86  
87 __END__