annotate flexbar.pl @ 44:2d1947bea9d6 draft default tip

Uploaded
author jtilman
date Tue, 07 May 2019 10:25:03 -0400
parents e1f80a81ba2c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
1 #!/usr/bin/env perl
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
2
44
2d1947bea9d6 Uploaded
jtilman
parents: 42
diff changeset
3 # Flexbar wrapper for Galaxy tool definition, version 3.5.0
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
4 # Author: Johannes Roehr
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
5
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
6 use warnings;
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
7 use strict;
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
8
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
9 my $format;
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
10 my @inFiles;
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
11 my @outFiles;
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
12
42
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
13 my $compression = "";
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
14
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
15 foreach(0..$#ARGV){
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
16 my $arg = $ARGV[$_];
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
17
40
2fcee21876db Uploaded
jtilman
parents: 38
diff changeset
18 if($arg =~ /\.(fastq\w+)$/ || $arg =~ /\.(fastq\w+\.gz)$/ || $arg =~ /\.(fastq\w+\.bz2)$/){
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
19
40
2fcee21876db Uploaded
jtilman
parents: 38
diff changeset
20 if(defined $format && $format ne $1){
42
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
21 warn "Read files should have the same format.\n";
40
2fcee21876db Uploaded
jtilman
parents: 38
diff changeset
22 exit 1;
2fcee21876db Uploaded
jtilman
parents: 38
diff changeset
23 }
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
24 $format = $1;
40
2fcee21876db Uploaded
jtilman
parents: 38
diff changeset
25
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
26 my $file = $arg;
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
27
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
28 $arg =~ s/\.fastq\w+$/\.fastq/;
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
29 $arg =~ s/\.fastq\w+\.gz$/\.fastq\.gz/;
40
2fcee21876db Uploaded
jtilman
parents: 38
diff changeset
30 $arg =~ s/\.fastq\w+\.bz2$/\.fastq\.bz2/;
2fcee21876db Uploaded
jtilman
parents: 38
diff changeset
31
42
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
32 $compression = "GZ" if $arg =~ /\.fastq\.gz$/;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
33 $compression = "BZ2" if $arg =~ /\.fastq\.bz2$/;
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
34
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
35 $ARGV[$_] = $arg;
42
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
36
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
37 if($arg =~ /\.dat_input\w\.fastq$/ || $arg =~ /\.dat_input\w\.fastq\.gz$/ || $arg =~ /\.dat_input\w\.fastq\.bz2$/){
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
38 push @inFiles, $arg;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
39 rename $file, $arg;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
40 }
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
41
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
42 push @outFiles, $arg if $arg =~ /\.dat\.fastq$/ || $arg =~ /\.dat\.fastq\.gz$/ || $arg =~ /\.dat\.fastq\.bz2$/;
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
43 }
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
44 }
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
45
42
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
46 my $barcoded = 0;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
47
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
48 $barcoded = 1 if $ARGV[$#ARGV] =~ /barcoded$/;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
49
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
50 my $call = join " ", @ARGV[0..($#ARGV - $barcoded)];
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
51
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
52 # $call = $call ." --zip-output ". $compression if $barcoded && $compression ne "";
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
53
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
54 system $call and exit 1;
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
55
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
56
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
57 unlink $_ or warn "Could not unlink $_: $!" foreach(@inFiles);
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
58
42
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
59 if($barcoded){
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
60 $format =~ s/\.gz//;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
61 $format =~ s/\.bz2//;
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
62
42
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
63 foreach(<$ARGV[$#ARGV]/flexbarOut*.fastq*>){
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
64
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
65 my $file = $_;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
66
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
67 s/fastq$/$format/;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
68 # s/fastq\.gz$/$format/;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
69 # s/fastq\.bz2$/$format/;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
70
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
71 rename $file, $_;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
72 }
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
73 }
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
74 else{
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
75 foreach(@outFiles){
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
76
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
77 my $file = $_;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
78
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
79 s/\.fastq$//;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
80 s/\.fastq\.gz$//;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
81 s/\.fastq\.bz2$//;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
82
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
83 rename $file, $_;
e1f80a81ba2c Uploaded
jtilman
parents: 40
diff changeset
84 }
38
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
85 }
216a55a39b52 Uploaded
jtilman
parents:
diff changeset
86