| 1 |
/* File: update.c |
| 2 |
* Author: Jean Thierry-Mieg ([email protected]) |
| 3 |
* Copyright (C) J Thierry-Mieg and R Durbin, 1991 |
| 4 |
* ------------------------------------------------------------------- |
| 5 |
* Acedb is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU General Public License |
| 7 |
* as published by the Free Software Foundation; either version 2 |
| 8 |
* of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 |
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt |
| 19 |
* ------------------------------------------------------------------- |
| 20 |
* This file is part of the ACEDB genome database package, written by |
| 21 |
* Richard Durbin (MRC LMB, UK) [email protected], and |
| 22 |
* Jean Thierry-Mieg (CRBM du CNRS, France) [email protected] |
| 23 |
* |
| 24 |
* Description: Parses the official acedb updates. |
| 25 |
* Exported functions: |
| 26 |
* updateData |
| 27 |
* updateDoAction |
| 28 |
* HISTORY: |
| 29 |
* Last edited: Nov 4 11:59 1999 (fw) |
| 30 |
* * Jan 20 10:16 1992 (mieg): interactive access to alias, |
| 31 |
should be done differently really. |
| 32 |
* Created: Fri Oct 25 13:35:14 1991 (mieg) |
| 33 |
*------------------------------------------------------------------- |
| 34 |
*/ |
| 35 |
|
| 36 |
/*$Id: update.c,v 1.38 2000/02/07 11:07:52 srk Exp $ */ |
| 37 |
|
| 38 |
#include "acedb.h" |
| 39 |
#include "aceio.h" |
| 40 |
#include "session.h" |
| 41 |
#include "parse.h" |
| 42 |
#include "model.h" |
| 43 |
#include "lex.h" /* for lexAlphaMakeAll */ |
| 44 |
#include "bs.h" /* for global BOOL flags */ |
| 45 |
|
| 46 |
#include "display.h" |
| 47 |
#include "main.h" /* pickDraw */ |
| 48 |
#include "vmap.h" /* for vMapMakeAll() */ |
| 49 |
#include "dbpath.h" |
| 50 |
|
| 51 |
/*************************************************************/ |
| 52 |
|
| 53 |
static int lineBox ; |
| 54 |
|
| 55 |
/*************************************************************/ |
| 56 |
/*************************************************************/ |
| 57 |
|
| 58 |
static Graph updateGraph = 0; |
| 59 |
static int line = 3 ; |
| 60 |
static void upMessage(char *cp) |
| 61 |
{ |
| 62 |
Graph old = graphActive() ; |
| 63 |
if(graphActivate(updateGraph)) |
| 64 |
{ graphText (cp, 1, line++) ; |
| 65 |
graphTextBounds (80,line+2) ; |
| 66 |
graphBoxDraw (0,-1,-1) ; |
| 67 |
} |
| 68 |
graphActivate(old) ; |
| 69 |
} |
| 70 |
|
| 71 |
/******************************************/ |
| 72 |
|
| 73 |
static void updateAlign (void) |
| 74 |
{ |
| 75 |
extern void gMapMakeAll(void) ; |
| 76 |
extern void pMapMakeAll(void) ; |
| 77 |
extern void cMapMakeAll(void) ; |
| 78 |
|
| 79 |
upMessage ("Making physical maps - a few minutes") ; |
| 80 |
pMapMakeAll () ; |
| 81 |
|
| 82 |
upMessage ("Making genetic maps - a minute or two") ; |
| 83 |
vMapMakeAll () ; |
| 84 |
gMapMakeAll () ; |
| 85 |
|
| 86 |
upMessage ("Making physical chromo maps - a minute or two") ; |
| 87 |
cMapMakeAll () ; |
| 88 |
|
| 89 |
upMessage ("Sorting the lexiques - a minute or two") ; |
| 90 |
lexAlphaMakeAll () ; |
| 91 |
|
| 92 |
upMessage ("I save to disk") ; |
| 93 |
sessionClose (TRUE); |
| 94 |
|
| 95 |
pickDraw () ; /* updates title bar */ |
| 96 |
|
| 97 |
upMessage ("Update complete") ; |
| 98 |
if (sessionDbName()) |
| 99 |
messout ("We are now using data release %s %d-%d", |
| 100 |
sessionDbName(), |
| 101 |
thisSession.mainDataRelease, thisSession.subDataRelease) ; |
| 102 |
else |
| 103 |
messout ("We are now using data release %d-%d", |
| 104 |
thisSession.mainDataRelease, thisSession.subDataRelease) ; |
| 105 |
} |
| 106 |
|
| 107 |
/******************************************/ |
| 108 |
|
| 109 |
static BOOL updateCheckFile (ACEIN update_io) |
| 110 |
{ |
| 111 |
int mainRelNum = -1, subRelNum = -1 ; |
| 112 |
char *first_line; |
| 113 |
|
| 114 |
/* When reading the first line we need to get the comment line. |
| 115 |
* Although it may seem dangerous to tinker with the speciaql here, |
| 116 |
* the update_io will be passed to the parsing module which resets |
| 117 |
* the special anyway. */ |
| 118 |
aceInSpecial (update_io, "\n"); |
| 119 |
|
| 120 |
first_line = aceInCard (update_io); |
| 121 |
|
| 122 |
if (sscanf (first_line, "// acedb update %d %d\n", |
| 123 |
&mainRelNum, &subRelNum) != 2) |
| 124 |
{ |
| 125 |
messout ("The first line of the update does not have the " |
| 126 |
"correct format. Abandoning update.") ; |
| 127 |
return FALSE ; |
| 128 |
} |
| 129 |
|
| 130 |
if (mainRelNum != thisSession.mainDataRelease || |
| 131 |
subRelNum != thisSession.subDataRelease+1) |
| 132 |
{ |
| 133 |
messout ("Update %d.%d does not match the current state", |
| 134 |
mainRelNum, subRelNum) ; |
| 135 |
return FALSE ; |
| 136 |
} |
| 137 |
return TRUE ; |
| 138 |
} /* updateCheckFile */ |
| 139 |
|
| 140 |
/******************************************/ |
| 141 |
|
| 142 |
static BOOL updateParseAceIn (ACEIN update_io) |
| 143 |
/* destroys update_io */ |
| 144 |
{ |
| 145 |
BOOL ok ; |
| 146 |
|
| 147 |
messStatus (messprintf ("Adding update %d", |
| 148 |
thisSession.subDataRelease + 1)) ; |
| 149 |
upMessage ("Update started. This may take a few minutes please wait.") ; |
| 150 |
|
| 151 |
XREF_DISABLED_FOR_UPDATE = TRUE ; |
| 152 |
ok = parseAceIn (update_io, 0, FALSE) ; /* destroys update_io */ |
| 153 |
XREF_DISABLED_FOR_UPDATE = FALSE ; |
| 154 |
|
| 155 |
return ok ; |
| 156 |
} /* updateParseAceIn */ |
| 157 |
|
| 158 |
/******************************************/ |
| 159 |
|
| 160 |
void updateDoAction (BOOL doAll) |
| 161 |
{ |
| 162 |
VoidRoutine previousCrashRoutine ; |
| 163 |
char fileName[256] , * fn; |
| 164 |
BOOL doAlign = FALSE ; |
| 165 |
ACEIN update_io; |
| 166 |
char *rawdir = dbPathStrictFilName("rawdata", "", "", "rd", 0); |
| 167 |
|
| 168 |
#if !defined(MACINTOSH) |
| 169 |
if (getenv ("ACEDB_DATA")) |
| 170 |
strcpy (fileName, getenv("ACEDB_DATA")) ; |
| 171 |
else |
| 172 |
#endif |
| 173 |
if (!rawdir) |
| 174 |
{ messout ("Sorry, can't find rawdata directory") ; |
| 175 |
return ; |
| 176 |
} |
| 177 |
else |
| 178 |
strcpy (fileName, rawdir) ; |
| 179 |
|
| 180 |
if (rawdir) |
| 181 |
messfree(rawdir); |
| 182 |
|
| 183 |
if (isWriteAccess()) |
| 184 |
{ messout("You still have write access\n" |
| 185 |
"First, save your earlier work") ; |
| 186 |
return ; |
| 187 |
} |
| 188 |
|
| 189 |
if (!sessionGainWriteAccess()) |
| 190 |
{ |
| 191 |
messout ("Sorry, you cannot gain write access\n" |
| 192 |
"Update impossible.") ; |
| 193 |
return ; |
| 194 |
} |
| 195 |
|
| 196 |
fn = fileName + strlen(fileName) ; |
| 197 |
|
| 198 |
previousCrashRoutine = messcrashroutine ; |
| 199 |
messcrashroutine = simpleCrashRoutine ; /* don't allow crash recovery */ |
| 200 |
|
| 201 |
upMessage ("Reading in model file") ; |
| 202 |
if (!getNewModels ()) /* needs write access */ |
| 203 |
messExit ("There were errors while reading the models during the update") ; |
| 204 |
|
| 205 |
while(TRUE) |
| 206 |
{ |
| 207 |
if (!isWriteAccess()) |
| 208 |
sessionGainWriteAccess() ; |
| 209 |
if (sessionDbName()) |
| 210 |
strcpy (fn, messprintf ("/update.%s.%d-%d", |
| 211 |
sessionDbName(), |
| 212 |
thisSession.mainDataRelease, |
| 213 |
thisSession.subDataRelease + 1)) ; |
| 214 |
else |
| 215 |
strcpy (fn, messprintf ("/update.%d-%d", |
| 216 |
thisSession.mainDataRelease, |
| 217 |
thisSession.subDataRelease + 1)) ; |
| 218 |
upMessage (messprintf("Looking for file %s",fileName)) ; |
| 219 |
upMessage (timeShow(timeNow())) ; |
| 220 |
if (!filCheckName (fileName, "", "r")) |
| 221 |
{ |
| 222 |
if (!doAlign) |
| 223 |
messout ("Could not find file %s",fileName) ; |
| 224 |
else |
| 225 |
upMessage (messprintf ("Could not find file %s", |
| 226 |
fileName)) ; |
| 227 |
break ; |
| 228 |
} |
| 229 |
|
| 230 |
/* note: these files are server side (in rawdata directory) */ |
| 231 |
update_io = aceInCreateFromFile (fileName, "r", "", 0); |
| 232 |
|
| 233 |
if (!update_io) /* should not fail */ |
| 234 |
{ |
| 235 |
messcrash ("updateDoAction() - inconsistency " |
| 236 |
"filName(%s) succeeded, " |
| 237 |
"but now we can't make an ACEIN from that file.", |
| 238 |
fileName) ; |
| 239 |
break ; |
| 240 |
} |
| 241 |
|
| 242 |
messStatus ("Updating, please wait.") ; |
| 243 |
if (!updateCheckFile (update_io)) |
| 244 |
{ |
| 245 |
aceInDestroy (update_io); |
| 246 |
break ; |
| 247 |
} |
| 248 |
|
| 249 |
if (!updateParseAceIn (update_io)) /* will destroy update_io */ |
| 250 |
messExit ("There were errors while parsing the " |
| 251 |
"official data: I exit.") ; |
| 252 |
|
| 253 |
thisSession.subDataRelease++ ; |
| 254 |
doAlign = TRUE ; |
| 255 |
sessionClose(TRUE) ; |
| 256 |
if (!doAll && !messQuery |
| 257 |
(messprintf ("We are now using data release %d-%d\n%s", |
| 258 |
thisSession.mainDataRelease, |
| 259 |
thisSession.subDataRelease, |
| 260 |
"Do you want to read the next update file ? "))) |
| 261 |
break ; |
| 262 |
} |
| 263 |
upMessage (timeShow(timeNow())) ; |
| 264 |
if (doAlign) |
| 265 |
{ if (!isWriteAccess()) |
| 266 |
sessionGainWriteAccess() ; |
| 267 |
updateAlign () ; |
| 268 |
} |
| 269 |
sessionClose(TRUE) ; |
| 270 |
upMessage (timeShow(timeNow())) ; |
| 271 |
messcrashroutine = previousCrashRoutine; /* reestablish crash recovery */ |
| 272 |
|
| 273 |
return; |
| 274 |
} /* updateDoAction */ |
| 275 |
|
| 276 |
/******************************************/ |
| 277 |
|
| 278 |
static void updateAction(void) |
| 279 |
{ updateDoAction(FALSE) ; |
| 280 |
} |
| 281 |
|
| 282 |
static void allUpdateAction(void) |
| 283 |
{ updateDoAction(TRUE) ; |
| 284 |
} |
| 285 |
|
| 286 |
/******************************************/ |
| 287 |
|
| 288 |
static void updateDestroy (void) |
| 289 |
{ |
| 290 |
updateGraph = 0 ; |
| 291 |
} |
| 292 |
|
| 293 |
/*********************************************/ |
| 294 |
/************* public routine ****************/ |
| 295 |
|
| 296 |
static MENUOPT updateMenu[]= |
| 297 |
{ |
| 298 |
{ graphDestroy, "Quit" }, |
| 299 |
{ help, "Help" }, |
| 300 |
{ updateAction, "Next Update" }, |
| 301 |
{ allUpdateAction, "All Updates" }, |
| 302 |
{ 0,0 } |
| 303 |
}; |
| 304 |
|
| 305 |
/********************************************/ |
| 306 |
|
| 307 |
void updateData(void) |
| 308 |
{ |
| 309 |
if (!graphActivate(updateGraph)) |
| 310 |
{ |
| 311 |
updateGraph = displayCreate("DtUpdate") ; |
| 312 |
|
| 313 |
graphMenu (updateMenu); |
| 314 |
graphTextBounds (80,100) ; |
| 315 |
graphRegister(DESTROY,updateDestroy) ; |
| 316 |
graphColor (BLACK) ; |
| 317 |
graphButtons (updateMenu, 1, 1, 50) ; |
| 318 |
graphText ("Line:", 2, 2.5) ; |
| 319 |
lineBox = graphBoxStart () ; |
| 320 |
/* |
| 321 |
*parseLineText = 0 ; |
| 322 |
graphTextPtr (parseLineText, 8, 2.5, 60) ; |
| 323 |
*/ |
| 324 |
graphBoxEnd () ; |
| 325 |
line = 4 ; |
| 326 |
if (sessionDbName()) |
| 327 |
upMessage (messprintf ("We are now using data release %s %d-%d", |
| 328 |
sessionDbName(), |
| 329 |
thisSession.mainDataRelease, |
| 330 |
thisSession.subDataRelease)) ; |
| 331 |
else |
| 332 |
upMessage (messprintf ("We are now using data release %d-%d", /* */ |
| 333 |
thisSession.mainDataRelease, |
| 334 |
thisSession.subDataRelease)) ; |
| 335 |
graphRedraw () ; |
| 336 |
} |
| 337 |
else |
| 338 |
graphPop() ; |
| 339 |
} |
| 340 |
|
| 341 |
/*********************************************/ |
| 342 |
/*********************************************/ |
| 343 |
|
| 344 |
|