Mercurial > repos > msjeon > abyss_tool
comparison abyss_toolsuite-92636934a189/abyss/abyss-pe_wrapper.pl @ 0:ce99b6666d1f draft
Uploaded
author | msjeon |
---|---|
date | Mon, 11 Jun 2012 14:48:15 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ce99b6666d1f |
---|---|
1 #!/usr/bin/env perl | |
2 | |
3 use strict; | |
4 use warnings; | |
5 use File::Copy; | |
6 | |
7 die("ERROR: Expected at least 8 arguments; got: @ARGV\n") unless @ARGV >= 8; | |
8 | |
9 # GET ARGS | |
10 my $kmer_size=shift @ARGV; | |
11 my $min_num_pairs=shift @ARGV; | |
12 my $outdir=shift @ARGV; | |
13 my $outfile=shift @ARGV; | |
14 my $contigs_outfile=shift @ARGV; | |
15 my $sam_outfile=shift @ARGV; | |
16 my $hist_outfile=shift @ARGV; | |
17 | |
18 # ALL FILES GO IN THIS extra_files_path | |
19 unless (-d $outdir) { | |
20 mkdir $outdir or die("Unable to make dir, $outdir\n"); | |
21 } | |
22 chdir $outdir; | |
23 | |
24 # RUN COMMAND | |
25 `abyss-pe k=$kmer_size n=$min_num_pairs in='@ARGV' name=abyss 2> $outdir/abyss.stderr > $outdir/abyss.stdout`; | |
26 if ($? != 0) { | |
27 unless ( -s "$outdir/abyss-3.hist") { print STDERR "NO CONTIGS WERE PRODUCED!\n" } | |
28 open(IN, "<$outdir/abyss.stdout") or die($!); | |
29 while (<IN>) { print STDERR $_ } | |
30 close IN; | |
31 die("ABORTING\n"); | |
32 } | |
33 | |
34 # FILTER HISTOGRAM | |
35 open (IN, "<$outdir/abyss.stderr") or die($!); | |
36 open (OUT, ">$outfile") or die($!); | |
37 while (my $line=<IN>) { | |
38 my @chars=split(//, $line); | |
39 my $filter=0; | |
40 foreach my $char (@chars) { | |
41 if (ord($char) >= 129) { | |
42 $filter=1; | |
43 last; | |
44 } | |
45 } | |
46 print OUT $line unless $filter; | |
47 } | |
48 close IN; | |
49 close OUT; | |
50 unlink("$outdir/abyss.stderr"); | |
51 | |
52 # OUTPUT INFO LINE TEXT | |
53 open(IN, "<$outdir/abyss.stdout") or die($!); | |
54 while (<IN>) { | |
55 if (/^Assembled \d+ k\-mer in \d+ contigs/) { | |
56 print; | |
57 last; | |
58 } | |
59 } | |
60 close IN; | |
61 | |
62 # GALAXY DOESN'T WANT GZIPPED DATAFILES | |
63 run("gunzip $outdir/abyss-3.sam.gz"); | |
64 | |
65 # MOVE OUTFILES | |
66 mv_outfile("$outdir/abyss-contigs.fa", $contigs_outfile); | |
67 mv_outfile("$outdir/abyss-3.sam", $sam_outfile); | |
68 mv_outfile("$outdir/coverage.hist", $hist_outfile); | |
69 exit; | |
70 | |
71 sub run { | |
72 my $cmd=shift; | |
73 my $output=`$cmd 2>&1`; | |
74 if ($? != 0) { | |
75 print STDERR "ERROR RUNNING COMMAND: $cmd\n"; | |
76 die($output); | |
77 } | |
78 return $output; | |
79 } | |
80 | |
81 | |
82 sub mv_outfile { | |
83 my ($src,$dest)=@_; | |
84 # if dest defined and src exist, then move outfiles to galaxy-specified location | |
85 if ( $dest ne 'None' and -f $src ) { | |
86 unlink($dest); | |
87 move($src,$dest); | |
88 } | |
89 } | |
90 __END__ |