[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.2 - (view) (download) (as text)

1 : olson 1.1 #
2 : olson 1.2 # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :    
18 :     #
19 : olson 1.1 # Scan an NR, replacing the existing IDs with the corresponding principal
20 :     # synonym id's from the given ID map file.
21 :     #
22 :    
23 :     use strict;
24 :    
25 :     my $usage = "assign_synonym_ids_to_nr NR id.map NewNR";
26 :    
27 :     @ARGV == 3 or die $usage;
28 :    
29 :     my $old_nr = shift;
30 :     my $id_map = shift;
31 :     my $new_nr = shift;
32 :    
33 :     open(ONR, "<$old_nr") or die "Cannot open $old_nr for reading: $!\n";
34 :     open(MAP, "<$id_map") or die "Cannot open $id_map for reading: $!\n";
35 :     open(NNR, ">$new_nr") or die "Cannot open $new_nr for writing: $!\n";
36 :    
37 :     my %map;
38 :    
39 :     while (<MAP>)
40 :     {
41 :     chomp;
42 :     my($k,$v) = split(/\t/);
43 :     $map{$k} = $v;
44 :     }
45 :    
46 :     close(MAP);
47 :    
48 :     print "Read map\n";
49 :    
50 :     local $/ = "\n>";
51 :    
52 :     my($id, $rest, $seq);
53 :     while (<ONR>)
54 :     {
55 :     chomp;
56 :     if (($id, $rest, $seq) = /^>?(\S+)([^\n]*)\n(.*)/s)
57 :     {
58 :     my $new = $map{$id};
59 :    
60 :     if (!defined($new))
61 :     {
62 :     warn "No mapped id found for $id\n";
63 :     $new = $id;
64 :     }
65 :     print NNR ">$new$rest\n$seq\n";
66 :     }
67 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3