1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
#!/usr/bin/perl -w
%databases = (
"embl" => "embl embl embl acc [.]dat\$",
"genbank" => "genbank genbank gb acc [.]seq\$",
"swiss" => "swiss sw sw acc [.]dat\$",
"pir" => "pir pir pir id [.]ref\$",
"swnew" => "swnew swnew sw acc [.]dat\$"
);
foreach $d (sort( keys(%databases))) {
my ($dir, $db,$fmt,$field, $fname) = split (/ /, $databases{$d});
my $srsdb;
print "$d: '$dir' '$db' '$fmt' '$field' '$fname'\n";
opendir(DIR, $dir);
while($file = readdir(DIR)) {
if($file !~ $fname) {next}
print ("\n $file\n");
open(IN, "$dir/$file") || die "Cannot open $dir/$file";
$ac=0;
$allok = 1;
$change=0;
if(-e "newfile") {system "rm newfile;touch newfile";}
if($fmt eq "pir") {
if(-e "newfile2") {system "rm newfile2;touch newfile2";}
}
if($file eq "est.dat") {$srsdb = $db."est"}
elsif($file eq "condiv.dat") {$srsdb = $db."con"}
elsif($file eq "wgs.dat") {$srsdb = $db."wgs"}
else {$srsdb = $db}
while (<IN>) {
$id="";
if($fmt eq "embl") {
if(/^AC +([^ ;\n]+)/) {
if(!$ac++){$id = $1}}
else {$ac=0}
}
elsif($fmt eq "sw") {
if(/^AC +([^ ;\n]+)/) {if(!$ac++){$id = $1}}
else {$ac=0}
}
elsif($fmt eq "gb") {
if(/^ACCESSION +([^ ;\n]+)/) {$id = $1}
}
elsif($fmt eq "pir") {
if(/^>..;([^ ;\n]+)/) {$id = $1}
}
if($id eq "") {next}
print " id:$id";
$istatus = system "EMBOSSRC=./dbfetch/ ;export EMBOSSRC ;EMBOSS_RCHOME=N ;export EMBOSS_RCHOME ;entret -auto t$db\-$field:$id x.x";
$jstatus = system "EMBOSSRC=./dbfetch ;export EMBOSSRC ;EMBOSS_RCHOME=N ;export EMBOSS_RCHOME ;entret -auto srs$srsdb\-$field:$id y.y";
if(!$jstatus && $fmt eq "pir") {
$file2 = $file;
$file2 =~ s/[.]ref/.seq/g;
open (Y, "y.y");
open (W, ">w.w");
my $pirseq = "";
my $pircount = 0;
my $pirlines = 0;
my $isseq = 0;
while(<Y>) {
print W;
if(/^>/) {$pircount++;$pirlines=0}
else {$pirlines++}
if($pircount == 2){
if($pirlines < 2) {next}
$isseq = 1;
s/\s//g;
}
$pirseq .= $_;
}
if($isseq) {$pirseq .= "\n"}
close Y;
close W;
open (Y, ">y.y");
print Y $pirseq;
close Y;
}
system "diff x.x y.y > z.z";
if($istatus) {
print " current failed $istatus\n";
$allok = 0;
}
elsif($jstatus) {
print " latest failed $jstatus\n";
$allok = 0;
}
elsif(-s "z.z") {
printf " diff %d %d %d\n", (-s "z.z"), (-s "x.x"), (-s "y.y");
$change=1;
if($fmt eq "pir") {
open (Z, "z.z");
while(<Z>) {print}
close Z;
open (REF, ">>newfile");
open (SEQ, ">>newfile2");
open (Y, "y.y");
$ref = 0;
$seq=0;
@pirseq = ();
while(<Y>) {
if(/^>/) {
$ref++;
if($ref == 1) {$saveref = $_}
if($ref == 2) {$_ = $saveref}
}
if($ref < 2) {
print REF;
}
else {
$seq++;
if($seq <= 2) {
print SEQ;
}
else {
chomp;
push @pirseq, split (/\s+/, $_);
}
}
}
foreach $p (@pirseq) {
# if($j++ == 8) {
# $j=0;
# print SEQ "\n";
# }
print SEQ "$p";
}
print SEQ "\n";
close REF;
close SEQ;
close Y;
}
else {
system "cat y.y >> newfile";
}
}
else {
print " OK\n";
if($fmt eq "pir") {
open (REF, ">>newfile");
open (SEQ, ">>newfile2");
open (Y, "w.w");
$ref = 0;
$seq=0;
@pirseq = ();
while(<Y>) {
if(/^>/) {
$ref++;
if($ref == 1) {$saveref = $_}
if($ref == 2) {$_ = $saveref}
}
if($ref < 2) {
print REF;
}
else {
$seq++;
if($seq <= 2) {
print SEQ;
}
else {
push @pirseq, split (/\s+/, $_);
}
}
}
foreach $p (@pirseq) {
print SEQ "$p";
}
print SEQ "\n";
close REF;
close SEQ;
close Y;
}
else {
system "cat y.y >> newfile";
}
}
}
close(IN);
if($allok && $change) {
$replace++;
printf "REPLACE $dir/$file %d %d\n", (-s "$dir/$file"), (-s "newfile");
system "cp newfile $dir/$file";
if($fmt eq "pir") {
printf "REPLACE $dir/$file2 %d %d\n", (-s "$dir/$file2"), (-s "newfile2");
system "cp newfile2 $dir/$file2";
}
}
elsif($allok) {
system "diff $dir/$file newfile > z.z";
if(-s "z.z") {
printf "KEEP but size changed %d %d %d\n",
(-s "$db/$file"), (-s "newfile"), (-s "z.z");
}
else {
print "KEEP unchanged\n";
}
if($fmt eq "pir") {
system "diff $dir/$file2 newfile2 > z.z";
if(-s "z.z") {
$replace++;
printf "KEEP but REF size changed %d %d %d\n",
(-s "$db/$file"), (-s "newfile"), (-s "z.z");
}
}
}
else {
print "PROBLEM somewhere\n";
}
}
}
if($replace) {
print "Replaced $replace databases\n";
}
else {
print "ALL UNCHANGED\n";
}
|