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