| 1 | package App::Dazz::Command::overlap2; | ||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use autodie; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use App::Dazz -command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use App::Dazz::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use constant abstract => "detect overlaps between two (large) files by daligner"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | return ( | ||||||||||||||||||||||||||||
| 13 | 6 | [ "dir|d=s", "working directory", { default => "." }, ], | |||||||||||||||||||||||||||
| 14 | [ "p1=s", "prefix of first file", { default => "anchor" }, ], | ||||||||||||||||||||||||||||
| 15 | [ "p2=s", "prefix of second file", { default => "long" }, ], | ||||||||||||||||||||||||||||
| 16 | [ "pd=s", "prefix of result files", ], | ||||||||||||||||||||||||||||
| 17 | [ "block|b=i", "block size in Mbp", { default => 20 }, ], | ||||||||||||||||||||||||||||
| 18 | [ "len|l=i", "minimal length of overlaps", { default => 1000 }, ], | ||||||||||||||||||||||||||||
| 19 | [ "idt|i=f", "minimal identity of overlaps", { default => 0.8 }, ], | ||||||||||||||||||||||||||||
| 20 | [ "all", "all overlaps instead of proper overlaps", ], | ||||||||||||||||||||||||||||
| 21 | [ "parallel|p=i", "number of threads", { default => 8 }, ], | ||||||||||||||||||||||||||||
| 22 | [ "verbose|v", "verbose mode", ], | ||||||||||||||||||||||||||||
| 23 | { show_defaults => 1, } | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 6 | ▶ | sub usage_desc { | ||||||||||||||||||||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 6 | return "dazz overlap2 [options] <infile1> <infile2>"; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | sub description { | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 1 | my $desc; | |||||||||||||||||||||||||||
| 33 | 1 | $desc .= ucfirst(abstract) . ".\n"; | |||||||||||||||||||||||||||
| 34 | 1 | $desc .= "\tAll intermediate files (.fasta, .replace.tsv, .db, .las, .show.txt, .ovlp.tsv)"; | |||||||||||||||||||||||||||
| 35 | 1 | $desc .= " are kept in the working directory.\n"; | |||||||||||||||||||||||||||
| 36 | 1 | return $desc; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 5 | ▶ | sub validate_args { | ||||||||||||||||||||||||||
|
Subroutine
validate_args: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 5 | my ( $self, $opt, $args ) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 5 | ▶ | if ( @{$args} != 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 1 | my $message = "This command need two input files.\n\tIt found"; | |||||||||||||||||||||||||||
| 44 | 1 | $message .= sprintf " [%s]", $_ for @{$args}; | |||||||||||||||||||||||||||
| 45 | 1 | $message .= ".\n"; | |||||||||||||||||||||||||||
| 46 | 1 | $self->usage_error($message); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 4 | for ( @{$args} ) { | |||||||||||||||||||||||||||
| 49 | 8 | ▶ | if ( !Path::Tiny::path($_)->is_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 1 | $self->usage_error("The input file [$_] doesn't exist."); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | $opt->{dir} = Path::Tiny::path( $opt->{dir} )->absolute()->stringify; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 3 | ▶ | if ( $opt->{p1} eq $opt->{p2} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | $self->usage_error("Two prefixes shouldn't be same."); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 3 | ▶ | if ( !exists $opt->{pd} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 3 | $opt->{pd} = $opt->{p1} . ucfirst( $opt->{p2} ); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=18 SCAR=46.1
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 3 | my ( $self, $opt, $args ) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | #@type Path::Tiny | ||||||||||||||||||||||||||||
| 69 | 3 | my $out_dir = Path::Tiny::path( $opt->{dir} ); | |||||||||||||||||||||||||||
| 70 | 3 | $out_dir->mkpath(); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # absolute paths before we chdir to $out_dir | ||||||||||||||||||||||||||||
| 73 | 3 | my $file1 = Path::Tiny::path( $args->[0] )->absolute->stringify; | |||||||||||||||||||||||||||
| 74 | 3 | my $file2 = Path::Tiny::path( $args->[1] )->absolute->stringify; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # enter out dir | ||||||||||||||||||||||||||||
| 77 | 3 | chdir $out_dir; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | { # Preprocess first file for dazzler | ||||||||||||||||||||||||||||
| 80 | 3 | my $cmd; | |||||||||||||||||||||||||||
| 81 | 3 | $cmd .= "faops filter -l 0 $file1 stdout"; | |||||||||||||||||||||||||||
| 82 | 3 | $cmd .= " | dazz dazzname --prefix $opt->{p1} stdin -o stdout"; | |||||||||||||||||||||||||||
| 83 | 3 | $cmd .= " > $opt->{p1}.fasta"; | |||||||||||||||||||||||||||
| 84 | 3 | App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 3 | ▶ | if ( !$out_dir->child("stdout.replace.tsv")->is_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | Carp::croak "Failed: create $opt->{p1}.replace.tsv\n"; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||
| 90 | 3 | $out_dir->child("stdout.replace.tsv")->move("$opt->{p1}.replace.tsv"); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 3 | chomp( my $first_sum = `faops n50 -H -N 0 -S $opt->{p1}.fasta` ); | |||||||||||||||||||||||||||
| 95 | 3 | chomp( my $first_count = `faops n50 -H -N 0 -C $opt->{p1}.fasta` ); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | { # Preprocess second file for dazzler | ||||||||||||||||||||||||||||
| 98 | 3 | my $second_start = $first_count + 1; | |||||||||||||||||||||||||||
| 99 | 3 | my $cmd; | |||||||||||||||||||||||||||
| 100 | 3 | $cmd .= "faops filter -l 0 -u -a $opt->{len} $file2 stdout"; | |||||||||||||||||||||||||||
| 101 | 3 | $cmd .= " | dazz dazzname --prefix $opt->{p2} --start $second_start stdin -o stdout"; | |||||||||||||||||||||||||||
| 102 | 3 | $cmd .= " > $opt->{p2}.fasta"; | |||||||||||||||||||||||||||
| 103 | 3 | App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | ▶ | if ( !$out_dir->child("stdout.replace.tsv")->is_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | Carp::croak "Failed: create $opt->{p2}.replace.tsv\n"; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||
| 109 | 3 | $out_dir->child("stdout.replace.tsv")->move("$opt->{p2}.replace.tsv"); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | { # Make the dazzler DB | ||||||||||||||||||||||||||||
| 114 | 3 | ▶ | if ( $out_dir->child( $opt->{pd} . ".db" )->is_file | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$out_dir->child($opt->{"pd"} . '.db')->is_file or $out_dir->child('.' . $opt->{"pd"} . '.bps')->is_file
MC/DC0%0/2
$out_dir->child($opt->{"pd"} . '.db')->is_file or $out_dir->child('.' . $opt->{"pd"} . '.bps')->is_file
$out_dir->child($opt->{"pd"} . '.db')->is_file
$out_dir->child('.' . $opt->{"pd"} . '.bps')->is_file
Truth table33%1/3
A or B
A= $out_dir->child($opt->{"pd"} . '.db')->is_fileB= $out_dir->child('.' . $opt->{"pd"} . '.bps')->is_file
| |||||||||||||||||||||||||||||
| 115 | or $out_dir->child( "." . $opt->{pd} . ".bps" )->is_file ) | ||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | 0 | App::Dazz::Common::exec_cmd( "DBrm $opt->{pd}", { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 3 | my $cmd; | |||||||||||||||||||||||||||
| 121 | 3 | $cmd .= "fasta2DB $opt->{pd} $opt->{p1}.fasta"; | |||||||||||||||||||||||||||
| 122 | 3 | $cmd .= " && fasta2DB $opt->{pd} $opt->{p2}.fasta"; | |||||||||||||||||||||||||||
| 123 | 3 | $cmd .= " && DBdust $opt->{pd}"; | |||||||||||||||||||||||||||
| 124 | 3 | $cmd .= " && DBsplit -s$opt->{block} $opt->{pd}"; | |||||||||||||||||||||||||||
| 125 | 3 | App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 3 | ▶ | if ( !$out_dir->child("$opt->{pd}.db")->is_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 3 | Carp::croak "Failed: fasta2DB\n"; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | { # Run daligner | ||||||||||||||||||||||||||||
| 133 | 3 | my $block_number; | |||||||||||||||||||||||||||
| 134 | 0 | for my $line ( $out_dir->child("$opt->{pd}.db")->lines ) { | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ( $line =~ /^blocks\s+=\s+(\d+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | $block_number = $1; | |||||||||||||||||||||||||||
| 137 | 0 | last; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | my $first_idx = int( $first_sum / 1_000_000 / $opt->{block} + 1 ); | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | print STDERR YAML::Syck::Dump { | ||||||||||||||||||||||||||||
| 144 | first_sum => $first_sum, | ||||||||||||||||||||||||||||
| 145 | first_count => $first_count, | ||||||||||||||||||||||||||||
| 146 | first_idx => $first_idx, | ||||||||||||||||||||||||||||
| 147 | block_number => $block_number, | ||||||||||||||||||||||||||||
| 148 | block_size => $opt->{block}, | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if $opt->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ( $out_dir->child( $opt->{pd} . ".las" )->is_file | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$out_dir->child($opt->{"pd"} . '.las')->is_file or $out_dir->child($opt->{"pd"} . '.1.las')->is_file
MC/DC0%0/2
$out_dir->child($opt->{"pd"} . '.las')->is_file or $out_dir->child($opt->{"pd"} . '.1.las')->is_file
$out_dir->child($opt->{"pd"} . '.las')->is_file
$out_dir->child($opt->{"pd"} . '.1.las')->is_file
Truth table0%0/3
A or B
A= $out_dir->child($opt->{"pd"} . '.las')->is_fileB= $out_dir->child($opt->{"pd"} . '.1.las')->is_file
| |||||||||||||||||||||||||||||
| 153 | or $out_dir->child( $opt->{pd} . ".1.las" )->is_file ) | ||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||
| 155 | 0 | App::Dazz::Common::exec_cmd( "rm $opt->{pd}*.las", { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # Don't use HPC.daligner as we want to avoid all-vs-all comparisions. | ||||||||||||||||||||||||||||
| 159 | # HPC.daligner tries to give every sequences the same change to match with others. | ||||||||||||||||||||||||||||
| 160 | 0 | for my $i ( 1 .. $first_idx ) { | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # Start from $i instead of $first_idx for conveniences of LAmerge | ||||||||||||||||||||||||||||
| 163 | 0 | for my $j ( $i .. $block_number ) { | |||||||||||||||||||||||||||
| 164 | 0 | my $cmd; | |||||||||||||||||||||||||||
| 165 | 0 | $cmd .= "daligner -M16 -T$opt->{parallel}"; | |||||||||||||||||||||||||||
| 166 | 0 | $cmd .= " -e$opt->{idt} -l$opt->{len} -s$opt->{len} -mdust"; | |||||||||||||||||||||||||||
| 167 | 0 | $cmd .= " $opt->{pd}.$i $opt->{pd}.$j"; | |||||||||||||||||||||||||||
| 168 | 0 | $cmd .= " && LAcheck -S $opt->{pd} $opt->{pd}.$i.$opt->{pd}.$j"; | |||||||||||||||||||||||||||
| 169 | 0 | $cmd .= " && LAcheck -S $opt->{pd} $opt->{pd}.$j.$opt->{pd}.$i"; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | for my $i ( 1 .. $first_idx ) { | |||||||||||||||||||||||||||
| 176 | 0 | my $cmd; | |||||||||||||||||||||||||||
| 177 | 0 | $cmd .= "LAmerge $opt->{pd}.$i"; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | for my $j ( 1 .. $block_number ) { | |||||||||||||||||||||||||||
| 180 | 0 | $cmd .= " $opt->{pd}.$i.$opt->{pd}.$j"; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | $cmd .= " && LAcheck -S $opt->{pd} $opt->{pd}.$i"; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | App::Dazz::Common::exec_cmd( "rm $opt->{pd}.*.$opt->{pd}.*.las", | ||||||||||||||||||||||||||||
| 189 | 0 | { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||
| 192 | 0 | my $cmd; | |||||||||||||||||||||||||||
| 193 | 0 | $cmd .= "LAcat $opt->{pd}.\@.las > $opt->{pd}.las"; | |||||||||||||||||||||||||||
| 194 | 0 | App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | App::Dazz::Common::exec_cmd( "rm $opt->{pd}.*.las", { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ( !$out_dir->child("$opt->{pd}.las")->is_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | Carp::croak "Failed: daligner\n"; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | { # outputs | ||||||||||||||||||||||||||||
| 205 | 0 | my $cmd = "LAshow -o $opt->{pd}.db $opt->{pd}.las > $opt->{pd}.show.txt"; | |||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ( $opt->{all} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | $cmd = "LAshow $opt->{pd}.db $opt->{pd}.las > $opt->{pd}.show.txt"; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | 0 | App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ( !$out_dir->child("$opt->{pd}.show.txt")->is_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 0 | Carp::croak "Failed: LAshow\n"; | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | $cmd = "cat $opt->{p1}.fasta $opt->{p2}.fasta "; | |||||||||||||||||||||||||||
| 216 | 0 | $cmd .= " | dazz show2ovlp stdin $opt->{pd}.show.txt"; | |||||||||||||||||||||||||||
| 217 | 0 | $cmd .= " -o $opt->{pd}.ovlp.tsv"; | |||||||||||||||||||||||||||
| 218 | 0 | App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 11 | 1; | |||||||||||||||||||||||||||