diff readshifter.pl @ 0:d42f4d78c85e draft

Uploaded
author messersc
date Wed, 17 Dec 2014 10:40:23 -0500
parents
children 243f75d0ed6e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/readshifter.pl	Wed Dec 17 10:40:23 2014 -0500
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+##############################################
+#### Shifts minus strand reads by read length
+#### Perl script		
+#############################################
+
+
+
+use feature qw(say);
+
+
+# ================== 
+# Parsing Arguments
+# ================== 
+
+#initialize to NULL
+my $bed_file = NULL; #bed file
+my $shift_size = NULL; #shift size
+my $read_length = NULL; #read length
+
+#Parse the arguments
+$bed_file = $ARGV[0]; #bed file
+$shift_size = $ARGV[1];	#shift size
+$read_length = $ARGV[2]; #read length
+
+#=======================> DONE! 
+
+
+
+# ========================================
+# Parse the bed file and extend the reads
+# ========================================
+
+#open the file
+open(DATA, $bed_file) || die("Can't open the bed file, probably you gave me the wrong path!");
+
+#loop through the rest of the file line by line (To do: look for a faster way)
+while (<DATA>) {
+    my ($start, $strand) = split(/\t/,$_,2);
+    $strand =~ s/\015?\012?$//;
+
+
+    
+	#plus strand
+	if ($strand eq '+') {
+		#do nothing
+	}
+	#minus strand
+	elsif ($strand eq '-') {
+		$start = $start - $shift_size + $read_length; #difference between $start and $end should be equal to fragment length ($shift_size)
+	}
+	#bad format 
+	else {
+		die("It appears the bed file is not formatted properly. Specifically, I expect to find either + or - in the second column, but I found something else!");	
+	}
+	if ($start >= 0) {
+		#Now write the new line
+		say join "\t", $start, $strand;
+	}
+}
+#=======================> DONE!