diff SMART/bacteriaRegulatoryRegion_Detection/sortGff.pl @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SMART/bacteriaRegulatoryRegion_Detection/sortGff.pl	Mon Apr 29 03:20:15 2013 -0400
@@ -0,0 +1,88 @@
+#!/usr/bin/perl -w
+###
+# But : ajout ou modif de couleur d'un gff
+# 
+# Entrees : fichier gff
+#
+# Sortie : gff affiche a l'ecran
+#
+###------------------------------------------------------
+
+#!/usr/bin/perl -w                                                                                                                                                     
+              
+use vars qw($USAGE);                      
+use strict;                               
+
+=head1 NAME
+
+sortGff.pl - sort a gff file
+
+=head1 SYNOPSIS
+
+% sortGff.pl -i file.gff [-h] 
+
+=head1 DESCRIPTION
+This script will sort a gff file (only when inversion of two successive lines).
+
+    -i|--input fileName  gff input file name
+    -o|--output fileName  gff3 output file name
+   [-h|--help]           help mode then die                              
+
+=head1 AUTHOR - Claire Toffano-Nioche - mar.11
+
+=cut
+
+#-----------------------
+my ($fileName, $colourGff, $outFileName) = ("", "", "sortOut.gff3") ;
+   # command line check
+    foreach my $num (0 .. $#ARGV) {
+        SWITCH: for ($ARGV[$num]) {
+        /--input|-i/ && do { 
+		$fileName=$ARGV[$num+1]; 
+		open ( fichierGff, "< $fileName" ) or die "Can't open gff file: \"$fileName\"\n" ; 
+		last };
+#		/--output|-o/ && do { 
+#		$outFileName=$ARGV[$num+1]; 
+#		last };
+        /--help|-h/ && do { exec("pod2text $0\n") ; die };
+        }
+    }
+    # informations retrieval
+#    open(OUT,">$outFileName") or die "Error can't $outFileName open for output. $!\n";
+    my @lines = <fichierGff> ; 
+    close fichierGff ;
+    # treatment
+	#print "gff file read ; number of lines : $#lines\n";
+    my $previous = 0;
+    my $i = 0;
+	#print "$#lines\n" ;
+    while ($i <= $#lines) {
+	my @infos = split('\t', $lines[$i]) ;
+	#print "info[3]:$infos[3]; prv:$previous!\n";
+	if ($infos[3] < $previous) {
+	    &exchange($i, $infos[3]) ;
+	    $previous=$infos[3] ; 
+	    $i--;
+	} 
+	$previous=$infos[3];
+	$i++;	
+    }
+    for (my $i=0 ; $i <= $#lines ; $i++) {
+#	print OUT $lines[$i] ;	
+	print $lines[$i] ;
+    }
+#close OUT ;
+exit(0);
+#-----------------------
+sub exchange {
+	my ($index, $position) = @_ ;
+	my @info_col = split("\t", $lines[$index-1]) ;
+	if ($info_col[3] > $position) {
+		#print "$lines[$index]";
+		my $line_to_push = $lines[$index-1] ;
+		$lines[$index-1] = $lines[$index] ;
+		$lines[$index] = $line_to_push ;
+	} else {
+		print "TODO : push > one line\n" ;
+	}
+}