-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathchangeClasses.pl
117 lines (94 loc) · 2.74 KB
/
changeClasses.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl
=head1 DESCRIPTION
changeClasses.pl -- Edit the *.cls file to change the class numbers for a given list of contig names.
=head1 USAGE
perl changeClasses.pl -cls esom.cls -names esom.names -list contigs.list -o output.cls
=head2 Options
-cls <CHARACTERS> *.cls file produced by the esomWrapper.pl script
-names <CHARACTERS> *.names file produced by the esomWrapper.pl script
-list <CHARACTERS> list of contig names(replace all special chracters with '_')
-tag <CHARACTERS> new class name/number to be assigned.[default=next available class number]
-out <CHARACTERS> new class file. default: esom_edited.cls
-version -v <BOOLEAN> version of the current script
-help -h <BOOLEAN> This message.
=head1 Author
Sunit Jain, (Fri Dec 6 08:59:27 EST 2013)
sunitj [AT] umich [DOT] edu
=head1 License
This script is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
=head1 Disclaimer
This script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
=cut
use strict;
use Getopt::Long;
use File::Basename;
my($cls, $names, $list, $tag, $out);
my $help;
my $version="changeClasses.pl\tv0.1.1";
GetOptions(
'c|cls:s'=>\$cls,
'n|names:s'=>\$names,
'l|list:s'=>\$list,
'tag:s'=>\$tag,
'o|out:s'=>\$out,
'v|version'=>sub{print $version."\n"; exit;},
'h|help'=>sub{system("perldoc $0 \| cat"); exit;},
);
print "\# $version\n";
die "Missing required input files. See '$0 -h' for help on how to use the script\n" if((! $cls)||(! $names)||(! $list));
$out=fileparse($cls,".cls")."_edited.cls" if (! $out);
open(LIST, "<".$list)||die $!;
my %index;
while(my $line=<LIST>){
$line=strip($line);
$index{lc($line)}++;
}
close LIST;
open(NAMES, "<".$names)||die $!;
my %num_name;
while(my $line=<NAMES>){
$line=strip($line);
next if ($line=~ /^%/);
my($number, $window, $name)=split(/\t/, $line);
next unless ($index{lc($name)});
$num_name{$number}++;
}
close NAMES;
open(CLS, "<".$cls)|| die $!;
open(NCLS, ">".$out)|| die $!;
my $num_classes=-1;
while(my $line=<CLS>){
$line=strip($line);
if ($line=~ /^%/){
print NCLS $line."\n";
$num_classes++;
}
else{
if($.==($num_classes+2)){
print NCLS "%".($num_classes)."\t".
($tag ? $tag : $num_classes)."\t".
getRandomColor()."\n";
}
my($number, $class)=split(/\t/, $line);
if($num_name{$number}){
print NCLS $number."\t".$num_classes."\n";
}
else{
print NCLS $line."\n";
}
}
}
close CLS;
close NCLS;
sub strip{
my $data=shift;
chomp $data;
$data=~ m/^\s+/;
$data=~ m/\s+$/;
return $data;
}
sub getRandomColor {
my ($r, $g, $b) = map { int rand 256 } 1 .. 3;
my $color= join("\t", $r, $g, $b);
return ($color);
}