changeset 1:898db63d2e84 draft

upgrade to new version
author bgruening
date Wed, 17 Jul 2013 15:05:43 -0400
parents 3c1664caa8e3
children 9109c2c3be1e
files trim_galore trim_galore_wrapper.xml
diffstat 2 files changed, 240 insertions(+), 350 deletions(-) [+]
line wrap: on
line diff
--- a/trim_galore	Sat Jul 06 09:52:23 2013 -0400
+++ b/trim_galore	Wed Jul 17 15:05:43 2013 -0400
@@ -7,7 +7,7 @@
 use File::Basename;
 use Cwd;
 
-## This program is Copyright (C) 2012, Felix Krueger (felix.krueger@babraham.ac.uk)
+## This program is Copyright (C) 2012-13, Felix Krueger (felix.krueger@babraham.ac.uk)
 
 ## This program is free software: you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 
 
 ## this script is taking in FastQ sequences and trims them with Cutadapt
-## last modified on 18 10 2012
+## last modified on 10 April 2013
 
 ########################################################################
 
@@ -37,11 +37,17 @@
 ########################################################################
 
 
-my $trimmer_version = '0.2.5';
+my $trimmer_version = '0.2.8';
 my $DOWARN = 1; # print on screen warning and text by default
 BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } };
 
-my ($cutoff,$adapter,$stringency,$rrbs,$length_cutoff,$keep,$fastqc,$non_directional,$phred_encoding,$fastqc_args,$trim,$gzip,$validate,$retain,$length_read_1,$length_read_2,$a2,$error_rate,$output_dir,$no_report_file) = process_commandline();
+my ($cutoff,$adapter,$stringency,$rrbs,$length_cutoff,$keep,$fastqc,$non_directional,$phred_encoding,$fastqc_args,$trim,$gzip,$validate,$retain,$length_read_1,$length_read_2,$a2,$error_rate,$output_dir,$no_report_file,$dont_gzip,$clip_r1,$clip_r2) = process_commandline();
+
+my @filenames = @ARGV;
+
+die "\nPlease provide the filename(s) of one or more FastQ file(s) to launch Trim Galore!\n
+USAGE:  'trim_galore [options] <filename(s)>'    or    'trim_galore --help'    for more options\n\n" unless (@filenames);
+
 
 ### SETTING DEFAULTS UNLESS THEY WERE SPECIFIED
 unless (defined $cutoff){
@@ -68,8 +74,6 @@
   $cutoff += 31;
 }
 
-my @filenames = @ARGV;
-
 my $file_1;
 my $file_2;
 
@@ -155,7 +159,7 @@
       }
 
       if ($length_read_2 == 35){
-	warn "Length cut-off for read 2: $length_read_2 b (default)\n";
+	warn "Length cut-off for read 2: $length_read_2 bb (default)\n";
 	print REPORT "Length cut-off for read 2: $length_read_2 bp (default)\n";
       }
       else{
@@ -180,6 +184,16 @@
     print REPORT "All sequences will be trimmed by 1 bp on their 3' end to avoid problems with invalid paired-end alignments with Bowtie 1\n";
   }
 
+  if ($clip_r1){
+    warn "All Read 1 sequences will be trimmed by $clip_r1 bp from their 5' end to avoid poor qualities or biases\n";
+    print REPORT "All Read 1 sequences will be trimmed by $clip_r1 bp from their 5' end to avoid poor qualities or biases\n";
+  }
+  if ($clip_r2){
+    warn "All Read 2 sequences will be trimmed by $clip_r2 bp from their 5' end to avoid poor qualities or biases (e.g. M-bias for BS-Seq applications)\n";
+    print REPORT "All Read 2 sequences will be trimmed by $clip_r2 bp from their 5' end to avoid poor qualities or biases (e.g. M-bias for BS-Seq applications)\n";
+  }
+
+
   if ($fastqc){
     warn "Running FastQC on the data once trimming has completed\n";
     print REPORT "Running FastQC on the data once trimming has completed\n";
@@ -195,9 +209,13 @@
     print REPORT "Keeping quality trimmed (but not yet adapter trimmed) intermediate FastQ file\n";
   }
 
+
   if ($gzip or $filename =~ /\.gz$/){
-    warn "Output file will be GZIP compressed\n";
-    print REPORT "Output file will be GZIP compressed\n";
+    $gzip = 1;
+    unless ($dont_gzip){
+      warn "Output file(s) will be GZIP compressed\n";
+      print REPORT "Output file will be GZIP compressed\n";
+    }
   }
 
   warn "\n";
@@ -265,9 +283,24 @@
     $output_filename =~ s/$/_trimmed.fq/;
   }
 
+  if ($gzip or $filename =~ /\.gz$/){
+    unless ($dont_gzip){
+      if ($validate){
+	open (OUT,'>',$output_dir.$output_filename) or die "Can't open $output_filename: $!\n"; # don't need to gzip intermediate file
+      }
+      else{
+	$output_filename .= '.gz';
+	open (OUT,"| gzip -c - > ${output_dir}${output_filename}") or die "Can't write to $output_filename: $!\n";
+      }
+    }
+    else{
+      open (OUT,'>',$output_dir.$output_filename) or die "Can't open $output_filename: $!\n"; # don't need to gzip intermediate file
+    }
+  }
+  else{
+    open (OUT,'>',$output_dir.$output_filename) or die "Can't open $output_filename: $!\n";
+  }
   warn "Writing final adapter and quality trimmed output to $output_filename\n\n";
-  open (OUT,'>',$output_dir.$output_filename) or die "Can't open $output_filename: $!\n";
-  sleep (2);
 
   my $count = 0;
   my $too_short = 0;
@@ -389,6 +422,12 @@
 	print OUT "$l1$seq\n$l3$qual\n";
       }
       else{ # single end
+
+	if ($clip_r1){
+	  $seq = substr($seq,$clip_r1); # starting after the sequences to be trimmed until the end of the sequence
+	  $qual = substr($qual,$clip_r1);
+	}
+
 	if (length $seq < $length_cutoff){
 	  ++$too_short;
 	  next;
@@ -463,6 +502,12 @@
 	print OUT "$l1$seq\n$l3$qual\n";
       }
       else{ # single end
+
+	if ($clip_r1){
+	  $seq = substr($seq,$clip_r1); # starting after the sequences to be trimmed until the end of the sequence
+	  $qual = substr($qual,$clip_r1);
+  	}
+
 	if (length $seq < $length_cutoff){
 	  ++$too_short;
 	  next;
@@ -535,24 +580,17 @@
   warn "\n";
   print REPORT "\n";
 
-  ### RUNNING FASTQC
-  if ($fastqc){
-    warn "\n  >>> Now running FastQC on the data <<<\n\n";
-    sleep (5);
-    if ($fastqc_args){
-      system ("$path_to_fastqc $fastqc_args $output_filename");
-    }
-    else{
-      system ("$path_to_fastqc $output_filename");
-    }
-  }
-
-  ### COMPRESSING OUTPUT FILE
-  unless ($validate){ # not gzipping intermediate files for paired-end files
-    if ($gzip or $filename =~ /\.gz$/){
-      warn "\n  >>> GZIP-ing the output file <<<\n\n";
-      system ("gzip -f $output_filename");
-      $output_filename = $output_filename.'.gz';
+  ### RUNNING FASTQC unless we are dealing with paired-end files
+  unless($validate){
+    if ($fastqc){
+      warn "\n  >>> Now running FastQC on the data <<<\n\n";
+      sleep (5);
+      if ($fastqc_args){
+	system ("$path_to_fastqc $fastqc_args $output_dir$output_filename");
+      }
+      else{
+	system ("$path_to_fastqc $output_dir$output_filename");
+      }
     }
   }
 
@@ -585,43 +623,24 @@
 	sleep (3);
 
 	if ($fastqc_args){
-	  system ("$path_to_fastqc $fastqc_args $val_1");
+	  system ("$path_to_fastqc $fastqc_args $output_dir$val_1");
 	}
 	else{
-	  system ("$path_to_fastqc $val_1");
+	  system ("$path_to_fastqc $output_dir$val_1");
 	}
 
 	warn "\n  >>> Now running FastQC on the validated data $val_2<<<\n\n";
 	sleep (3);
 
 	if ($fastqc_args){
-	  system ("$path_to_fastqc $fastqc_args $val_2");
+	  system ("$path_to_fastqc $fastqc_args $output_dir$val_2");
 	}
 	else{
-	  system ("$path_to_fastqc $val_2");
+	  system ("$path_to_fastqc $output_dir$val_2");
 	}
 	
       }
 
-      if ($gzip or $filename =~ /\.gz$/){
-		
-	# compressing main fastQ output files
-	warn "Compressing the validated output file $val_1 ...\n";
-	system ("gzip -f $val_1");
-	
-	warn "Compressing the validated output file $val_2 ...\n";
-	system ("gzip -f $val_2");
-
-
-	if ($retain){ # compressing unpaired reads
-	  warn "Compressing the unpaired read output $un_1 ...\n";
-	  system ("gzip -f $un_1");
-	
-	  warn "Compressing the unpaired read output $un_2 ...\n";
-	  system ("gzip -f $un_2");
-	}
-      }
-
       warn "Deleting both intermediate output files $file_1 and $file_2\n";
       unlink "$output_dir$file_1";
       unlink "$output_dir$file_2";
@@ -641,7 +660,7 @@
   my $file_1 = shift;
   my $file_2 = shift;
 
-  warn "file_1 $file_1 file_2 $file_2\n\n";
+  warn "file_1: $file_1, file_2: $file_2\n\n";
 
   if ($file_1 =~ /\.gz$/){
     open (IN1,"zcat $output_dir$file_1 |") or die "Couldn't read from file $file_1: $!\n";
@@ -677,8 +696,32 @@
     $out_2 =~ s/trimmed\.fq$/val_2.fq/;
   }
 
-  open (R1,'>',$output_dir.$out_1) or die "Couldn't write to $out_1 $!\n";
-  open (R2,'>',$output_dir.$out_2) or die "Couldn't write to $out_2 $!\n";
+  if ($gzip){
+    if ($dont_gzip){
+      open (R1,'>',$output_dir.$out_1) or die "Couldn't write to $out_1 $!\n";
+    }
+    else{
+      $out_1 .= '.gz';
+      open (R1,"| gzip -c - > ${output_dir}${out_1}") or die "Can't write to $out_1: $!\n";
+    }
+  }
+  else{
+    open (R1,'>',$output_dir.$out_1) or die "Couldn't write to $out_1 $!\n";
+  }
+
+  if ($gzip){
+    if ($dont_gzip){
+      open (R2,'>',$output_dir.$out_2) or die "Couldn't write to $out_2 $!\n";
+    }
+    else{
+      $out_2 .= '.gz';
+      open (R2,"| gzip -c - > ${output_dir}${out_2}") or die "Can't write to $out_2: $!\n";
+    }
+  }
+  else{
+    open (R2,'>',$output_dir.$out_2) or die "Couldn't write to $out_2 $!\n";
+  }
+
   warn "Writing validated paired-end read 1 reads to $out_1\n";
   warn "Writing validated paired-end read 2 reads to $out_2\n\n";
 
@@ -704,8 +747,31 @@
       $unpaired_2 =~ s/trimmed\.fq$/unpaired_2.fq/;
     }
 
-    open (UNPAIRED1,'>',$output_dir.$unpaired_1) or die "Couldn't write to $unpaired_1: $!\n";
-    open (UNPAIRED2,'>',$output_dir.$unpaired_2) or die "Couldn't write to $unpaired_2: $!\n";
+    if ($gzip){
+      if ($dont_gzip){
+	open (UNPAIRED1,'>',$output_dir.$unpaired_1) or die "Couldn't write to $unpaired_1: $!\n";
+      }
+      else{
+	$unpaired_1 .= '.gz';
+	open (UNPAIRED1,"| gzip -c - > ${output_dir}${unpaired_1}") or die "Can't write to $unpaired_1: $!\n";
+      }
+    }
+    else{
+      open (UNPAIRED1,'>',$output_dir.$unpaired_1) or die "Couldn't write to $unpaired_1: $!\n";
+    }
+
+    if ($gzip){
+      if ($dont_gzip){
+	open (UNPAIRED2,'>',$output_dir.$unpaired_2) or die "Couldn't write to $unpaired_2: $!\n";
+      }
+      else{
+	$unpaired_2 .= '.gz';
+	open (UNPAIRED2,"| gzip -c - > ${output_dir}${unpaired_2}") or die "Can't write to $unpaired_2: $!\n";
+      }
+    }
+    else{
+      open (UNPAIRED2,'>',$output_dir.$unpaired_2) or die "Couldn't write to $unpaired_2: $!\n";
+    }
 
     warn "Writing unpaired read 1 reads to $unpaired_1\n";
     warn "Writing unpaired read 2 reads to $unpaired_2\n\n";
@@ -733,7 +799,7 @@
     ++$count;
 
 
-    ## small check if the sequence files appear to FastQ files
+    ## small check if the sequence files appear to be FastQ files
     if ($count == 1){ # performed just once
       if ($id_1 !~ /^\@/ or $l3_1 !~ /^\+/){
 	die "Input file doesn't seem to be in FastQ format at sequence $count\n";
@@ -746,6 +812,14 @@
     chomp $seq_1;
     chomp $seq_2;
 
+    if ($clip_r1){
+      $seq_1 = substr($seq_1,$clip_r1); # starting after the sequences to be trimmed until the end of the sequence
+      $qual_1 = substr($qual_1,$clip_r1);
+    }
+    if ($clip_r2){
+      $seq_2 = substr($seq_2,$clip_r2); # starting after the sequences to be trimmed until the end of the sequence
+      $qual_2 = substr($qual_2,$clip_r2);
+    }
 
     ### making sure that the reads do have a sensible length
     if ( (length($seq_1) < $length_cutoff) or (length($seq_2) < $length_cutoff) ){
@@ -795,6 +869,14 @@
     warn "Number of unpaired read 2 reads printed: $read_2_printed\n";
   }
 
+  close R1 or die $!;
+  close R2 or die $!;
+
+  if ($retain){
+    close UNPAIRED1 or die $!;
+    close UNPAIRED2 or die $!;
+  }
+
   warn "\n";
   if ($retain){
     return ($out_1,$out_2,$unpaired_1,$unpaired_2);
@@ -830,6 +912,9 @@
   my $output_dir;
   my $no_report_file;
   my $suppress_warn;
+  my $dont_gzip;
+  my $clip_r1;
+  my $clip_r2;
 
   my $command_line = GetOptions ('help|man' => \$help,
 				 'q|quality=i' => \$quality,
@@ -856,8 +941,12 @@
 				 'o|output_dir=s' => \$output_dir,
 				 'no_report_file' => \$no_report_file,
 				 'suppress_warn' => \$suppress_warn,
+				 'dont_gzip' => \$dont_gzip,
+				 'clip_R1=i' => \$clip_r1,
+				 'clip_R2=i' => \$clip_r2,
 				);
-  
+
+
   ### EXIT ON ERROR if there were errors with any of the supplied options
   unless ($command_line){
     die "Please respecify command line options\n";
@@ -879,7 +968,7 @@
                                (powered by Cutadapt)
                                   version $trimmer_version
 
-                             Last update: 18 10 2012
+                             Last update: 10 04 2013
 
 VERSION
     exit;
@@ -1011,7 +1100,25 @@
     $output_dir = '';
   }
 
-  return ($quality,$adapter,$stringency,$rrbs,$length_cutoff,$keep,$fastqc,$non_directional,$phred_encoding,$fastqc_args,$trim,$gzip,$validate,$retain,$length_read_1,$length_read_2,$adapter2,$error_rate,$output_dir,$no_report_file);
+  ### Trimming at the 5' end
+  if (defined $clip_r2){ # trimming 5' bases of read 1
+    die "Clipping the 5' end of read 2 is only allowed for paired-end files (--paired)\n" unless ($validate);
+  }
+
+  if (defined $clip_r1){ # trimming 5' bases of read 1
+    unless ($clip_r1 > 0 and $clip_r1 < 100){
+      die "The 5' clipping value for read 1 should have a sensible value (> 0 and < read length)\n\n";
+    }
+  }
+
+  if (defined $clip_r2){ # trimming 5' bases of read 2
+    unless ($clip_r2 > 0 and $clip_r2 < 100){
+      die "The 5' clipping value for read 2 should have a sensible value (> 0 and < read length)\n\n";
+    }
+  }
+
+
+  return ($quality,$adapter,$stringency,$rrbs,$length_cutoff,$keep,$fastqc,$non_directional,$phred_encoding,$fastqc_args,$trim,$gzip,$validate,$retain,$length_read_1,$length_read_2,$adapter2,$error_rate,$output_dir,$no_report_file,$dont_gzip,$clip_r1,$clip_r2);
 }
 
 
@@ -1065,8 +1172,11 @@
 -e <ERROR RATE>         Maximum allowed error rate (no. of errors divided by the length of the matching
                         region) (default: 0.1)
 
---gzip                  Compress the output file with gzip. If the input files are gzip-compressed
-                        the output files will be automatically gzip compressed as well.
+--gzip                  Compress the output file with GZIP. If the input files are GZIP-compressed
+                        the output files will automatically be GZIP compressed as well. As of v0.2.8 the
+                        compression will take place on the fly.
+
+--dont_gzip             Output files won't be compressed with GZIP. This option overrides --gzip.
 
 --length <INT>          Discard reads that became shorter than length INT because of either
                         quality or adapter trimming. A value of '0' effectively disables
@@ -1084,6 +1194,17 @@
 
 --suppress_warn         If specified any output to STDOUT or STDERR will be suppressed.
 
+--clip_R1 <int>         Instructs Trim Galore to remove <int> bp from the 5' end of read 1 (or single-end
+                        reads). This may be useful if the qualities were very poor, or if there is some
+                        sort of unwanted bias at the 5' end. Default: OFF.
+
+--clip_R2 <int>         Instructs Trim Galore to remove <int> bp from the 5' end of read 2 (paired-end reads
+                        only). This may be useful if the qualities were very poor, or if there is some sort
+                        of unwanted bias at the 5' end. For paired-end BS-Seq, it is recommended to remove
+                        the first few bp because the end-repair reaction may introduce a bias towards low
+                        methylation. Please refer to the M-bias plot section in the Bismark User Guide for
+                        some examples. Default: OFF.
+
 
 
 RRBS-specific options (MspI digested material):
@@ -1152,7 +1273,7 @@
                         Default: 35 bp.
 
 
-Last modified on 18 Oct 2012.
+Last modified on 15 July 2013.
 
 HELP
   exit;
--- a/trim_galore_wrapper.xml	Sat Jul 06 09:52:23 2013 -0400
+++ b/trim_galore_wrapper.xml	Wed Jul 17 15:05:43 2013 -0400
@@ -1,5 +1,5 @@
-<tool id="trim_galore" name="Trim Galore" version="0.2.4.1">
-    <!-- Wrapper compatible with Trim Galore version 0.2.4.0 -->
+<tool id="trim_galore" name="Trim Galore" version="0.2.8">
+    <!-- Wrapper compatible with Trim Galore version 0.2.8 -->
     <description>adaptive quality and adapter trimmer</description>
     <version_command interpreter="perl">trim_galore --version</version_command>
     <requirements>
@@ -9,7 +9,37 @@
     <command interpreter="perl">
         #from glob import glob
         #import tempfile, os
-        
+
+        ##
+        ##  Creating a temporary directory where trim_galore will store all result files
+        ##
+
+        #set $temp_dir = os.path.abspath(tempfile.mkdtemp())
+
+
+        ## trim_galore removes .fastq and .fq file extensions of input files. 
+        ## That is essential if Galaxy provides links to files (these can have real extensions), but that behaviour is causing an inconsitency in output filenaming.
+        ## Fix: link every file to $TMP without file extension
+
+        #if $singlePaired.sPaired == "single":
+            #set $input_singles_tmp_handle = tempfile.NamedTemporaryFile( dir=$temp_dir )
+            #set $input_singles_tmp = $input_singles_tmp_handle.name
+            #silent $input_singles_tmp_handle.close()
+            #silent os.system("ln -s %s %s" % (str($singlePaired.input_singles), $input_singles_tmp))
+        #else:
+            #set $input_mate1_tmp_handle = tempfile.NamedTemporaryFile( dir=$temp_dir )
+            #set $input_mate2_tmp_handle = tempfile.NamedTemporaryFile( dir=$temp_dir )
+            
+            #set $input_mate1_tmp = $input_mate1_tmp_handle.name
+            #silent $input_mate1_tmp_handle.close()
+
+            #set $input_mate2_tmp = $input_mate2_tmp_handle.name
+            #silent $input_mate2_tmp_handle.close()
+
+            #silent os.system("ln -s %s %s" % (str($singlePaired.input_mate1), $input_mate1_tmp))
+            #silent os.system("ln -s %s %s" % (str($singlePaired.input_mate2), $input_mate2_tmp))
+        #end if
+
         trim_galore
 
         ##
@@ -35,6 +65,14 @@
             ## default 20
             --length $params.min_length
 
+            #if int($params.clip_R1) > 0:
+                --clip_R1 $params.clip_R1
+            #end if
+            
+            #if int($params.clip_R2) > 0:
+                --clip_R2 $params.clip_R2
+            #end if
+
             #if $params.retain_unpaired.settingsType == "retain_unpaired_output":
                 --retain_unpaired
                 --length_1 $params.retain_unpaired.length_1
@@ -54,12 +92,6 @@
 
         #end if
 
-        ##
-        ##  Creating a temporary directory where trim_galore will store all result files
-        ##
-
-        #set $temp_dir = os.path.abspath(tempfile.mkdtemp())
-
         --output_dir $temp_dir
         --suppress_warn
 
@@ -79,7 +111,7 @@
             #end if
 
             ## input sequence
-            $singlePaired.input_singles
+            $input_singles_tmp
         #else:
             --paired 
             #if $singlePaired.input_mate1.ext == "fastqillumina":
@@ -100,8 +132,8 @@
             #end if
 
             ## input sequences
-            $singlePaired.input_mate1
-            $singlePaired.input_mate2
+            $input_mate1_tmp
+            $input_mate2_tmp
 
         #end if
 
@@ -113,32 +145,32 @@
 
 
         #if $singlePaired.sPaired == "single":
-            #set $single_end_path =  os.path.join($temp_dir, os.path.basename(str($singlePaired.input_singles)) + '_trimmed.fq')
+            #set $single_end_path =  os.path.join($temp_dir, os.path.basename(str($input_singles_tmp)) + '_trimmed.fq')
             mv $single_end_path $trimmed_reads_single;
 
             #if $params.settingsType == "custom":
                 #if $params.report:
-                    #set $report_path =  os.path.join($temp_dir, os.path.basename(str($singlePaired.input_singles)) + '_trimming_report.txt')
+                    #set $report_path =  os.path.join($temp_dir, os.path.basename(str($input_singles_tmp)) + '_trimming_report.txt')
                     mv $report_path $report_file;
                 #end if
             #end if
 
         #else:
-            #set $paired_end_path_1 =  os.path.join($temp_dir, os.path.basename(str($singlePaired.input_mate1)) + '_val_1.fq')
-            #set $paired_end_path_2 =  os.path.join($temp_dir, os.path.basename(str($singlePaired.input_mate2)) + '_val_2.fq')
+            #set $paired_end_path_1 =  os.path.join($temp_dir, os.path.basename(str($input_mate1_tmp)) + '_val_1.fq')
+            #set $paired_end_path_2 =  os.path.join($temp_dir, os.path.basename(str($input_mate2_tmp)) + '_val_2.fq')
             mv $paired_end_path_1 $trimmed_reads_pair1;
             mv $paired_end_path_2 $trimmed_reads_pair2;
 
             #if $params.settingsType == "custom":
                 #if $params.retain_unpaired.settingsType == "retain_unpaired_output":
-                    #set $unpaired_path_1 =  os.path.join($temp_dir, os.path.basename(str($singlePaired.input_mate1)) + '_unpaired_1.fq')
-                    #set $unpaired_path_2 =  os.path.join($temp_dir, os.path.basename(str($singlePaired.input_mate2)) + '_unpaired_2.fq')
+                    #set $unpaired_path_1 =  os.path.join($temp_dir, os.path.basename(str($input_mate1_tmp)) + '_unpaired_1.fq')
+                    #set $unpaired_path_2 =  os.path.join($temp_dir, os.path.basename(str($input_mate2_tmp)) + '_unpaired_2.fq')
                     mv $unpaired_path_1 $unpaired_reads_1;
                     mv $unpaired_path_2 $unpaired_reads_2;
                 #end if
 
                 #if $params.report:
-                    #set $report_path =  os.path.join($temp_dir, os.path.basename(str($singlePaired.input_mate1)) + '_trimming_report.txt')
+                    #set $report_path =  os.path.join($temp_dir, os.path.basename(str($input_mate1_tmp)) + '_trimming_report.txt')
                     mv $report_path $report_file;
                 #end if
 
@@ -146,7 +178,7 @@
         #end if
 
         ## delete the temp_dir
-        rm -rf $temp_dir
+        ##rm -rf $temp_dir
 
     </command>
     <inputs>
@@ -188,6 +220,9 @@
                 <param name="error_rate" type="float" value="0.1" label="Maximum allowed error rate" />
                 <param name="min_length" type="integer" value="20" label="Discard reads that became shorter than length INT" />
 
+                <param name="clip_R1" type="integer" value="0" label="nstructs Trim Galore to remove INT bp from the 5' end of read 1" />
+                <param name="clip_R2" type="integer" value="0" label="nstructs Trim Galore to remove INT bp from the 5' end of read 2" />
+
                 <param name="report" type="boolean" truevalue="true" falsevalue="false" checked="False" label="Generate a report file" help="" />
 
                 <conditional name="retain_unpaired">
@@ -306,272 +341,6 @@
 
 ------
 
-**Know what you are doing**
-
-.. class:: warningmark
-
-There is no such thing (yet) as an automated gearshift in short read mapping. It is all like stick-shift driving in San Francisco. In other words = running this tool with default parameters will probably not give you meaningful results. A way to deal with this is to **understand** the parameters by carefully reading the `documentation`__ and experimenting. Fortunately, Galaxy makes experimenting easy.
-
- .. __: http://www.bioinformatics.babraham.ac.uk/projects/bismark/
-
-------
-
-**Input formats**
-
-Bismark accepts files in either Sanger FASTQ format (galaxy type *fastqsanger*), Illumina FASTQ format (galaxy type *fastqillumina*) or FASTA format (galaxy type *fasta*). Use the FASTQ Groomer to prepare your files.
-
-------
-
-**A Note on Built-in Reference Genomes**
-
-The default variant for all genomes is "Full", defined as all primary chromosomes (or scaffolds/contigs) including mitochondrial plus associated unmapped, plasmid, and other segments. When only one version of a genome is available in this tool, it represents the default "Full" variant. Some genomes will have more than one variant available. The "Canonical Male" or sometimes simply "Canonical" variant contains the primary chromosomes for a genome. For example a human "Canonical" variant contains chr1-chr22, chrX, chrY, and chrM. The "Canonical Female" variant contains the primary chromosomes excluding chrY.
-
-------
-
-The final output of Bismark is in SAM format by default.
-
-**Outputs**
-
-The output is in SAM format, and has the following columns::
-
-    Column  Description
-  --------  --------------------------------------------------------
-  1  QNAME  seq-ID
-  2  FLAG   this flag tries to take the strand a bisulfite read 
-            originated from into account 
-            (this is different from ordinary DNA alignment flags!)
-  3  RNAME  chromosome
-  4  POS    start position
-  5  MAPQ   always 255
-  6  CIGAR  extended CIGAR string
-  7  MRNM   Mate Reference sequence NaMe ('=' if same as RNAME)
-  8  MPOS   1-based Mate POSition
-  9  ISIZE  Inferred insert SIZE
-  10 SEQ    query SEQuence on the same strand as the reference
-  11 QUAL   Phred33 scale
-  12 NM-tag edit distance to the reference)
-  13 XX-tag base-by-base mismatches to the reference. 
-            This does not include indels.
-  14 XM-tag methylation call string
-  15 XR-tag read conversion state for the alignment
-  16 XG-tag genome conversion state for the alignment
-  
-
-Each read of paired-end alignments is written out in a separate line in the above format.
-
-
-It looks like this (scroll sideways to see the entire example)::
-
-  QNAME	FLAG	RNAME	POS	MAPQ	CIAGR	MRNM	MPOS	ISIZE	SEQ	QUAL	OPT
-  HWI-EAS91_1_30788AAXX:1:1:1761:343	4	*	0	0	*	*	0	0	AAAAAAANNAAAAAAAAAAAAAAAAAAAAAAAAAAACNNANNGAGTNGNNNNNNNGCTTCCCACAGNNCTGG	hhhhhhh;;hhhhhhhhhhh^hOhhhhghhhfhhhgh;;h;;hhhh;h;;;;;;;hhhhhhghhhh;;Phhh
-  HWI-EAS91_1_30788AAXX:1:1:1578:331	4	*	0	0	*	*	0	0	GTATAGANNAATAAGAAAAAAAAAAATGAAGACTTTCNNANNTCTGNANNNNNNNTCTTTTTTCAGNNGTAG	hhhhhhh;;hhhhhhhhhhhhhhhhhhhhhhhhhhhh;;h;;hhhh;h;;;;;;;hhhhhhhhhhh;;hhVh
-
--------
-
-**Bismark settings**
-
-All of the options have a default value. You can change any of them. If any Bismark function is missing please contact the tool author or your Galaxy admin.
-
-------
-
-**Bismark parameter list**
-
-This is an exhaustive list of Bismark options:
-
-------
-
-**OPTIONS**
-
-
-Input::
-
-  --singles              A comma- or space-separated list of files containing the reads to be aligned (e.g.
-                         lane1.fq,lane2.fq lane3.fq). Reads may be a mix of different lengths. Bismark will
-                         produce one mapping result and one report file per input file.
-
-  -1 mates1              Comma-separated list of files containing the #1 mates (filename usually includes
-                         "_1"), e.g. flyA_1.fq,flyB_1.fq). Sequences specified with this option must
-                         correspond file-for-file and read-for-read with those specified in mates2.
-                         Reads may be a mix of different lengths. Bismark will produce one mapping result
-                         and one report file per paired-end input file pair.
-
-  -2 mates2              Comma-separated list of files containing the #2 mates (filename usually includes
-                         "_2"), e.g. flyA_1.fq,flyB_1.fq). Sequences specified with this option must
-                         correspond file-for-file and read-for-read with those specified in mates1.
-                         Reads may be a mix of different lengths.
-
-  -q/--fastq             The query input files (specified as mate1,mate2 or singles are FASTQ
-                         files (usually having extension .fg or .fastq). This is the default. See also
-                         --solexa-quals.
-
-  -f/--fasta             The query input files (specified as mate1,mate2 or singles are FASTA
-                         files (usually havin extension .fa, .mfa, .fna or similar). All quality values
-                         are assumed to be 40 on the Phred scale.
-
-  -s/--skip INT          Skip (i.e. do not align) the first INT reads or read pairs from the input.
-
-  -u/--upto INT          Only aligns the first INT reads or read pairs from the input. Default: no limit.
-
-  --phred33-quals        FASTQ qualities are ASCII chars equal to the Phred quality plus 33. Default: on.
-
-  --phred64-quals        FASTQ qualities are ASCII chars equal to the Phred quality plus 64. Default: off.
-
-  --solexa-quals         Convert FASTQ qualities from solexa-scaled (which can be negative) to phred-scaled
-                         (which can't). The formula for conversion is: 
-                         phred-qual = 10 * log(1 + 10 ** (solexa-qual/10.0)) / log(10). Used with -q. This
-                         is usually the right option for use with (unconverted) reads emitted by the GA
-                         Pipeline versions prior to 1.3. Works only for Bowtie 1. Default: off.
-
-  --solexa1.3-quals      Same as --phred64-quals. This is usually the right option for use with (unconverted)
-                         reads emitted by GA Pipeline version 1.3 or later. Default: off.
-
-
-Alignment::
-
-  -n/--seedmms INT       The maximum number of mismatches permitted in the "seed", i.e. the first L base pairs
-                         of the read (where L is set with -l/--seedlen). This may be 0, 1, 2 or 3 and the 
-                         default is 1. This option is only available for Bowtie 1 (for Bowtie 2 see -N).
-
-  -l/--seedlen           The "seed length"; i.e., the number of bases of the high quality end of the read to
-                         which the -n ceiling applies. The default is 28. Bowtie (and thus Bismark) is faster for
-                         larger values of -l. This option is only available for Bowtie 1 (for Bowtie 2 see -L).
-
-  -e/--maqerr INT        Maximum permitted total of quality values at all mismatched read positions throughout
-                         the entire alignment, not just in the "seed". The default is 70. Like Maq, bowtie rounds
-                         quality values to the nearest 10 and saturates at 30. This value is not relevant for
-                         Bowtie 2.
-
-  --chunkmbs INT         The number of megabytes of memory a given thread is given to store path descriptors in
-                         --best mode. Best-first search must keep track of many paths at once to ensure it is
-                         always extending the path with the lowest cumulative cost. Bowtie tries to minimize the
-                         memory impact of the descriptors, but they can still grow very large in some cases. If
-                         you receive an error message saying that chunk memory has been exhausted in --best mode,
-                         try adjusting this parameter up to dedicate more memory to the descriptors. This value
-                         is not relevant for Bowtie 2. Default: 512.
-
-  -I/--minins INT        The minimum insert size for valid paired-end alignments. E.g. if -I 60 is specified and
-                         a paired-end alignment consists of two 20-bp alignments in the appropriate orientation
-                         with a 20-bp gap between them, that alignment is considered valid (as long as -X is also
-                         satisfied). A 19-bp gap would not be valid in that case. Default: 0.
-
-  -X/--maxins INT        The maximum insert size for valid paired-end alignments. E.g. if -X 100 is specified and
-                         a paired-end alignment consists of two 20-bp alignments in the proper orientation with a
-                         60-bp gap between them, that alignment is considered valid (as long as -I is also satisfied).
-                         A 61-bp gap would not be valid in that case. Default: 500.
-
-
-
-Output::
-
-  --non_directional      The sequencing library was constructed in a non strand-specific manner, alignments to all four
-                         bisulfite strands will be reported. Default: OFF.
-
-                         (The current Illumina protocol for BS-Seq is directional, in which case the strands complementary
-                         to the original strands are merely theoretical and should not exist in reality. Specifying directional
-                         alignments (which is the default) will only run 2 alignment threads to the original top (OT)
-                         or bottom (OB) strands in parallel and report these alignments. This is the recommended option
-                         for sprand-specific libraries).
-
-  --sam-no-hd            Suppress SAM header lines (starting with @). This might be useful when very large input files are
-                         split up into several smaller files to run concurrently and the output files are to be merged.
-
-  --quiet                Print nothing besides alignments.
-
-  --vanilla              Performs bisulfite mapping with Bowtie 1 and prints the 'old' output (as in Bismark 0.5.X) instead
-                         of SAM format output.
-
-  -un/--unmapped         Write all reads that could not be aligned to a file in the output directory. Written reads will
-                         appear as they did in the input, without any translation of quality values that may have
-                         taken place within Bowtie or Bismark. Paired-end reads will be written to two parallel files with _1
-                         and _2 inserted in their filenames, i.e. _unmapped_reads_1.txt and unmapped_reads_2.txt. Reads
-                         with more than one valid alignment with the same number of lowest mismatches (ambiguous mapping)
-                         are also written to _unmapped_reads.txt unless the option --ambiguous is specified as well.
-
-  --ambiguous            Write all reads which produce more than one valid alignment with the same number of lowest
-                         mismatches or other reads that fail to align uniquely to a file in the output directory.
-                         Written reads will appear as they did in the input, without any of the translation of quality
-                         values that may have taken place within Bowtie or Bismark. Paired-end reads will be written to two
-                         parallel files with _1 and _2 inserted in theit filenames, i.e. _ambiguous_reads_1.txt and
-                         _ambiguous_reads_2.txt. These reads are not written to the file specified with --un.
-
-  -o/--output_dir DIR    Write all output files into this directory. By default the output files will be written into
-                         the same folder as the input file(s). If the specified folder does not exist, Bismark will attempt
-                         to create it first. The path to the output folder can be either relative or absolute.
-
-  --temp_dir DIR          Write temporary files to this directory instead of into the same directory as the input files. If
-                         the specified folder does not exist, Bismark will attempt to create it first. The path to the
-                         temporary folder can be either relative or absolute.
-
-------
-
-Bowtie 2 alignment options::
-
-  -N INT                 Sets the number of mismatches to allowed in a seed alignment during multiseed alignment.
-                         Can be set to 0 or 1. Setting this higher makes alignment slower (often much slower)
-                         but increases sensitivity. Default: 0. This option is only available for Bowtie 2 (for
-                         Bowtie 1 see -n).
-
-  -L INT                   Sets the length of the seed substrings to align during multiseed alignment. Smaller values
-                         make alignment slower but more senstive. Default: the --sensitive preset of Bowtie 2 is
-                         used by default, which sets -L to 20. This option is only available for Bowtie 2 (for
-                         Bowtie 1 see -l).
-
-  --ignore-quals         When calculating a mismatch penalty, always consider the quality value at the mismatched
-                         position to be the highest possible, regardless of the actual value. I.e. input is treated
-                         as though all quality values are high. This is also the default behavior when the input
-                         doesn't specify quality values (e.g. in -f mode). This option is invariable and on by default.
-
-
-Bowtie 2 paired-end options::
-
-  --no-mixed             This option disables Bowtie 2's behavior to try to find alignments for the individual mates if
-                         it cannot find a concordant or discordant alignment for a pair. This option is invariable and
-                         and on by default.
-
-  --no-discordant        Normally, Bowtie 2 looks for discordant alignments if it cannot find any concordant alignments.
-                         A discordant alignment is an alignment where both mates align uniquely, but that does not
-                         satisfy the paired-end constraints (--fr/--rf/--ff, -I, -X). This option disables that behavior
-                         and it is on by default.
-
-
-Bowtie 2 effort options::
-
-  -D INT                 Up to INT consecutive seed extension attempts can "fail" before Bowtie 2 moves on, using
-                         the alignments found so far. A seed extension "fails" if it does not yield a new best or a
-                         new second-best alignment. Default: 15.
-
-  -R INT                 INT is the maximum number of times Bowtie 2 will "re-seed" reads with repetitive seeds.
-                         When "re-seeding," Bowtie 2 simply chooses a new set of reads (same length, same number of
-                         mismatches allowed) at different offsets and searches for more alignments. A read is considered
-                         to have repetitive seeds if the total number of seed hits divided by the number of seeds
-                         that aligned at least once is greater than 300. Default: 2.
-
-
-Bowtie 2 Scoring options::
-
-  --score_min "func"     Sets a function governing the minimum alignment score needed for an alignment to be considered
-                         "valid" (i.e. good enough to report). This is a function of read length. For instance, specifying
-                         L,0,-0.2 sets the minimum-score function f to f(x) = 0 + -0.2 * x, where x is the read length.
-                         See also: setting function options at http://bowtie-bio.sourceforge.net/bowtie2. The default is
-                         L,0,-0.2.
-
-
-Bowtie 2 Reporting options::
-
- --most_valid_alignments INT This used to be the Bowtie 2 parameter -M. As of Bowtie 2 version 2.0.0 beta7 the option -M is
-                         deprecated. It will be removed in subsequent versions. What used to be called -M mode is still the
-                         default mode, but adjusting the -M setting is deprecated.  Use the -D and -R options to adjust the
-                         effort expended to find valid alignments.
-
-                         For reference, this used to be the old (now deprecated) description of -M:
-                         Bowtie 2 searches for at most INT+1 distinct, valid alignments for each read. The search terminates when it
-                         can't find more distinct valid alignments, or when it finds INT+1 distinct alignments, whichever
-                         happens first. Only the best alignment is reported. Information from the other alignments is used to
-                         estimate mapping quality and to set SAM optional fields, such as AS:i and XS:i. Increasing -M makes 
-                         Bowtie 2 slower, but increases the likelihood that it will pick the correct alignment for a read that
-                         aligns many places. For reads that have more than INT+1 distinct, valid alignments, Bowtie 2 does not
-                         guarantee that the alignment reported is the best possible in terms of alignment score. -M is
-                         always used and its default value is set to 10.
 
   </help>
 </tool>