comparison kmernator_wrapper.pl @ 0:d9da256384e1 default tip

Uploaded
author edward-kirton
date Thu, 14 Jul 2011 22:19:53 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d9da256384e1
1 #!/usr/bin/env perl
2
3 # FilterReads (AKA Kmernator) wrapper for Galaxy.
4 # Kmernator by Rob Egan (RSEgan@LBL.gov)
5 # Wrapper for Galaxy supported by Edward Kirton (ESKirton@LBL.gov)
6 # Produced under funding from the United States Department of Energy Office of Science
7 # Freely distributable under the same license as Galaxy itself.
8
9 use strict;
10 use warnings;
11 use File::Copy;
12
13 # SHIFT OUTFILE PATHS OFF ARGV
14 die unless @ARGV;
15 my $id=shift @ARGV;
16 my $results_dir=shift @ARGV;
17 my $working_dir=shift @ARGV;
18 my $mmap_infile=shift @ARGV;
19 my $kmer=shift @ARGV;
20 my $mmap_outfile=shift @ARGV;
21 my $gc_map_outfile=shift @ARGV;
22 my $partition_by_depth=shift @ARGV;
23 my $format=shift @ARGV;
24 my @infiles=();
25 my @history_ids=();
26 while (my $infile=shift @ARGV) {
27 last if $infile eq 'END';
28 push @infiles, $infile;
29 my $hid=shift @ARGV;
30 push @history_ids, $hid;
31 die("Input file $hid does not exist ($infile)\n") unless -e $infile;
32 }
33
34 # PREPARE
35 mkdir($working_dir) unless -d $working_dir;
36 chdir($working_dir) or die($!);
37 for (my $i=0; $i<=$#infiles; $i++) {
38 my $infile=$infiles[$i];
39 symlink($infile,"$working_dir/$i.fastq");
40 unshift @ARGV, "--input-file $working_dir/$i.fastq";
41 }
42 if ($mmap_infile ne 'None') {
43 symlink("$mmap_infile", "$working_dir/out-mmap");
44 unshift @ARGV, "--load-kmer-mmap 1";
45 }
46
47 # RUN
48 my $output=`FilterReads @ARGV --output-file $working_dir/out`;
49 die("Kmernator died while running command: @ARGV\nOUTPUT:\n$output\n") if $?;
50
51 # MOVE OUTFILES
52 if ($kmer < 1) {
53 my $dest=join("_",'primary',$id,'FilteredReads','visible',$format);
54 move("out-in.fastq","$results_dir/$dest") or die($!);
55 } elsif ($partition_by_depth > 0) {
56 opendir(DIR, $working_dir) or die($!);
57 my @files = readdir(DIR);
58 closedir(DIR);
59 foreach my $file ( @files ) {
60 next unless $file =~ /^out\-(MinDepth\d+\-PartitionDepth\d+)\.fastq$/ or $file =~ /^out\-(MinDepth\d+\-PartitionDepth\d+\-consensus\-\d+)\.fastq$/;
61 #next unless $file =~ /^out\-(MinDepth\d+\-PartitionDepth\d+)\-dataset_\d+\.fastq$/ or $file =~ /^out\-(MinDepth\d+\-PartitionDepth\d+\-consensus\-\d+)\.fastq$/;
62 my $dest=join("_",'primary',$id,$1,'visible',$format);
63 move($file,"$results_dir/$dest") or die($!);
64 }
65 move("out-GC.txt",$gc_map_outfile) or die($!);
66 move("out-mmap",$mmap_outfile) or die($!);
67 } else {
68 opendir(DIR, $working_dir) or die($!);
69 my @files = readdir(DIR);
70 closedir(DIR);
71 foreach my $file ( @files ) {
72 next unless $file =~ /^out\-(MinDepth\d+)\.fastq$/ or $file =~ /^out\-(MinDepth\d+\-consensus\-\d+)\.fastq$/;
73 #next unless $file =~ /^out\-(MinDepth\d+)\-dataset_\d+\.fastq$/ or $file =~ /^out\-(MinDepth\d+\-consensus\-\d+)\.fastq$/;
74 my $dest=join("_",'primary',$id,$1,'visible',$format);
75 move($file,"$results_dir/$dest") or die($!);
76 }
77 move("out-GC.txt",$gc_map_outfile) or die($!);
78 move("out-mmap",$mmap_outfile) or die($!);
79 }
80 if ( -f "out-0-Artifact.fastq" ) {
81 for (my $i=0; $i<=$#infiles; $i++) {
82 my $hid=$history_ids[$i];
83 my $dest=join("_",'primary',$id,"Dataset-$hid-Artifact",'visible',$format);
84 move("out-$i-Artifact.fastq", "$results_dir/$dest") or die($!);
85 }
86 }
87 exit;