Repository 'barcode_stacks'
hg clone https://toolshed.g2.bx.psu.edu/repos/tiagoantao/barcode_stacks

Changeset 0:5dc02b8a2a57 (2016-04-08)
Commit message:
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
added:
barcode_sort.pl
barcode_sort.xml
tool_dependencies.xml
b
diff -r 000000000000 -r 5dc02b8a2a57 barcode_sort.pl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/barcode_sort.pl Fri Apr 08 11:38:00 2016 -0400
[
b'@@ -0,0 +1,153 @@\n+#!/usr/bin/perl -w\r\n+use strict; use warnings;\r\n+\r\n+my $cut_site = $ARGV[7]; #let the user specify the cut site keyword (e.g. "TGCA" for the SbfI 6 bp cutter)\r\n+\r\n+my $b = $ARGV[6]; #let the user specify barcode length\r\n+my $n = 2;        # set number of nucleotides to expect before the barcode (bestRAD libraries run at U. Oregon have 2bp here)\r\n+my $c = $b + $n;  # set position for start of enzyme cutsite, which occurs after the initial nucleotides plus the barcode\r\n+my $e = 6;        # set length of remaining enzyme cutsite sequence (e.g. 6 for SbfI) -- for other than SbfI, need to change the actual sequence below!!!\r\n+my $e = length($cut_site); #calculate the length of the cut site\r\n+# note this is the length of what\'s left after enzyme digestion, NOT the full length of the enzyme recognition site\r\n+# the program expects all correct forward reads to follow the pattern: $n initial nucleotides, then $b nucleotides of barcode, then $e nucleotides of the cutsite\r\n+\r\n+my $is_resilient;\r\n+\r\n+open (IN, $ARGV[0]);    # read file with barcodes\r\n+my %counts = ();        # make a hash of barcodes that will be searched\r\n+while(<IN>) {           # counts of each barcode can be tracked with this hash, with a few more lines of code below\r\n+    chomp($_);\r\n+    $counts{$_} = 0;\r\n+}\r\n+close IN;\r\n+\r\n+open (IN1, $ARGV[1]);        # read fastq file of raw forward reads\r\n+open (IN2, $ARGV[2]);        # read fastq file of raw reverse reads  -- these must have pairs in identical order\r\n+open (OUT1, ">$ARGV[3]");    # create fastq outfile for flipped forward reads (cutsite end)\r\n+open (OUT2, ">$ARGV[4]");    # create fastq outfile for flipped reverse reads (randomly sheared end)\r\n+my $forward; my $reverse; my $barcode;        # establish string variables for all parts of fastq files\r\n+my $name1; my $name2; my $third1; my $third2; my $qual1; my $qual2;\r\n+\r\n+$is_resilient = $ARGV[5];  # true if is resilient to errors - Brian\'s additions\r\n+\r\n+\r\n+sub strDiffMaxDelta {\r\n+\r\n+    my ( $s1, $s2, $maxDelta ) = @_;\r\n+    my $diffCount = () = ( $s1 ^ $s2 ) =~ /[^\\x00]/g;\r\n+    return $diffCount <= $maxDelta;\r\n+\r\n+}\r\n+\r\n+if ($is_resilient eq "true") {\r\n+\r\n+    my $max_errors = $ARGV[8];\r\n+\r\n+    while($name1 = <IN1>) {        # start reading through the paired fastq input files\r\n+        $name2 = <IN2>;            # read all parts of a single read pair (4 lines in each of the 2 fastq files)\r\n+        $forward = <IN1>;\r\n+        $reverse = <IN2>;\r\n+        $third1 = <IN1>; $third2 = <IN2>; $qual1 = <IN1>; $qual2 = <IN2>;\r\n+        my $which = 0; my $for; my $rev;        # establish variables used below\r\n+\r\n+        if(strDiffMaxDelta(substr($forward, $c, $e), $cut_site, $max_errors)) {            # check for SbfI cutsite in the correct place in forward read\r\n+            if(strDiffMaxDelta(substr($reverse, $c, $e), $cut_site, $max_errors)) {        # check for SbfI cutsite in the correct place in reverse read\r\n+                $for = substr($forward, $n, $b);            # this is where a barcode should be if it\'s in the forward read\r\n+                $rev = substr($reverse, $n, $b);            # this is where a barcode should be if it\'s in the reverse read\r\n+                if(exists $counts{$for} && (exists $counts{$rev}) == 0) {        # if a correct barcode and cutsite are in forward but not reverse read...\r\n+                    $which = 1; $barcode = $for; $counts{$for}++;                # which = 1 means the pair is correctly oriented\r\n+                }\r\n+                elsif((exists $counts{$for}) == 0 && exists $counts{$rev}) {    # if a correct barcode and cutsite are only in the reverse read...\r\n+                    $which = 2; $barcode = $rev; $counts{$rev}++;                # which = 2 means the pair needs to be flipped\r\n+                }\r\n+            }\r\n+            else {                                            # the cutsite is only found in the forward read\r\n+                #$barcode = substr($forward, $n, $b);\r\n+     '..b'OUT1 "$name2$temp1$third2$temp2";\r\n+            print OUT2 "$name1$forward$third1$qual1";\r\n+        }                                                    # if which == 0, nothing is printed out for the pair\r\n+    }\r\n+    close IN1;\r\n+    close IN2;\r\n+    close OUT1;\r\n+    close OUT2;\r\n+\r\n+    foreach my $key (sort keys %counts) {\r\n+        print "$key" . "\\t" . "$counts{$key}\\n";\r\n+    }\r\n+\r\n+}\r\n+\r\n+\r\n+else{ #Paul\'s code\r\n+\r\n+    while($name1 = <IN1>) {        # start reading through the paired fastq input files\r\n+        $name2 = <IN2>;            # read all parts of a single read pair (4 lines in each of the 2 fastq files)\r\n+        $forward = <IN1>;\r\n+        $reverse = <IN2>;\r\n+        $third1 = <IN1>; $third2 = <IN2>; $qual1 = <IN1>; $qual2 = <IN2>;\r\n+\r\n+        my $which = 0; my $for; my $rev;        # establish variables used below\r\n+        if(substr($forward, $c, $e) eq "TGCAGG") {            # check for SbfI cutsite in the correct place in forward read\r\n+            if(substr($reverse, $c, $e) eq "TGCAGG") {        # check for SbfI cutsite in the correct place in reverse read\r\n+                $for = substr($forward, $n, $b);            # this is where a barcode should be if it\'s in the forward read\r\n+                $rev = substr($reverse, $n, $b);            # this is where a barcode should be if it\'s in the reverse read\r\n+                if(exists $counts{$for} && (exists $counts{$rev}) == 0) {        # if a correct barcode and cutsite are in forward but not reverse read...\r\n+                    $which = 1; $barcode = $for; $counts{$for}++;                # which = 1 means the pair is correctly oriented\r\n+                }\r\n+                elsif((exists $counts{$for}) == 0 && exists $counts{$rev}) {    # if a correct barcode and cutsite are only in the reverse read...\r\n+                    $which = 2; $barcode = $rev; $counts{$rev}++;                # which = 2 means the pair needs to be flipped\r\n+                }\r\n+            }\r\n+            else {                                            # the cutsite is only found in the forward read\r\n+                $barcode = substr($forward, $n, $b);\r\n+                if(exists $counts{$barcode}) {$which = 1; $counts{$barcode}++; }    # if a correct barcode is in the forward read, the pair is correctly oriented\r\n+            }\r\n+        }\r\n+        elsif(substr($reverse, $c, $e) eq "TGCAGG") {        # cutsite not in forward read but is in reverse read\r\n+            $barcode = substr($reverse, $n, $b);\r\n+            if(exists $counts{$barcode}) {$which = 2; $counts{$barcode}++; }        # pair needs to be flipped\r\n+        }                                                    # if a cutsite and correct barcode has not been found in either read, which = 0 at this point\r\n+        if($which == 1) {                                    # if the pair is correctly oriented, print out fastq format for the pair\r\n+            my $temp1 = substr($forward, $n);                # trim initial nucleotides off read and quality scores...\r\n+            my $temp2 = substr($qual1, $n);                    # so that output keeps barcode and cutsite but not other nucleotides...\r\n+            print OUT1 "$name1$temp1$third1$temp2";            # and is ready to go into process_radtags\r\n+            print OUT2 "$name2$reverse$third2$qual2";\r\n+        }\r\n+        elsif($which == 2) {                                # if the pair needs to be flipped, print out fastq format for the flipped pair\r\n+            my $temp1 = substr($reverse, $n);\r\n+            my $temp2 = substr($qual2, $n);\r\n+            print OUT1 "$name2$temp1$third2$temp2";\r\n+            print OUT2 "$name1$forward$third1$qual1";\r\n+        }                                                    # if which == 0, nothing is printed out for the pair\r\n+\r\n+\r\n+    }\r\n+    close IN1;\r\n+    close IN2;\r\n+    close OUT1;\r\n+    close OUT2;\r\n+\r\n+    foreach my $key (sort keys %counts) {\r\n+        print "$key" . "\\t" . "$counts{$key}\\n";\r\n+    }\r\n+}\r\n'
b
diff -r 000000000000 -r 5dc02b8a2a57 barcode_sort.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/barcode_sort.xml Fri Apr 08 11:38:00 2016 -0400
b
@@ -0,0 +1,52 @@
+<tool id="barcode_sort_stacks" name="Barcode sorting for Stacks"  version="2.0.2" force_history_refresh="True">
+  <description>Barcode Sorting with Paired-End reads for Stacks</description>
+
+<stdio>
+   <exit_code range="1" level="fatal" description="Error in script execution" />
+</stdio>
+
+<command interpreter="perl">
+
+barcode_sort.pl $barcode $f1 $f2 $barcoded $nonbarcoded true $barcode_length $cut_site $max_errors
+
+</command>
+
+<inputs>
+  <param name="barcode" format="text" type="data" label="Barcode file" />
+  <param name="barcode_length" type="integer" value="6" label="Barcode length" />
+  <param name="f1" type="data" format="fastq" label="First read FASTQ" />
+  <param name="f2" type="data" format="fastq" label="Second read FASTQ" />
+  <param name="cut_site" type="text" value="TGCA" label="Cut site" />
+  <param name="max_errors" type="integer" value="2" label="Maximum number of errors" />
+</inputs>
+<outputs>
+  <data format="fastq" name="barcoded" label="Barcoded sequences"/>
+  <data format="fastq" name="nonbarcoded" label="Non barcoded sequences"/>
+</outputs>
+
+<help>
+
+.. class:: infomark
+
+**What it does**
+
+This program takes 2 input sequence files where the barcode can be on either
+the 1st or 2nd read (but not both) and sorts all barcoded reads into a single
+file and all non-barcoded files into a second file. This separation is needed
+for the STACKs program as it does not handle sequences where the barcode is
+arbitrarily on the 1st or 2nd read.
+
+--------
+
+**Created by:**
+
+Paul Hohenlohe with changes from Brian Hand.
+
+**Integrated by:**
+
+Tiago Antao
+
+
+</help>
+
+</tool>
b
diff -r 000000000000 -r 5dc02b8a2a57 tool_dependencies.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_dependencies.xml Fri Apr 08 11:38:00 2016 -0400
b
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<tool_dependency>
+</tool_dependency>