# HG changeset patch # User jtilman # Date 1530617851 14400 # Node ID e1f80a81ba2c6953852bfb8a2385582cbb5065c6 # Parent b0847c1e320be56d4e0278b65a81f6a05c581eb8 Uploaded diff -r b0847c1e320b -r e1f80a81ba2c flexbar.pl --- a/flexbar.pl Tue Jul 03 07:36:49 2018 -0400 +++ b/flexbar.pl Tue Jul 03 07:37:31 2018 -0400 @@ -10,13 +10,15 @@ my @inFiles; my @outFiles; +my $compression = ""; + foreach(0..$#ARGV){ my $arg = $ARGV[$_]; if($arg =~ /\.(fastq\w+)$/ || $arg =~ /\.(fastq\w+\.gz)$/ || $arg =~ /\.(fastq\w+\.bz2)$/){ if(defined $format && $format ne $1){ - print STDERR "Paired read files should have the same format.\n"; + warn "Read files should have the same format.\n"; exit 1; } $format = $1; @@ -27,29 +29,58 @@ $arg =~ s/\.fastq\w+\.gz$/\.fastq\.gz/; $arg =~ s/\.fastq\w+\.bz2$/\.fastq\.bz2/; - push @inFiles, $arg if $arg =~ /\.dat_input\.fastq$/ || $arg =~ /\.dat_input\.fastq\.gz$/ || $arg =~ /\.dat_input\.fastq\.bz2$/; - push @outFiles, $arg if $arg =~ /\.dat\.fastq$/ || $arg =~ /\.dat\.fastq\.gz$/ || $arg =~ /\.dat\.fastq\.bz2$/; + $compression = "GZ" if $arg =~ /\.fastq\.gz$/; + $compression = "BZ2" if $arg =~ /\.fastq\.bz2$/; $ARGV[$_] = $arg; - rename $file, $arg; + + if($arg =~ /\.dat_input\w\.fastq$/ || $arg =~ /\.dat_input\w\.fastq\.gz$/ || $arg =~ /\.dat_input\w\.fastq\.bz2$/){ + push @inFiles, $arg; + rename $file, $arg; + } + + push @outFiles, $arg if $arg =~ /\.dat\.fastq$/ || $arg =~ /\.dat\.fastq\.gz$/ || $arg =~ /\.dat\.fastq\.bz2$/; } } -my $call = join " ", @ARGV; +my $barcoded = 0; + +$barcoded = 1 if $ARGV[$#ARGV] =~ /barcoded$/; + +my $call = join " ", @ARGV[0..($#ARGV - $barcoded)]; + +# $call = $call ." --zip-output ". $compression if $barcoded && $compression ne ""; system $call and exit 1; unlink $_ or warn "Could not unlink $_: $!" foreach(@inFiles); -foreach(@outFiles){ - - my $file = $_; +if($barcoded){ + $format =~ s/\.gz//; + $format =~ s/\.bz2//; - s/\.fastq$//; - s/\.fastq\.gz$//; - s/\.fastq\.bz2$//; - - rename $file, $_; + foreach(<$ARGV[$#ARGV]/flexbarOut*.fastq*>){ + + my $file = $_; + + s/fastq$/$format/; + # s/fastq\.gz$/$format/; + # s/fastq\.bz2$/$format/; + + rename $file, $_; + } +} +else{ + foreach(@outFiles){ + + my $file = $_; + + s/\.fastq$//; + s/\.fastq\.gz$//; + s/\.fastq\.bz2$//; + + rename $file, $_; + } }