[Bio] / FigKernelScripts / rewrite_peg_syns.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/rewrite_peg_syns.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : redwards 1.1 #__perl--
2 :    
3 :     # rewrite and merge peg.synonyms file with a partial file. For example, after adding a genome, you might run sims_after_adding_genome which then creates a partial sims file
4 :     # this will take that file, and the existing peg.synonyms file and merge them.
5 :     #
6 :     # Rob Edwards
7 :     # Nov 11, 2009
8 :    
9 :     use strict;
10 :     use Getopt::Std;
11 :     my %opts;
12 :     getopts('n:o:d:', \%opts);
13 :     unless ($opts{n} && $opts{o} && $opts{d}) {
14 :     die <<EOF;
15 :     $0
16 :     -n new peg synonyms that will be appended to old ones
17 :     -o directory where old peg synonyms file is
18 :     -d directory where new peg synonyms should end up
19 :     EOF
20 :     }
21 :    
22 :     unless (-e "$opts{o}/peg.synonyms") {die "OLD FILE: $opts{o}/peg.synonyms does not exist!"}
23 :     unless (-e "$opts{n}") {die "NEW FILE: $opts{n} does not exist!"}
24 :     if (-e "$opts{d}/peg.synonyms") {die "Cowardly won't overwrite $opts{d}/peg.synonyms"}
25 :    
26 :     open(IN, $opts{n}) || die "can't open $opts{n}";
27 :     my $line;
28 :     while (<IN>) {
29 :     chomp;
30 :     my ($md5, $matches)=split /\t/;
31 :     foreach my $tple (split /\;/, $matches) {
32 :     my ($peg, $len)=split /\,/, $tple;
33 :     $line->{$md5}->{$peg}=$len;
34 :     }
35 :     }
36 :     close IN;
37 :    
38 :     open(IN, "$opts{o}/peg.synonyms") || die "can't open $opts{o}/peg.synonyms";
39 :     open(OUT, ">$opts{d}/peg.synonyms") || die "can't write to $opts{d}/peg.synonyms";
40 :     while (<IN>) {
41 :     my ($md5, $matches)=split /\t/;
42 :     if ($line->{$md5}) {
43 :     chomp($matches);
44 :     foreach my $tple (split /\;/, $matches) {
45 :     my ($peg, $len)=split /\,/, $tple;
46 :     $line->{$md5}->{$peg}=$len;
47 :     }
48 :     }
49 :     else {
50 :     print OUT;
51 :     }
52 :     }
53 :     foreach my $md5 (keys %$line) {
54 :     print OUT "$md5\t", join(";", map {$_="$_,".$line->{$md5}->{$_}} keys %{$line->{$md5}}), "\n";
55 :     }
56 :     close IN;
57 :     close OUT;
58 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3