# HG changeset patch
# User saskia-hiltemann
# Date 1445519910 14400
# Node ID e77c9484b2d06563f90b307a3ff2de15f1a3fe4c
Uploaded
diff -r 000000000000 -r e77c9484b2d0 chrprefix.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/chrprefix.sh	Thu Oct 22 09:18:30 2015 -0400
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+inputfile=$1
+col=$2
+addremove=$3
+outputfile=$4
+
+echo "args: $@"
+echo "inputfile: $inputfile"
+echo "column: $column"
+echo "addremove: $addremove"
+echo "outputfile: $outputfile"
+
+#get column number
+column=`expr match "$col" '\([0-9]*\)'`  
+echo "colnumber: $column"
+
+if [ $addremove == "add" ]
+then
+	echo "adding prefix to column $column"
+	awk 'BEGIN{
+		FS="\t"
+		OFS="\t"
+		c="'"$column"'"
+	}{
+		if (index($0,"#")!=1){
+			$c="chr"$c			
+		}
+		print $0
+		
+	}END{}' $inputfile > $outputfile
+
+else	#remove prefix
+	echo "removing prefix from column $column"
+	awk 'BEGIN{
+		FS="\t"
+		OFS="\t"
+		c="'"$column"'"
+	}{
+		if (FNR>1 && index($0,"#")!=1){
+			$c=substr($c,4)			
+		}
+		print $0
+	
+	}END{}' $inputfile > $outputfile
+fi
+
+echo "inputfile: "
+head -5 $inputfile
+
+echo "outputfile: "
+head -5 $outputfile
diff -r 000000000000 -r e77c9484b2d0 chrprefix.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/chrprefix.xml	Thu Oct 22 09:18:30 2015 -0400
@@ -0,0 +1,47 @@
+ 
+
+   add or remove chr prefix from a column 
+  
+