| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Rangeops::Command::create; |
|
2
|
9
|
|
|
9
|
|
5604
|
use strict; |
|
|
9
|
|
|
|
|
21
|
|
|
|
9
|
|
|
|
|
239
|
|
|
3
|
9
|
|
|
9
|
|
45
|
use warnings; |
|
|
9
|
|
|
|
|
21
|
|
|
|
9
|
|
|
|
|
196
|
|
|
4
|
9
|
|
|
9
|
|
42
|
use autodie; |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
48
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
43207
|
use App::Rangeops -command; |
|
|
9
|
|
|
|
|
22
|
|
|
|
9
|
|
|
|
|
80
|
|
|
7
|
9
|
|
|
9
|
|
2722
|
use App::Rangeops::Common; |
|
|
9
|
|
|
|
|
24
|
|
|
|
9
|
|
|
|
|
209
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
9
|
|
|
9
|
|
42
|
use constant abstract => 'create blocked fasta files from range links'; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
5543
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub opt_spec { |
|
12
|
|
|
|
|
|
|
return ( |
|
13
|
1
|
|
|
1
|
1
|
16
|
[ "outfile|o=s", "Output filename. [stdout] for screen." ], |
|
14
|
|
|
|
|
|
|
[ "genome|g=s", "Reference genome file.", { required => 1 }, ], |
|
15
|
|
|
|
|
|
|
[ "name|n=s", "Default name for ranges.", ], |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub usage_desc { |
|
20
|
1
|
|
|
1
|
1
|
23939
|
return "rangeops create [options] "; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub description { |
|
24
|
1
|
|
|
1
|
1
|
976
|
my $desc; |
|
25
|
1
|
|
|
|
|
4
|
$desc .= ucfirst(abstract) . ".\n"; |
|
26
|
1
|
|
|
|
|
3
|
return $desc; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub validate_args { |
|
30
|
0
|
|
|
0
|
1
|
|
my ( $self, $opt, $args ) = @_; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if ( !@{$args} ) { |
|
|
0
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$self->usage_error("This command need one or more input files."); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
0
|
|
|
|
|
|
for ( @{$args} ) { |
|
|
0
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
next if lc $_ eq "stdin"; |
|
37
|
0
|
0
|
|
|
|
|
if ( !Path::Tiny::path($_)->is_file ) { |
|
38
|
0
|
|
|
|
|
|
$self->usage_error("The input file [$_] doesn't exist."); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if ( !exists $opt->{outfile} ) { |
|
43
|
|
|
|
|
|
|
$opt->{outfile} |
|
44
|
0
|
|
|
|
|
|
= Path::Tiny::path( $args->[0] )->absolute . ".fas"; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub execute { |
|
49
|
0
|
|
|
0
|
1
|
|
my ( $self, $opt, $args ) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#----------------------------# |
|
52
|
|
|
|
|
|
|
# Output |
|
53
|
|
|
|
|
|
|
#----------------------------# |
|
54
|
0
|
|
|
|
|
|
my $out_fh; |
|
55
|
0
|
0
|
|
|
|
|
if ( lc( $opt->{outfile} ) eq "stdout" ) { |
|
56
|
0
|
|
|
|
|
|
$out_fh = \*STDOUT; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
else { |
|
59
|
0
|
|
|
|
|
|
open $out_fh, ">", $opt->{outfile}; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#----------------------------# |
|
63
|
|
|
|
|
|
|
# Loading |
|
64
|
|
|
|
|
|
|
#----------------------------# |
|
65
|
0
|
|
|
|
|
|
my $info_of = {}; |
|
66
|
0
|
|
|
|
|
|
for my $file ( @{$args} ) { |
|
|
0
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
for my $line ( App::RL::Common::read_lines($file) ) { |
|
68
|
0
|
|
|
|
|
|
$info_of = App::Rangeops::Common::build_info( [$line], $info_of ); |
|
69
|
0
|
|
|
|
|
|
my @parts; |
|
70
|
0
|
|
|
|
|
|
for my $part ( split /\t/, $line ) { |
|
71
|
0
|
0
|
|
|
|
|
next unless exists $info_of->{$part}; |
|
72
|
0
|
|
|
|
|
|
push @parts, $part; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
0
|
0
|
|
|
|
|
next unless @parts >= 2; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
for my $range (@parts) { |
|
77
|
0
|
|
|
|
|
|
my $info = $info_of->{$range}; |
|
78
|
|
|
|
|
|
|
my $location = sprintf "%s:%d-%d", $info->{chr}, $info->{start}, |
|
79
|
0
|
|
|
|
|
|
$info->{end}; |
|
80
|
|
|
|
|
|
|
my $seq = App::Rangeops::Common::get_seq_faidx( $opt->{genome}, |
|
81
|
0
|
|
|
|
|
|
$location ); |
|
82
|
0
|
0
|
0
|
|
|
|
if ( defined $info->{strand} and $info->{strand} ne "+" ) { |
|
83
|
0
|
|
|
|
|
|
$seq = App::Fasops::Common::revcom($seq); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
0
|
|
|
|
|
if ( $opt->{name} ) { |
|
86
|
0
|
|
|
|
|
|
$info->{name} = $opt->{name}; |
|
87
|
0
|
|
|
|
|
|
$range = App::RL::Common::encode_header($info); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
0
|
|
|
|
|
|
print {$out_fh} ">$range\n"; |
|
|
0
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
print {$out_fh} "$seq\n"; |
|
|
0
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
|
92
|
0
|
|
|
|
|
|
print {$out_fh} "\n"; |
|
|
0
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
close $out_fh; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |