comparison nanopolish_index.pl @ 7:32cb27adeb34 draft

planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopolish commit 2dabc22c3707cc87100b094b25705160b842e9f9-dirty
author jdv
date Mon, 12 Feb 2018 00:58:10 -0500
parents
children f64b148e6189
comparison
equal deleted inserted replaced
6:36cc4ae4160e 7:32cb27adeb34
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use 5.012;
6
7 use Cwd qw/getcwd abs_path/;
8 use File::Copy qw/copy/;
9 use Getopt::Long qw/:config pass_through/;
10 use threads;
11 use threads::shared;
12 use BioX::Seq::Stream;
13
14 my $fn_link = 'reads';
15
16 my $fn_fast5;
17 my $fn_reads;
18 my $fn_outfile;
19
20 # parse genome filename and add back to arg stack
21 GetOptions(
22 'fast5=s' => \$fn_fast5,
23 'reads=s' => \$fn_reads,
24 'outfile=s' => \$fn_outfile,
25 );
26
27 my $ret;
28
29 $fn_fast5 = abs_path($fn_fast5);
30 $fn_reads = abs_path($fn_reads);
31 $fn_outfile = abs_path($fn_outfile);
32
33 # extract FAST5 files to path where they are expected
34 my $fast5_dir = 'fast5';
35 if (-e $fast5_dir) {
36 warn "$fast5_dir exists, won't overwrite";
37 exit;
38 }
39 mkdir $fast5_dir;
40 my $cwd = abs_path( getcwd() );
41 chdir $fast5_dir;
42
43 # use system 'tar' to transparently and safely handle absolute paths
44 $ret = system(
45 'tar',
46 '-xf',
47 $fn_fast5
48 );
49 die "Failed to extract tarball: $!\n"
50 if ($ret);
51
52 chdir $cwd;
53
54 symlink( $fn_reads, $fn_link )
55 or die "Failed to create symlink: $@";
56
57 # index reads
58 $ret = system(
59 'nanopolish',
60 'index',
61 '--directory' => $fast5_dir,
62 $fn_link,
63 );
64 die "Failed nanopolish indexing: $!\n"
65 if ($ret);
66
67 my @idx_fns = glob "$fn_link.*";
68 $ret = system(
69 'tar',
70 '-cf' => $fn_outfile,
71 @idx_fns,
72 );
73 die "Failed tarball creation: $!\n"
74 if ($ret);