Mercurial > repos > yufei-luo > s_mart
comparison SMART/bacteriaRegulatoryRegion_Detection/sortGff.pl @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:b0e8584489e6 | 18:94ab73e8a190 |
---|---|
1 #!/usr/bin/perl -w | |
2 ### | |
3 # But : ajout ou modif de couleur d'un gff | |
4 # | |
5 # Entrees : fichier gff | |
6 # | |
7 # Sortie : gff affiche a l'ecran | |
8 # | |
9 ###------------------------------------------------------ | |
10 | |
11 #!/usr/bin/perl -w | |
12 | |
13 use vars qw($USAGE); | |
14 use strict; | |
15 | |
16 =head1 NAME | |
17 | |
18 sortGff.pl - sort a gff file | |
19 | |
20 =head1 SYNOPSIS | |
21 | |
22 % sortGff.pl -i file.gff [-h] | |
23 | |
24 =head1 DESCRIPTION | |
25 This script will sort a gff file (only when inversion of two successive lines). | |
26 | |
27 -i|--input fileName gff input file name | |
28 -o|--output fileName gff3 output file name | |
29 [-h|--help] help mode then die | |
30 | |
31 =head1 AUTHOR - Claire Toffano-Nioche - mar.11 | |
32 | |
33 =cut | |
34 | |
35 #----------------------- | |
36 my ($fileName, $colourGff, $outFileName) = ("", "", "sortOut.gff3") ; | |
37 # command line check | |
38 foreach my $num (0 .. $#ARGV) { | |
39 SWITCH: for ($ARGV[$num]) { | |
40 /--input|-i/ && do { | |
41 $fileName=$ARGV[$num+1]; | |
42 open ( fichierGff, "< $fileName" ) or die "Can't open gff file: \"$fileName\"\n" ; | |
43 last }; | |
44 # /--output|-o/ && do { | |
45 # $outFileName=$ARGV[$num+1]; | |
46 # last }; | |
47 /--help|-h/ && do { exec("pod2text $0\n") ; die }; | |
48 } | |
49 } | |
50 # informations retrieval | |
51 # open(OUT,">$outFileName") or die "Error can't $outFileName open for output. $!\n"; | |
52 my @lines = <fichierGff> ; | |
53 close fichierGff ; | |
54 # treatment | |
55 #print "gff file read ; number of lines : $#lines\n"; | |
56 my $previous = 0; | |
57 my $i = 0; | |
58 #print "$#lines\n" ; | |
59 while ($i <= $#lines) { | |
60 my @infos = split('\t', $lines[$i]) ; | |
61 #print "info[3]:$infos[3]; prv:$previous!\n"; | |
62 if ($infos[3] < $previous) { | |
63 &exchange($i, $infos[3]) ; | |
64 $previous=$infos[3] ; | |
65 $i--; | |
66 } | |
67 $previous=$infos[3]; | |
68 $i++; | |
69 } | |
70 for (my $i=0 ; $i <= $#lines ; $i++) { | |
71 # print OUT $lines[$i] ; | |
72 print $lines[$i] ; | |
73 } | |
74 #close OUT ; | |
75 exit(0); | |
76 #----------------------- | |
77 sub exchange { | |
78 my ($index, $position) = @_ ; | |
79 my @info_col = split("\t", $lines[$index-1]) ; | |
80 if ($info_col[3] > $position) { | |
81 #print "$lines[$index]"; | |
82 my $line_to_push = $lines[$index-1] ; | |
83 $lines[$index-1] = $lines[$index] ; | |
84 $lines[$index] = $line_to_push ; | |
85 } else { | |
86 print "TODO : push > one line\n" ; | |
87 } | |
88 } |