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

Annotation of /FigKernelScripts/assign_synonym_ids_to_nr.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : olson 1.1 #
2 :     # Scan an NR, replacing the existing IDs with the corresponding principal
3 :     # synonym id's from the given ID map file.
4 :     #
5 :    
6 :     use strict;
7 :    
8 :     my $usage = "assign_synonym_ids_to_nr NR id.map NewNR";
9 :    
10 :     @ARGV == 3 or die $usage;
11 :    
12 :     my $old_nr = shift;
13 :     my $id_map = shift;
14 :     my $new_nr = shift;
15 :    
16 :     open(ONR, "<$old_nr") or die "Cannot open $old_nr for reading: $!\n";
17 :     open(MAP, "<$id_map") or die "Cannot open $id_map for reading: $!\n";
18 :     open(NNR, ">$new_nr") or die "Cannot open $new_nr for writing: $!\n";
19 :    
20 :     my %map;
21 :    
22 :     while (<MAP>)
23 :     {
24 :     chomp;
25 :     my($k,$v) = split(/\t/);
26 :     $map{$k} = $v;
27 :     }
28 :    
29 :     close(MAP);
30 :    
31 :     print "Read map\n";
32 :    
33 :     local $/ = "\n>";
34 :    
35 :     my($id, $rest, $seq);
36 :     while (<ONR>)
37 :     {
38 :     chomp;
39 :     if (($id, $rest, $seq) = /^>?(\S+)([^\n]*)\n(.*)/s)
40 :     {
41 :     my $new = $map{$id};
42 :    
43 :     if (!defined($new))
44 :     {
45 :     warn "No mapped id found for $id\n";
46 :     $new = $id;
47 :     }
48 :     print NNR ">$new$rest\n$seq\n";
49 :     }
50 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3