Parent Directory
|
Revision Log
Revision 1.3 - (view) (download) (as text)
1 : | efrank | 1.1 | # -*- perl -*- |
2 : | |||
3 : | use strict; | ||
4 : | use FIG; | ||
5 : | my $fig = new FIG; | ||
6 : | |||
7 : | use DBrtns; | ||
8 : | |||
9 : | |||
10 : | my $temp_dir = "$FIG_Config::temp"; | ||
11 : | my($organisms_dir) = "$FIG_Config::organisms"; | ||
12 : | |||
13 : | my($genome,@types,$type,$id,$loc,@aliases,$aliases,$contig); | ||
14 : | |||
15 : | # usage: load_features [G1 G2 G3 ... ] | ||
16 : | |||
17 : | open(REL,">$temp_dir/tmpfeat$$") || die "could not open $temp_dir/tmpfeat$$"; | ||
18 : | |||
19 : | my $dbf = $fig->{_dbf}; | ||
20 : | |||
21 : | |||
22 : | |||
23 : | my @genomes; | ||
24 : | if (@ARGV == 0) | ||
25 : | { | ||
26 : | $dbf->drop_table( tbl => "features" ); | ||
27 : | if ($FIG_Config::dbms eq "Pg") | ||
28 : | { | ||
29 : | $dbf->create_table( tbl => "features", | ||
30 : | flds => "id varchar(32) UNIQUE NOT NULL, type varchar(16),genome varchar(16)," . | ||
31 : | "location varchar(5000)," . | ||
32 : | "contig varchar(96), minloc INTEGER, maxloc INTEGER," . | ||
33 : | "aliases TEXT, PRIMARY KEY ( id )" | ||
34 : | ); | ||
35 : | } | ||
36 : | elsif ($FIG_Config::dbms eq "mysql") | ||
37 : | { | ||
38 : | $dbf->create_table( tbl => "features", | ||
39 : | flds => "id varchar(32) UNIQUE NOT NULL, type varchar(16),genome varchar(16)," . | ||
40 : | "location TEXT," . | ||
41 : | "contig varchar(96), minloc INTEGER, maxloc INTEGER," . | ||
42 : | "aliases TEXT, PRIMARY KEY ( id )" | ||
43 : | ); | ||
44 : | } | ||
45 : | |||
46 : | $dbf->create_index( idx => "features_org_ix", | ||
47 : | tbl => "features", | ||
48 : | type => "btree", | ||
49 : | flds => "genome" ); | ||
50 : | $dbf->create_index( idx => "features_type_ix", | ||
51 : | type => "btree", | ||
52 : | tbl => "features", | ||
53 : | flds => "type" ); | ||
54 : | $dbf->create_index( idx => "features_beg_ix", | ||
55 : | type => "btree", | ||
56 : | tbl => "features", | ||
57 : | flds => "genome,contig,minloc" ); | ||
58 : | |||
59 : | @genomes = $fig->genomes; | ||
60 : | } | ||
61 : | else | ||
62 : | { | ||
63 : | @genomes = @ARGV; | ||
64 : | overbeek | 1.2 | foreach $genome (@genomes) |
65 : | { | ||
66 : | $dbf->SQL("DELETE FROM features WHERE ( genome = \'$genome\' )"); | ||
67 : | } | ||
68 : | efrank | 1.1 | } |
69 : | |||
70 : | foreach $genome (@genomes) | ||
71 : | { | ||
72 : | opendir(FEAT,"$organisms_dir/$genome/Features") | ||
73 : | || die "could not open $genome/Features"; | ||
74 : | @types = grep { $_ =~ /^[a-zA-Z]+$/ } readdir(FEAT); | ||
75 : | closedir(FEAT); | ||
76 : | |||
77 : | foreach $type (@types) | ||
78 : | { | ||
79 : | if ((-s "$organisms_dir/$genome/Features/$type/tbl") && | ||
80 : | open(TBL,"<$organisms_dir/$genome/Features/$type/tbl")) | ||
81 : | { | ||
82 : | # print STDERR "loading $genome/Features/$type/tbl\n"; | ||
83 : | while (defined($_ = <TBL>)) | ||
84 : | { | ||
85 : | chop; | ||
86 : | ($id,$loc,@aliases) = split(/\t/,$_); | ||
87 : | if ($id) | ||
88 : | { | ||
89 : | my($minloc,$maxloc); | ||
90 : | if ($loc) | ||
91 : | { | ||
92 : | $loc =~ s/\s+$//; | ||
93 : | ($contig,$minloc,$maxloc) = &FIG::boundaries_of($loc); | ||
94 : | if ($minloc && $maxloc) | ||
95 : | { | ||
96 : | ($minloc < $maxloc) || (($minloc,$maxloc) = ($maxloc,$minloc)); | ||
97 : | } | ||
98 : | } | ||
99 : | |||
100 : | if (! $contig) | ||
101 : | { | ||
102 : | $loc = $contig = $minloc = $maxloc = ""; | ||
103 : | } | ||
104 : | |||
105 : | if (@aliases > 0) | ||
106 : | { | ||
107 : | $aliases = join(",",grep(/\S/,@aliases)); | ||
108 : | } | ||
109 : | else | ||
110 : | { | ||
111 : | $aliases = ""; | ||
112 : | } | ||
113 : | $minloc = (! $minloc) ? 0 : $minloc; | ||
114 : | $maxloc = (! $maxloc) ? 0 : $maxloc; | ||
115 : | overbeek | 1.3 | if ((length($loc) < 5000) && (length($contig) < 96) && (length($id) < 32)) |
116 : | { | ||
117 : | print REL "$id\t$type\t$genome\t$loc\t$contig\t$minloc\t$maxloc\t$aliases\n"; | ||
118 : | } | ||
119 : | efrank | 1.1 | } |
120 : | } | ||
121 : | close(TBL); | ||
122 : | } | ||
123 : | } | ||
124 : | } | ||
125 : | close(REL); | ||
126 : | |||
127 : | $dbf->load_table( tbl => "features", | ||
128 : | file => "$temp_dir/tmpfeat$$" ); | ||
129 : | |||
130 : | if (@ARGV == 0) { $dbf->vacuum_it("features") } | ||
131 : | unlink("$temp_dir/tmpfeat$$"); |
MCS Webmaster | ViewVC Help |
Powered by ViewVC 1.0.3 |