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