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

Annotation of /FigKernelScripts/load_sims.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : olson 1.9 #
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 : overbeek 1.1
19 :    
20 :     # -*- perl -*-
21 :    
22 :     use FIG;
23 : overbeek 1.6 use strict;
24 :    
25 :     use Cwd 'abs_path';
26 :    
27 : overbeek 1.1 my $fig = new FIG;
28 :    
29 :     use DBrtns;
30 :    
31 : olson 1.10 my $usage = "usage: load_sims [-clear] SimsDir";
32 : overbeek 1.6
33 :     my $dir;
34 :    
35 : olson 1.10 my $drop_tables = 0;
36 :    
37 :     if ($ARGV[0] eq '-clear')
38 :     {
39 :     $drop_tables = 1;
40 :     shift @ARGV;
41 :     }
42 :    
43 : overbeek 1.2 ($dir = shift @ARGV)
44 :     || die $usage;
45 : overbeek 1.1
46 : overbeek 1.6 $dir = abs_path($dir);
47 :    
48 :     -d $dir or die "Sims dir $dir does not exist\n";
49 :    
50 :     my $dbf = $fig->db_handle();
51 : overbeek 1.1
52 : overbeek 1.6 my($mediumint, $pscType);
53 : overbeek 1.5 if ($dbf->{_dbms} eq 'mysql')
54 :     {
55 :     $mediumint = "mediumint";
56 : overbeek 1.6 $pscType = "real";
57 : overbeek 1.5 }
58 :     else
59 :     {
60 :     $mediumint = "integer";
61 : overbeek 1.6 $pscType = "float8";
62 : overbeek 1.5 }
63 :    
64 : olson 1.7
65 :     opendir(SIMS,$dir) || die "$dir does not exist";
66 : olson 1.8 my @files = map { "$dir/$_" } grep { $_ !~ /^\./ } readdir(SIMS);
67 : olson 1.7
68 :     closedir(SIMS);
69 :    
70 :     my($row_size, $max_rows) = $dbf->estimate_table_size(\@files);
71 :    
72 : olson 1.10 if ($drop_tables)
73 :     {
74 :     $dbf->drop_table( tbl => "condensed_sims" );
75 :     $dbf->create_table( tbl => 'condensed_sims',
76 :     flds => "g1 smallint, p1 $mediumint, g2 smallint, p2 $mediumint, iden real, psc $pscType, paraN INTEGER",
77 :     type => 'InnoDB'
78 :     );
79 :     }
80 :    
81 :     my $tmp_file = "$FIG_Config::temp/load_sim_tmp.$$";
82 : olson 1.7
83 : olson 1.8 foreach my $file (@files)
84 : overbeek 1.1 {
85 : olson 1.10 my $load_file = $file;
86 :    
87 : olson 1.8 if (-s $file)
88 : overbeek 1.3 {
89 : olson 1.10 #
90 :     # Determine if we need to map.
91 :     #
92 :    
93 :     open(S, "<$file") or die "Cannot open $file: $!\n";
94 :     $_ = <S>;
95 :    
96 :     if (/^fig/)
97 :     {
98 :     print "Mapping $file\n";
99 :    
100 :     open(TMP, ">$tmp_file") or die "Cannot open $tmp_file for writing: $!\n";
101 :    
102 :     while (defined($_))
103 :     {
104 :     chomp;
105 :     my($p1, $p2, @rest) = split(/\t/);
106 :     print TMP join("\t", $fig->map_peg_to_ids($p1), $fig->map_peg_to_ids($p2), @rest), "\n";
107 :    
108 :     $_ = <S>;
109 :     }
110 :     close(TMP);
111 :     close(S);
112 :    
113 :     $load_file = $tmp_file;
114 :     }
115 :    
116 :     print "Loading $load_file\n";
117 :    
118 : overbeek 1.3 $dbf->load_table( tbl => "condensed_sims",
119 : olson 1.10 file => $load_file );
120 : overbeek 1.3 }
121 : overbeek 1.1 }
122 : olson 1.10
123 :     if ($drop_tables)
124 :     {
125 :     print "Creating index\n";
126 :     $dbf->create_index( idx => "condensed_sims_ix",
127 :     tbl => "condensed_sims",
128 :     type => "btree",
129 :     flds => "g1, p1" );
130 :     }
131 : overbeek 1.1
132 :     $dbf->vacuum_it("condensed_sims");
133 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3