| 1 | package App::Egaz::Command::prepseq; | ||||||||||||||||||||||||||||
| 2 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use autodie; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use App::Egaz -command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use App::Egaz::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | sub abstract { | ||||||||||||||||||||||||||
|
Subroutine
abstract: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 2 | return 'preparing steps for lastz'; | |||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | return ( | ||||||||||||||||||||||||||||
| 15 | 3 | [ "outdir|o=s", "Output directory", ], | |||||||||||||||||||||||||||
| 16 | [ "min=i", "minimal length of sequences", ], | ||||||||||||||||||||||||||||
| 17 | [ "about=i", "split sequences to chunks about approximate size", ], | ||||||||||||||||||||||||||||
| 18 | [ "repeatmasker=s", "call `egaz repeatmasker` with these options", ], | ||||||||||||||||||||||||||||
| 19 | [ "gi", "remove GI numbers from fasta header", ], | ||||||||||||||||||||||||||||
| 20 | [ "verbose|v", "verbose mode", ], | ||||||||||||||||||||||||||||
| 21 | { show_defaults => 1, } | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | sub usage_desc { | ||||||||||||||||||||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 3 | return "egaz prepseq [options] <path/seqfile>"; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub description { | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 1 | my $desc; | |||||||||||||||||||||||||||
| 31 | 1 | $desc .= ucfirst(abstract) . ".\n"; | |||||||||||||||||||||||||||
| 32 | 1 | $desc .= <<'MARKDOWN'; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | * Call `faops filter -N -s to convert IUPAC codes to 'N' and simplify sequence names | ||||||||||||||||||||||||||||
| 35 | * for --gi, see [this link](https://ncbiinsights.ncbi.nlm.nih.gov/2016/07/15/ncbi-is-phasing-out-sequence-gis-heres-what-you-need-to-know/) | ||||||||||||||||||||||||||||
| 36 | * If <path/seqfile> is a file | ||||||||||||||||||||||||||||
| 37 | * call `faops split-name` to separate each sequences into `--outdir` | ||||||||||||||||||||||||||||
| 38 | * with --about, call `faops split-about` to split sequences to chunks about specified size | ||||||||||||||||||||||||||||
| 39 | * gzipped file is OK | ||||||||||||||||||||||||||||
| 40 | * If <path/> is a directory | ||||||||||||||||||||||||||||
| 41 | * --outdir will be omitted and set to <path/> | ||||||||||||||||||||||||||||
| 42 | * --min, --about will be omitted | ||||||||||||||||||||||||||||
| 43 | * only files with suffix of '.fa' will be processed | ||||||||||||||||||||||||||||
| 44 | * each files should contain only 1 sequences and names of file and sequence should be matched | ||||||||||||||||||||||||||||
| 45 | * Create chr.sizes via `faops size` | ||||||||||||||||||||||||||||
| 46 | * Create chr.2bit via `faToTwoBit` | ||||||||||||||||||||||||||||
| 47 | * `faops` and `faToTwoBit` should be in $PATH | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | MARKDOWN | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | return $desc; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub validate_args { | ||||||||||||||||||||||||||
|
Subroutine
validate_args: called CC=11 SCAR=34.1
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 2 | my ( $self, $opt, $args ) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | if ( @{$args} != 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 1 | my $message = "This command need one input file/directory.\n\tIt found"; | |||||||||||||||||||||||||||
| 59 | 1 | $message .= sprintf " [%s]", $_ for @{$args}; | |||||||||||||||||||||||||||
| 60 | 1 | $message .= ".\n"; | |||||||||||||||||||||||||||
| 61 | 1 | $self->usage_error($message); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 1 | for ( @{$args} ) { | |||||||||||||||||||||||||||
| 64 | 1 | ▶ | if ( !( Path::Tiny::path($_)->is_file or Path::Tiny::path($_)->is_dir ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
Path::Tiny::path($_)->is_file or Path::Tiny::path($_)->is_dir
MC/DC0%0/2
Path::Tiny::path($_)->is_file or Path::Tiny::path($_)->is_dir
Path::Tiny::path($_)->is_file
Path::Tiny::path($_)->is_dir
Truth table33%1/3
A or B
A= Path::Tiny::path($_)->is_fileB= Path::Tiny::path($_)->is_dir
| |||||||||||||||||||||||||||||
| 65 | 1 | $self->usage_error("The input file/directory [$_] doesn't exist."); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # set default --outdir | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ( Path::Tiny::path( $args->[0] )->is_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $opt->{outdir} = "." if ( !$opt->{outdir} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | printf STDERR "--outdir set to [%s]\n", $opt->{outdir} if $opt->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( Path::Tiny::path( $args->[0] )->is_dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | $opt->{outdir} = $args->[0]; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | print STDERR "--outdir set to [$args->[0]]\n" if $opt->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 0 | my ( $self, $opt, $args ) = @_; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | #@type Path::Tiny | ||||||||||||||||||||||||||||
| 84 | 0 | my $outdir = Path::Tiny::path( $opt->{outdir} ); | |||||||||||||||||||||||||||
| 85 | 0 | $outdir->mkpath(); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | #----------------------------# | ||||||||||||||||||||||||||||
| 88 | # split-name | ||||||||||||||||||||||||||||
| 89 | #----------------------------# | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( Path::Tiny::path( $args->[0] )->is_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | my $cmd; | |||||||||||||||||||||||||||
| 92 | 0 | $cmd .= " faops filter -N -s"; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | $cmd .= " -a $opt->{min}" if $opt->{min}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | $cmd .= " $args->[0] stdout"; | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( $opt->{gi} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | $cmd .= " |"; | |||||||||||||||||||||||||||
| 97 | 0 | $cmd .= q{ perl -p -e '/\>gi\|/ and s/gi\|\d+\|\w+\|//'}; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 0 | $cmd .= " |"; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ( $opt->{about} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | $cmd .= " faops split-about stdin $opt->{about} $outdir"; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | else { | ||||||||||||||||||||||||||||
| 104 | 0 | $cmd .= " faops split-name stdin $outdir"; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 0 | App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||
| 109 | # Store files in tempdir and then copy back | ||||||||||||||||||||||||||||
| 110 | 0 | my $tempdir = Path::Tiny::tempdir("prepseq_XXXXXXXX"); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my @paths = Path::Tiny::path( $args->[0] )->children(qr/\.fa$/); | |||||||||||||||||||||||||||
| 113 | 0 | for my Path::Tiny $path (@paths) { | |||||||||||||||||||||||||||
| 114 | 0 | my $basename = $path->basename(".fa"); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | my $cmd; | |||||||||||||||||||||||||||
| 117 | 0 | $cmd .= " faops filter -N -s"; | |||||||||||||||||||||||||||
| 118 | 0 | $cmd .= " $path stdout"; | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ( $opt->{gi} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | $cmd .= " |"; | |||||||||||||||||||||||||||
| 121 | 0 | $cmd .= q{ perl -p -e '/\>gi\|/ and s/gi\|\d+\|\w+\|//'}; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 0 | $cmd .= " > $tempdir/$basename.fa"; | |||||||||||||||||||||||||||
| 124 | 0 | App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 125 | 0 | $tempdir->child("$basename.fa")->copy( $args->[0], "$basename.fa" ); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | #----------------------------# | ||||||||||||||||||||||||||||
| 130 | # repeatmasker | ||||||||||||||||||||||||||||
| 131 | #----------------------------# | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ( $opt->{repeatmasker} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | my $cmd = "egaz repeatmasker $outdir/*.fa -o $outdir"; | |||||||||||||||||||||||||||
| 134 | 0 | $cmd .= " $opt->{repeatmasker}"; | |||||||||||||||||||||||||||
| 135 | 0 | App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | #----------------------------# | ||||||||||||||||||||||||||||
| 139 | # chr.sizes | ||||||||||||||||||||||||||||
| 140 | #----------------------------# | ||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||
| 142 | 0 | my $cmd = "faops size $outdir/*.fa > $outdir/chr.sizes"; | |||||||||||||||||||||||||||
| 143 | 0 | App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | #----------------------------# | ||||||||||||||||||||||||||||
| 147 | # chr.2bit | ||||||||||||||||||||||||||||
| 148 | #----------------------------# | ||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||
| 150 | 0 | my $cmd = "faToTwoBit $outdir/*.fa $outdir/chr.2bit"; | |||||||||||||||||||||||||||
| 151 | 0 | App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | #----------------------------# | ||||||||||||||||||||||||||||
| 155 | # chr.fasta.fai | ||||||||||||||||||||||||||||
| 156 | #----------------------------# | ||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||
| 158 | 0 | my $cmd = "cat $outdir/*.fa | faops filter -U stdin $outdir/chr.fasta"; | |||||||||||||||||||||||||||
| 159 | 0 | App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | $cmd = "samtools faidx $outdir/chr.fasta"; | |||||||||||||||||||||||||||
| 162 | 0 | App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | return; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 19 | 1; | |||||||||||||||||||||||||||