def init(): # # requires: # # effects: # 1. Processes command line options # 2. Initializes global file descriptors/file names # # returns: # global diagFile, errorFile db.useOneConnection(1) try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor db.set_sqlLogFD(diagFile) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date()))
def init(): global fpB6BcpFile, fpMgpBcpFile, sourceLookup, nextAssocKey try: fpB6BcpFile = open(b6BcpFile, 'w') except: 'Could not open file for writing %s\n' % b6BcpFile sys.exit(1) if B6_ONLY == 'false': try: fpMgpBcpFile = open(mgpBcpFile, 'w') except: 'Could not open file for writing %s\n' % mgpBcpFile sys.exit(1) loadSourceLookup() # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) db.useOneConnection(1) # # get next _Assoc_key # results = db.sql(''' select nextval('seq_source_assoc_seq') as nextAssocKey ''', 'auto') nextAssocKey = results[0]['nextAssocKey'] return 0
def initialize(): global mgi_to_uniprotFile global uniprotFile global markerIPFile global markerIPRef global annotEvidence, annotEditor, annotDate # # initialize caches # db.useOneConnection(1) db.set_sqlLogFunction(db.sqlLogAll) mgi_to_uniprotFile = os.getenv('MGI_UNIPROT_LOAD_FILE') uniprotFile = os.getenv('UNIPROT_ACC_ASSOC_FILE') markerIPFile = os.getenv('MARKER_IP_ASSOC_FILE') markerIPRef = os.environ['MARKER_IP_ANNOT_REF'] annotEvidence = os.environ['ANNOT_EVIDENCECODE'] annotEditor = os.environ['ANNOT_EDITOR'] annotDate = os.environ['ANNOT_DATE'] rc = 0 # # Make sure the required environment variables are set. # if not mgi_to_uniprotFile: print 'Environment variable not set: MGI_UNIPROT_LOAD_FILE' rc = 1 if not uniprotFile: print 'Environment variable not set: UNIPROT_ACC_ASSOC' rc = 1 if not markerIPFile: print 'Environment variable not set: MARKER_IP_ASSOC_FILE' rc = 1 if not markerIPRef: print 'Environment variable not set: MARKER_IP_ANNOT_REF' rc = 1 if not annotEvidence: print 'Environment variable not set: ANNOT_EVIDENCECODE' rc = 1 if not annotEditor: print 'Environment variable not set: ANNOT_EDITOR' rc = 1 if not annotDate: print 'Environment variable not set: ANNOT_DATE' rc = 1 return rc
def init(): ''' # requires: # # effects: # 1. Processes command line options # 2. Initializes local DBMS parameters # 3. Initializes global file descriptors/file names # 4. Initializes global keys # # returns: # ''' global inputFile, outputFile, diagFile, errorFile, errorFileName, diagFileName db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) diagFileName = inputFileName + '.diagnostics' errorFileName = inputFileName + '.error' outputFileName = inputFileName + '.trans' try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: outputFile = open(outputFileName, 'w') except: exit(1, 'Could not open file %s\n' % outputFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor db.set_sqlLogFD(diagFile) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) diagFile.write('Input File: %s\n' % (inputFileName)) diagFile.write('Output File: %s\n' % (outputFileName)) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date()))
def init(): global bcpCommand global diagFile, errorFile, inputFile, errorFileName, diagFileName global markerFile, refFile, aliasFile db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) bcpCommand = bcpCommand + db.get_sqlServer() + ' ' + db.get_sqlDatabase( ) + ' %s ' + currentDir + ' %s "\\t" "\\n" mgd' head, tail = os.path.split(inputFileName) diagFileName = outputDir + '/' + tail + '.diagnostics' errorFileName = outputDir + '/' + tail + '.error' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: markerFile = open(markerFileName, 'w') except: exit(1, 'Could not open file %s\n' % markerFileName) try: refFile = open(refFileName, 'w') except: exit(1, 'Could not open file %s\n' % refFileName) try: aliasFile = open(aliasFileName, 'w') except: exit(1, 'Could not open file %s\n' % aliasFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) return
def init(): # requires: # # effects: # 1. Processes command line options # 2. Initializes local DBMS parameters # 3. Initializes global file descriptors/file names # 4. Initializes global keys # # returns: # global diagFile, errorFile, inputFile, errorFileName, diagFileName global strainFile db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) fdate = mgi_utils.date('%m%d%Y') # current date head, tail = os.path.split(inputFileName) diagFileName = tail + '.' + fdate + '.diagnostics' errorFileName = tail + '.' + fdate + '.error' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: strainFile = open(strainFileName, 'w') except: exit(1, 'Could not open file %s\n' % strainFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor db.set_sqlLogFD(diagFile) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) return
def init(): global bcpCommand global diagFile, errorFile, inputFile, errorFileName, diagFileName global markerFile, refFile, aliasFile db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) bcpCommand = bcpCommand + db.get_sqlServer() + ' ' + db.get_sqlDatabase() + ' %s ' + currentDir + ' %s "\\t" "\\n" mgd' head, tail = os.path.split(inputFileName) diagFileName = outputDir + '/' + tail + '.diagnostics' errorFileName = outputDir + '/' + tail + '.error' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: markerFile = open(markerFileName, 'w') except: exit(1, 'Could not open file %s\n' % markerFileName) try: refFile = open(refFileName, 'w') except: exit(1, 'Could not open file %s\n' % refFileName) try: aliasFile = open(aliasFileName, 'w') except: exit(1, 'Could not open file %s\n' % aliasFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) return
def init(): ''' # requires: # # effects: # 1. Processes command line options # 2. Initializes local DBMS parameters # 3. Initializes global file descriptors/file names # # returns: # ''' global inputFile, outputFile, diagFile, errorFile global inputFileName, errorFileName, diagFileName, outputFileName try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: diagFile = open(diagFileName, 'w+') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: outputFile = open(outputFileName, 'w') except: exit(1, 'Could not open file %s\n' % outputFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor db.set_commandLogFile(diagFileName) # Set Log File Descriptor diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) diagFile.write('Input File: %s\n' % (inputFileName)) errorFile.write('\nStart file: %s\n\n' % (mgi_utils.date()))
def init(): # Purpose: process command line options # Returns: nothing # Assumes: nothing # Effects: initializes global variables # exits if files cannot be opened # Throws: nothing global inputFile, diagFile, errorFile, errorFileName, diagFileName db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) fdate = mgi_utils.date('%m%d%Y') # current date head, tail = os.path.split(inputFileName) diagFileName = tail + '.' + fdate + '.diagnostics' errorFileName = tail + '.' + fdate + '.error' try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor db.set_sqlLogFD(diagFile) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) diagFile.write('Input File: %s\n' % (inputFileName)) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) return
def initialize(): global inputFileName, outputFileName, inputFile, outputFile db.useOneConnection(1) db.set_sqlLogFunction(db.sqlLogAll) inputFileName = os.getenv('INFILE_1_0') outputFileName = os.getenv('OUTPUT_1_0_PROTEINCODING') # # Make sure the required environment variables are set. # if not inputFileName: print 'Environment variable not set: INFILE_1_0' return 1 # # Make sure the required environment variables are set. # if not outputFileName: print 'Environment variable not set: OUTPUT_1_0_PROTEINCODING' return 1 # # Open the input file # try: inputFile = open(inputFileName, 'r') except: print 'Cannot open file: ' + inputFileName return 1 # # Open the output file # try: outputFile = open(outputFileName, 'w') except: print 'Cannot open file: ' + outputFileName return 1 return 0
def init(): global fpB6AnnotFile, fpMgpAnnotFile try: fpB6AnnotFile = open(b6AnnotFile, 'w') except: 'Could not open file for writing %s\n' % b6AnnotFile sys.exit(1) try: fpMgpAnnotFile = open(mgpAnnotFile, 'w') except: 'Could not open file for writing %s\n' % mgpAnnotFile sys.exit(1) loadFeatureTypeLookup() # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) db.useOneConnection(1) return 0
def init(): global diagFile, errorFile, inputFile, errorFileName, diagFileName db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) head, tail = os.path.split(inputFileName) diagFileName = outputDir + '/' + tail + '.diagnostics' errorFileName = outputDir + '/' + tail + '.error' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) return
def init(): ''' # requires: # # effects: # 1. Processes command line options # 2. Initializes local DBMS parameters # 3. Initializes global file descriptors/file names # 4. Initializes global keys # # returns: # ''' global inputFile, diagFile, errorFile, errorFileName, diagFileName global passwordFileName, noteFileName global exptFile, exptMarkerFile, accFile, noteFile global inputFileName, exptFileName, exptMarkerFileName, accFileName global mode, exptType try: optlist, args = getopt.getopt(sys.argv[1:], 'S:D:U:P:M:I:R:E:C:') except: showUsage() # # Set server, database, user, passwords depending on options # specified by user. # server = '' database = '' user = '' password = '' inputFileName = '' jnum = '' createdBy = '' for opt in optlist: if opt[0] == '-S': server = opt[1] elif opt[0] == '-D': database = opt[1] elif opt[0] == '-U': user = opt[1] elif opt[0] == '-P': passwordFileName = opt[1] elif opt[0] == '-M': mode = opt[1] elif opt[0] == '-I': inputFileName = opt[1] elif opt[0] == '-E': exptType = re.sub('"', '', opt[1]) else: showUsage() # User must specify Server, Database, User and Password password = string.strip(open(passwordFileName, 'r').readline()) if server == '' or \ database == '' or \ user == '' or \ password == '' or \ mode == '' or \ inputFileName == '' or \ exptType == '': showUsage() # Initialize db.py DBMS parameters db.set_sqlLogin(user, password, server, database) db.useOneConnection(1) diagFileName = 'mappingload.diag' errorFileName = 'mappingload.error' exptFileName = 'MLD_Expts.mapping.bcp' exptMarkerFileName = 'MLD_Expt_Marker.mapping.bcp' accFileName = 'ACC_Accession.mapping.bcp' noteFileName = 'MLD_Notes.mapping.bcp' try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: exptFile = open(exptFileName, 'w') except: exit(1, 'Could not open file %s\n' % exptFileName) try: exptMarkerFile = open(exptMarkerFileName, 'w') except: exit(1, 'Could not open file %s\n' % exptMarkerFileName) try: accFile = open(accFileName, 'w') except: exit(1, 'Could not open file %s\n' % accFileName) try: noteFile = open(noteFileName, 'w') except: exit(1, 'Could not open file %s\n' % noteFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor db.set_commandLogFile(diagFileName) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (server)) diagFile.write('Database: %s\n' % (database)) diagFile.write('User: %s\n' % (user)) diagFile.write('Input File: %s\n' % (inputFileName)) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date()))
def initialize(): global diagFile, errorFile, inputFile, errorFileName, diagFileName global alleleFile, mutationFile, mutantFile, refFile global accFile, accRefFile, noteFile, annotFile global newAlleleFile db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) head, tail = os.path.split(inputFileName) diagFileName = outputDir + '/' + tail + '.diagnostics' errorFileName = outputDir + '/' + tail + '.error' newAlleleFileName = outputDir + '/' + tail + '.new' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: newAlleleFile = open(newAlleleFileName, 'w') except: exit(1, 'Could not open file %s\n' % newAlleleFileName) try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: alleleFile = open(alleleFileName, 'w') except: exit(1, 'Could not open file %s\n' % alleleFileName) try: mutationFile = open(mutationFileName, 'w') except: exit(1, 'Could not open file %s\n' % mutationFileName) try: mutantFile = open(mutantFileName, 'w') except: exit(1, 'Could not open file %s\n' % mutantFileName) try: refFile = open(refFileName, 'w') except: exit(1, 'Could not open file %s\n' % refFileName) try: accFile = open(accFileName, 'w') except: exit(1, 'Could not open file %s\n' % accFileName) try: accRefFile = open(accRefFileName, 'w') except: exit(1, 'Could not open file %s\n' % accRefFileName) try: noteFile = open(noteFileName, 'w') except: exit(1, 'Could not open file %s\n' % noteFileName) try: annotFile = open(annotFileName, 'w') except: exit(1, 'Could not open file %s\n' % annotFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date()))
def init(): # Purpose: process command line options # Returns: nothing # Assumes: nothing # Effects: initializes global variables # calls showUsage() if usage error # exits if files cannot be opened # Throws: nothing global diagFile, reportFile, reportFileName, diagFileName, passwordFileName global mode try: optlist, args = getopt.getopt(sys.argv[1:], 'S:D:U:P:') except: showUsage() # # Set server, database, user, passwords depending on options # specified by user. # server = '' database = '' user = '' password = '' for opt in optlist: if opt[0] == '-S': server = opt[1] elif opt[0] == '-D': database = opt[1] elif opt[0] == '-U': user = opt[1] elif opt[0] == '-P': passwordFileName = opt[1] else: showUsage() # User must specify Server, Database, User and Password password = string.strip(open(passwordFileName, 'r').readline()) if server == '' or \ database == '' or \ user == '' or \ password == '': showUsage() # Initialize db.py DBMS parameters db.set_sqlLogin(user, password, server, database) db.useOneConnection(1) head, tail = os.path.split(sys.argv[0]) diagFileName = os.environ['RUNTIME_DIR'] + '/' + tail + '.diagnostics' reportFileName = tail + '.rpt' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: reportFile = reportlib.init(reportFileName, 'Deleted: Marker Annotations To Obsolete Terms', outputdir = os.environ['RUNTIME_DIR']) except: exit(1, 'Could not open file %s\n' % reportFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor #db.set_sqlLogFD(diagFile) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (server)) diagFile.write('Database: %s\n' % (database)) diagFile.write('User: %s\n' % (user)) return
def init(): global diagFile, errorFile, errorFileName, diagFileName global outResultStFile, outResultFile, outResultImageFile global inResultsFile, inStructureFile db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) diagFileName = 'resultsload.diagnostics' errorFileName = 'resultsload.error' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) # Input Files try: inResultsFile = open(inResultsFileName, 'r') except: exit(1, 'Could not open file %s\n' % inResultsFileName) try: inStructureFile = open(inStructureFileName, 'r') except: exit(1, 'Could not open file %s\n' % inStructureFileName) # Output Files try: outResultStFile = open(outResultStFileName, 'w') except: exit(1, 'Could not open file %s\n' % outResultStFileName) try: outResultFile = open(outResultFileName, 'w') except: exit(1, 'Could not open file %s\n' % outResultFileName) try: outResultImageFile = open(outResultImageFileName, 'w') except: exit(1, 'Could not open file %s\n' % outResultImageFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) return
def init(): # requires: # # effects: # 1. Processes command line options # 2. Initializes local DBMS parameters # 3. Initializes global file descriptors/file names # 4. Initializes global keys # # returns: # global diagFileName, errorFileName, synFileName global inputFile, diagFile, errorFile, synFile global mgiTypeKey, createdByKey, referenceKey db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) head, tail = os.path.split(inputFileName) diagFileName = logDir + '/' + tail + '.diagnostics' errorFileName = logDir + '/' + tail + '.error' synFileName = 'MGI_Synonym.bcp' print inputFileName print logDir try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: synFile = open(outputDir + '/' + synFileName, 'w') except: exit(1, 'Could not open file %s\n' % synFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) diagFile.write('Object Type: %s\n' % (mgiType)) diagFile.write('Input File: %s\n' % (inputFileName)) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) mgiTypeKey = loadlib.verifyMGIType(mgiType, 0, errorFile) createdByKey = loadlib.verifyUser(createdBy, 0, errorFile) # if reference is J:0, then no reference is given if jnum == 'J:0': referenceKey = '' else: referenceKey = loadlib.verifyReference(jnum, 0, errorFile) # exit if we can't resolve mgiType, createdBy or jnum if mgiTypeKey == 0 or \ createdByKey == 0 or \ referenceKey == 0: exit(1) if mode == 'reload': print 'mode is: %s, deleting synonyms' % mode sys.stdout.flush() db.sql('delete from MGI_Synonym ' + \ 'where _MGIType_key = %d ' % (mgiTypeKey) + \ 'and _CreatedBy_key = %d ' % (createdByKey), None)
def initialize(): global mgi_to_uniprotFile global mgi_to_markertypeFile global uniprotFile global ec2goFile, goECFile global ip2goFile, goIPFile global spkw2goFile, goSPKWFile global goECRef, goIPRef, goSPKWRef global annotEvidence, annotEditor, annotDate, annotNote, annotNotePrefix # # initialize caches # db.useOneConnection(1) db.set_sqlLogFunction(db.sqlLogAll) mgi_to_uniprotFile = os.getenv('MGI_UNIPROT_LOAD_FILE') mgi_to_markertypeFile = os.getenv('MGI_ACC_ASSOC_FILE') uniprotFile = os.getenv('UNIPROT_ACC_ASSOC_FILE') ec2goFile = os.getenv('EC2GOFILE') goECFile = os.getenv('GO_EC_ASSOC_FILE') goECRef = os.environ['GO_EC_ANNOT_REF'] ip2goFile = os.getenv('IP2GOFILE') goIPFile = os.getenv('GO_IP_ASSOC_FILE') goIPRef = os.environ['GO_IP_ANNOT_REF'] spkw2goFile = os.getenv('SPKW2GOFILE') goSPKWFile = os.getenv('GO_SPKW_ASSOC_FILE') goSPKWRef = os.environ['GO_SPKW_ANNOT_REF'] annotEvidence = os.environ['ANNOT_EVIDENCECODE'] annotEditor = os.environ['ANNOT_EDITOR'] annotDate = os.environ['ANNOT_DATE'] annotNote = os.environ['ANNOT_NOTE'] annotNotePrefix = os.environ['ANNOT_NOTEPREFIX'] rc = 0 # # Make sure the required environment variables are set. # if not mgi_to_uniprotFile: print 'Environment variable not set: MGI_UNIPROT_LOAD_FILE' rc = 1 if not uniprotFile: print 'Environment variable not set: UNIPROT_ACC_ASSOC' rc = 1 if not mgi_to_markertypeFile: print 'Environment variable not set: MGI_ACC_ASSOC_FILE' rc = 1 if not ec2goFile: print 'Environment variable not set: EC2GOFILE' rc = 1 if not goECFile: print 'Environment variable not set: GO_EC_ASSOC_FILE' rc = 1 if not goECRef: print 'Environment variable not set: GO_EC_ANNOTREF' rc = 1 if not ip2goFile: print 'Environment variable not set: IP2GOFILE' rc = 1 if not goIPFile: print 'Environment variable not set: GO_IP_ASSOC_FILE' rc = 1 if not goIPRef: print 'Environment variable not set: GO_IP_ANNOTREF' rc = 1 if not goSPKWFile: print 'Environment variable not set: GO_SPKW_ASSOC_FILE' rc = 1 if not goSPKWRef: print 'Environment variable not set: GO_SPKW_ANNOTREF' rc = 1 if not annotEvidence: print 'Environment variable not set: ANNOT_EVIDENCECODE' rc = 1 if not annotEditor: print 'Environment variable not set: ANNOT_EDITOR' rc = 1 if not annotDate: print 'Environment variable not set: ANNOT_DATE' rc = 1 if not annotNote: print 'Environment variable not set: ANNOT_NOTE' rc = 1 if not annotNotePrefix: print 'Environment variable not set: ANNOT_NOTEPREFIX' rc = 1 return rc
def init(): ''' # requires: # # effects: # 1. Processes command line options # 2. Initializes local DBMS parameters # 3. Initializes global file descriptors/file names # 4. Initializes global keys # # returns: # ''' global inputFile, diagFile, errorFile, errorFileName, diagFileName global transTypeFile, transFile global transTypeFileName, transFileName db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) # the default output file names are bases on 'inputFileName' head, fileName = os.path.split(inputFileName) # rename 'head' head = outputFileDir fdate = mgi_utils.date('%m%d%Y') # current date diagFileName = head + '/' + fileName + '.' + fdate + '.diagnostics' print diagFileName errorFileName = head + '/' + fileName + '.' + fdate + '.error' print errorFileName transTypeFileName = head + '/' + fileName + '.' + fdate + '.MGI_TranslationType.bcp' print transTypeFileName transFileName = head + '/' + fileName + '.' + fdate + '.MGI_Translation.bcp' print transFileName try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: transTypeFile = open(transTypeFileName, 'w') except: exit(1, 'Could not open file %s\n' % transTypeFileName) try: transFile = open(transFileName, 'w') except: exit(1, 'Could not open file %s\n' % transFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor db.set_sqlLogFD(diagFile) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) diagFile.write('Input File: %s\n' % (inputFileName)) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date()))
def init(): global diagFile, errorFile, errorFileName, diagFileName global outAccFile, outPrepFile, outAssayFile, outAssayNoteFile global outGelLaneFile, outGelLaneStFile, outGelRowFile, outGelBandFile global inPrimerFile, inPrepFile, inAssayFile, inGelLaneFile, inGelBandFile db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) fdate = mgi_utils.date('%m%d%Y') # current date diagFileName = sys.argv[0] + '.' + fdate + '.diagnostics' errorFileName = sys.argv[0] + '.' + fdate + '.error' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) # Input Files try: inPrepFile = open(inPrepFileName, 'r') except: exit(1, 'Could not open file %s\n' % inPrepFileName) try: inAssayFile = open(inAssayFileName, 'r') except: exit(1, 'Could not open file %s\n' % inAssayFileName) try: inGelLaneFile = open(inGelLaneFileName, 'r') except: exit(1, 'Could not open file %s\n' % inGelLaneFileName) try: inGelBandFile = open(inGelBandFileName, 'r') except: exit(1, 'Could not open file %s\n' % inGelBandFileName) # Output Files try: outPrepFile = open(outPrepFileName, 'w') except: exit(1, 'Could not open file %s\n' % outPrepFileName) try: outAssayFile = open(outAssayFileName, 'w') except: exit(1, 'Could not open file %s\n' % outAssayFileName) try: outAssayNoteFile = open(outAssayNoteFileName, 'w') except: exit(1, 'Could not open file %s\n' % outAssayNoteFileName) try: outGelLaneFile = open(outGelLaneFileName, 'w') except: exit(1, 'Could not open file %s\n' % outGelLaneFileName) try: outGelLaneStFile = open(outGelLaneStFileName, 'w') except: exit(1, 'Could not open file %s\n' % outGelLaneStFileName) try: outGelRowFile = open(outGelRowFileName, 'w') except: exit(1, 'Could not open file %s\n' % outGelRowFileName) try: outGelBandFile = open(outGelBandFileName, 'w') except: exit(1, 'Could not open file %s\n' % outGelBandFileName) try: outAccFile = open(outAccFileName, 'w') except: exit(1, 'Could not open file %s\n' % outAccFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) return
def init(outputfile, title = None, outputdir = None, printHeading = 'JAX', isHTML = 0, fileExt = None, sqlOneConnection = 1, sqlLogging = 1): ''' # requires: outputfile, the name of the output file (string) # title, the title of the report (string) # outputdir, the directory in which to place the output file (string); # the default is the current working directory # printHeading, set to Header Type if the header is to be printed (default is JAX) # isHTML, set to 1 if the output file is HTML format, 0 otherwise # (default is 0) # fileExt, the file extension of the output file (e.g. ".rpt", ".tab") # # effects: # 1. Opens the output file under $HOME/mgireport directory for writing # 2. Initializes the output file with the title of the report, if given # # returns: # The file descriptor which was initialized # ''' suffix = '' if fileExt != None: suffix = fileExt if isHTML: suffix = suffix + '.html' elif isHTML: suffix = suffix + '.html' else: suffix = '.rpt' outputfile = os.path.splitext(outputfile) if outputdir is None: outputdir = os.getcwd() filename = outputdir + '/' + outputfile[0] + suffix fp = open(filename, 'w') if isHTML: fp.write("<HTML>") fp.write("<BODY>") fp.write("<PRE>") # see finish_nonps for closing of these markups if printHeading is not None: header(fp, printHeading) if title is not None: fp.write(str.center(title, column_width) + 2 * CRT) if sqlOneConnection: db.useOneConnection(1) if sqlLogging: db.set_sqlLogFunction(db.sqlLogAll) return fp
def init(): global diagFile, errorFile, inputFile, errorFileName, diagFileName global strainFile, markerFile, accFile, annotFile global noteFile, noteChunkFile db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) fdate = mgi_utils.date('%m%d%Y') # current date head, tail = os.path.split(inputFileName) diagFileName = tail + '.' + fdate + '.diagnostics' errorFileName = tail + '.' + fdate + '.error' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: strainFile = open(strainFileName, 'w') except: exit(1, 'Could not open file %s\n' % strainFileName) try: markerFile = open(markerFileName, 'w') except: exit(1, 'Could not open file %s\n' % markerFileName) try: accFile = open(accFileName, 'w') except: exit(1, 'Could not open file %s\n' % accFileName) try: noteFile = open(noteFileName, 'w') except: exit(1, 'Could not open file %s\n' % noteFileName) try: noteChunkFile = open(noteChunkFileName, 'w') except: exit(1, 'Could not open file %s\n' % noteChunkFileName) try: annotFile = open(annotFileName, 'w') except: exit(1, 'Could not open file %s\n' % annotFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) return
def init(): global diagFile, errorFile, inputFile, errorFileName, diagFileName global outSetFile, outMemberFile global setKey, setMemberKey, createdByKey, mgiTypeKey, useSetKey global DEBUG db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) diagFileName = '%s/setload.diagnostics' % (outputDir) errorFileName = '%s/setload.error' % (outputDir) try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) # Output Files try: fullPathSetFile = '%s/%s' % (outputDir, outSetFileName) outSetFile = open(fullPathSetFile, 'w') except: exit(1, 'Could not open file %s\n' % fullPathSetFile) try: fullPathMemberFile = '%s/%s' % (outputDir, outMemberFileName) outMemberFile = open(fullPathMemberFile, 'w') except: exit(1, 'Could not open file %s\n' % fullPathMemberFile) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) if mode == 'preview': DEBUG = 1 bcpon = 0 elif mode != 'load': exit(1, 'Invalid Processing Mode: %s\n' % (mode)) results = db.sql('select max(_Set_key) + 1 as maxKey from MGI_Set', 'auto') setKey = results[0]['maxKey'] createdByKey = loadlib.verifyUser(createdBy, 0, errorFile) mgiTypeKey = loadlib.verifyMGIType(setType, 0, errorFile) # # use existing MGI_Set, or create a new one # results = db.sql( 'select _Set_key from MGI_Set where _MGIType_key = %s and name = \'%s\'' % (mgiTypeKey, setName), 'auto') if len(results) > 0: for r in results: setKey = r['_Set_key'] # delete/reload db.sql('delete from MGI_SetMember where _Set_key = %s' % (setKey), None) else: outSetFile.write(str(setKey) + TAB + \ str(mgiTypeKey) + TAB + \ str(setName) + TAB + \ '1' + TAB + \ str(createdByKey) + TAB + str(createdByKey) + TAB + \ loaddate + TAB + loaddate + CRT) results = db.sql( 'select max(_SetMember_key) + 1 as maxKey from MGI_SetMember', 'auto') setMemberKey = results[0]['maxKey'] return
def initialize(): # Purpose: open file descriptors; write timestamps to log files # Returns: 1 if error, else 0 # Assumes: Nothing # Effects: Sets global variables, exits if a file can't be opened, # creates files in the file system global fpDiagFile, fpErrorFile, fpInputFile, errorFileName, diagFileName global fpAlleleFile, fpMutationFile, fpRefFile global fpAccFile, fpNoteFile, fpAnnotFile global fpNewAlleleRptFile db.useOneConnection(1) #db.set_sqlUser(user) #db.set_sqlPasswordFromFile(passwordFileName) head, tail = os.path.split(inputFileName) diagFileName = outputDir + '/' + tail + '.diagnostics' errorFileName = outputDir + '/' + tail + '.error' try: fpDiagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: fpErrorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: fpNewAlleleRptFile = open(newAlleleRptFileName, 'w') except: exit(1, 'Could not open file %s\n' % newAlleleRptFileName) try: fpInputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: fpAlleleFile = open(alleleFileName, 'w') except: exit(1, 'Could not open file %s\n' % alleleFileName) try: fpMutationFile = open(mutationFileName, 'w') except: exit(1, 'Could not open file %s\n' % mutationFileName) try: fpRefFile = open(refFileName, 'w') except: exit(1, 'Could not open file %s\n' % refFileName) try: fpAccFile = open(accFileName, 'w') except: exit(1, 'Could not open file %s\n' % accFileName) try: fpNoteFile = open(noteFileName, 'w') except: exit(1, 'Could not open file %s\n' % noteFileName) try: fpAnnotFile = open(annotFileName, 'w') except: exit(1, 'Could not open file %s\n' % annotFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) fpDiagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) fpDiagFile.write('Server: %s\n' % (db.get_sqlServer())) fpDiagFile.write('Database: %s\n' % (db.get_sqlDatabase())) fpErrorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) return 0
def init(): global diagFile, errorFile, inputFile, errorFileName, diagFileName global outSetFile, outMemberFile global setKey, setMemberKey, createdByKey, mgiTypeKey, useSetKey global DEBUG db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) diagFileName = '%s/setload.diagnostics' % (outputDir) errorFileName = '%s/setload.error' % (outputDir) try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) # Output Files try: fullPathSetFile = '%s/%s' % (outputDir, outSetFileName) outSetFile = open(fullPathSetFile, 'w') except: exit(1, 'Could not open file %s\n' % fullPathSetFile) try: fullPathMemberFile = '%s/%s' % (outputDir, outMemberFileName) outMemberFile = open(fullPathMemberFile, 'w') except: exit(1, 'Could not open file %s\n' % fullPathMemberFile) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) if mode == 'preview': DEBUG = 1 bcpon = 0 elif mode != 'load': exit(1, 'Invalid Processing Mode: %s\n' % (mode)) results = db.sql('select max(_Set_key) + 1 as maxKey from MGI_Set', 'auto') setKey = results[0]['maxKey'] createdByKey = loadlib.verifyUser(createdBy, 0, errorFile) mgiTypeKey = loadlib.verifyMGIType(setType, 0, errorFile) # # use existing MGI_Set, or create a new one # results = db.sql('select _Set_key from MGI_Set where _MGIType_key = %s and name = \'%s\'' % (mgiTypeKey, setName), 'auto') if len(results) > 0: for r in results: setKey = r['_Set_key'] # delete/reload db.sql('delete from MGI_SetMember where _Set_key = %s' % (setKey), None) else: outSetFile.write(str(setKey) + TAB + \ str(mgiTypeKey) + TAB + \ str(setName) + TAB + \ '1' + TAB + \ str(createdByKey) + TAB + str(createdByKey) + TAB + \ loaddate + TAB + loaddate + CRT) results = db.sql('select max(_SetMember_key) + 1 as maxKey from MGI_SetMember', 'auto') setMemberKey = results[0]['maxKey'] return
def init(): # requires: # # effects: # 1. Processes command line options # 2. Initializes local DBMS parameters # 3. Initializes global file descriptors/file names # 4. Initializes global keys # # returns: # global inputFile, diagFile, errorFile, errorFileName, diagFileName global refFileName, refFile global mgiTypeKey global refAssocKey, createdByKey db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) fdate = mgi_utils.date('%m%d%Y') # current date head, tail = os.path.split(inputFileName) diagFileName = tail + '.' + fdate + '.diagnostics' errorFileName = tail + '.' + fdate + '.error' refFileName = tail + '.MGI_Reference_Assoc.bcp' try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: refFile = open(refFileName, 'w') except: exit(1, 'Could not open file %s\n' % refFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor db.set_sqlLogFD(diagFile) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) diagFile.write('Object Type: %s\n' % (mgiType)) diagFile.write('Input File: %s\n' % (inputFileName)) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) mgiTypeKey = loadlib.verifyMGIType(mgiType, 0, errorFile) createdByKey = loadlib.verifyUser(createdBy, 0, errorFile)
def init(): ''' # requires: # # effects: # 1. Processes command line options # 2. Initializes local DBMS parameters # 3. Initializes global file descriptors/file names # 4. Initializes global keys # # returns: # ''' global inputFile, diagFile, errorFile, errorFileName, diagFileName global passwordFileName, noteFileName global exptFile, exptMarkerFile, accFile, noteFile global inputFileName, exptFileName, exptMarkerFileName, accFileName global mode, exptType try: optlist, args = getopt.getopt(sys.argv[1:], 'S:D:U:P:M:I:R:E:C:') except: showUsage() # # Set server, database, user, passwords depending on options # specified by user. # server = '' database = '' user = '' password = '' inputFileName = '' jnum = '' createdBy = '' for opt in optlist: if opt[0] == '-S': server = opt[1] elif opt[0] == '-D': database = opt[1] elif opt[0] == '-U': user = opt[1] elif opt[0] == '-P': passwordFileName = opt[1] elif opt[0] == '-M': mode = opt[1] elif opt[0] == '-I': inputFileName = opt[1] elif opt[0] == '-E': exptType = re.sub('"', '', opt[1]) else: showUsage() # User must specify Server, Database, User and Password password = str.strip(open(passwordFileName, 'r').readline()) if server == '' or \ database == '' or \ user == '' or \ password == '' or \ mode == '' or \ inputFileName == '' or \ exptType == '': showUsage() # Initialize db.py DBMS parameters db.set_sqlLogin(user, password, server, database) db.useOneConnection(1) diagFileName = 'mappingload.diag' errorFileName = 'mappingload.error' exptFileName = 'MLD_Expts.mapping.bcp' exptMarkerFileName = 'MLD_Expt_Marker.mapping.bcp' accFileName = 'ACC_Accession.mapping.bcp' noteFileName = 'MLD_Notes.mapping.bcp' try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: exptFile = open(exptFileName, 'w') except: exit(1, 'Could not open file %s\n' % exptFileName) try: exptMarkerFile = open(exptMarkerFileName, 'w') except: exit(1, 'Could not open file %s\n' % exptMarkerFileName) try: accFile = open(accFileName, 'w') except: exit(1, 'Could not open file %s\n' % accFileName) try: noteFile = open(noteFileName, 'w') except: exit(1, 'Could not open file %s\n' % noteFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor db.set_commandLogFile(diagFileName) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (server)) diagFile.write('Database: %s\n' % (database)) diagFile.write('User: %s\n' % (user)) diagFile.write('Input File: %s\n' % (inputFileName)) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date()))
def initialize(): global diagFile, errorFile, inputFile, errorFileName, diagFileName global alleleFile, mutationFile, mutantFile, refFile global accFile, accRefFile, noteFile, noteChunkFile, annotFile global newAlleleFile db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) head, tail = os.path.split(inputFileName) diagFileName = outputDir + '/' + tail + '.diagnostics' errorFileName = outputDir + '/' + tail + '.error' newAlleleFileName = outputDir + '/' + tail + '.new' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: newAlleleFile = open(newAlleleFileName, 'w') except: exit(1, 'Could not open file %s\n' % newAlleleFileName) try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) try: alleleFile = open(alleleFileName, 'w') except: exit(1, 'Could not open file %s\n' % alleleFileName) try: mutationFile = open(mutationFileName, 'w') except: exit(1, 'Could not open file %s\n' % mutationFileName) try: mutantFile = open(mutantFileName, 'w') except: exit(1, 'Could not open file %s\n' % mutantFileName) try: refFile = open(refFileName, 'w') except: exit(1, 'Could not open file %s\n' % refFileName) try: accFile = open(accFileName, 'w') except: exit(1, 'Could not open file %s\n' % accFileName) try: accRefFile = open(accRefFileName, 'w') except: exit(1, 'Could not open file %s\n' % accRefFileName) try: noteFile = open(noteFileName, 'w') except: exit(1, 'Could not open file %s\n' % noteFileName) try: noteChunkFile = open(noteChunkFileName, 'w') except: exit(1, 'Could not open file %s\n' % noteChunkFileName) try: annotFile = open(annotFileName, 'w') except: exit(1, 'Could not open file %s\n' % annotFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date()))
import loadlib # # from configuration file # user = os.environ['MGD_DBUSER'] passwordFileName = os.environ['MGD_DBPASSWORDFILE'] loaddate = loadlib.loaddate modifiedBy = os.environ['MODIFIEDBY'] modifiedByKey = None newMkrType = os.environ['NEWMKRTYPE'] newMkrTypeKey = None db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) db.set_sqlLogFunction(db.sqlLogAll) inputFileName = os.environ['NOMENDATAFILE'] inputFile = None # file descriptor updateList = [] # list of marker keys to update mgiToMrkKeyDict = {} # {mgiID:markerKey, ...} try: inputFile = open(inputFileName, 'r') except: exit(1, 'Could not open file %s\n' % inputFileName) # # get keys for NEWMKRTYPE and MODIFIEDBY # results = db.sql('''select _Marker_Type_key from MRK_Types where name = '%s' ''' % newMkrType, 'auto') if len(results) == 0: exit (1, 'Invalid marker type %s\n' % newMkrType)
def initDB(): # # requires: # # effects: # 1. Initializes database options # 2. Loads global dictionaries # # returns: # global primerDict, primer2Dict, markerDict, marker2Dict db.useOneConnection(1) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) # Set Log File Descriptor db.set_sqlLogFD(diagFile) # cache all MIT primers that have a UniSTS ID db.sql('select p._Probe_key, p.name, stsID = a1.accID, mgiID = a2.accID ' + \ 'into #primers ' + \ 'from PRB_Probe p, ACC_Accession a1, ACC_Accession a2 ' + \ 'where p._Probe_key = a1._Object_key ' + \ 'and a1._MGIType_key = 3 ' + \ 'and a1._LogicalDB_key = 80 ' + \ 'and a1.preferred = 1 ' + \ 'and p._Probe_key = a2._Object_key ' + \ 'and a2._MGIType_key = 3 ' + \ 'and a2._LogicalDB_key = 1 ' + \ 'and a2.preferred = 1', None) db.sql('create index idx1 on #primers(_Probe_key)', None) results = db.sql('select * from #primers', 'auto') for r in results: primerDict[r['stsID']] = (r['name'], r['mgiID']) # cache all MIT primers for J:34136 db.sql('select p._Probe_key, p.name into #primers2 ' + \ 'from PRB_Probe p ' + \ 'where p._SegmentType_key = 63473 ' + \ 'and p.name like "d%mit%"', None) db.sql('create index idx1 on #primers2(_Probe_key)', None) results = db.sql('select a.accID, p.name from #primers2 p, ACC_Accession a ' + \ 'where p._Probe_key = a._Object_key ' + \ 'and a._MGIType_key = 3 ' + \ 'and a._LogicalDB_key = 1 ' + \ 'and a.prefixPart = "MGI:" ' + \ 'and a.preferred = 1', 'auto') for r in results: primer2Dict[r['name']] = r['accID'] # cache all MIT primer/marker relationships using primers cached by UniSTS ID results = db.sql('select a.accID, p.stsID, p.name, m.chromosome, m.symbol ' + \ 'from #primers p, PRB_Marker pm, MRK_Marker m, ACC_Accession a ' + \ 'where p._Probe_key = pm._Probe_key ' + \ 'and pm._Marker_key = m._Marker_key ' + \ 'and pm._Marker_key = a._Object_key ' + \ 'and a._MGIType_key = 2 ' + \ 'and a._LogicalDB_key = 1 ' + \ 'and a.prefixPart = "MGI:" ' + \ 'and a.preferred = 1', 'auto') for r in results: if not markerDict.has_key(r['name']): markerDict[r['name']] = [] markerDict[r['name']].append(r) # cache all MIT primer/marker relationships using primers cached by J:34136 results = db.sql('select a.accID, p.name, m.chromosome, m.symbol ' + \ 'from #primers2 p, PRB_Marker pm, MRK_Marker m, ACC_Accession a ' + \ 'where p._Probe_key = pm._Probe_key ' + \ 'and pm._Marker_key = m._Marker_key ' + \ 'and pm._Marker_key = a._Object_key ' + \ 'and a._MGIType_key = 2 ' + \ 'and a._LogicalDB_key = 1 ' + \ 'and a.prefixPart = "MGI:" ' + \ 'and a.preferred = 1', 'auto') for r in results: if not marker2Dict.has_key(r['name']): marker2Dict[r['name']] = [] marker2Dict[r['name']].append(r)
def init(): global diagFile, errorFile, inputFile, errorFileName, diagFileName global strainFile, markerFile, accFile, annotFile global noteFile db.useOneConnection(1) db.set_sqlUser(user) db.set_sqlPasswordFromFile(passwordFileName) fdate = mgi_utils.date('%m%d%Y') # current date head, tail = os.path.split(inputFileName) diagFileName = tail + '.' + fdate + '.diagnostics' errorFileName = tail + '.' + fdate + '.error' try: diagFile = open(diagFileName, 'w') except: exit(1, 'Could not open file %s\n' % diagFileName) try: errorFile = open(errorFileName, 'w') except: exit(1, 'Could not open file %s\n' % errorFileName) try: inputFile = open(inputFileName, 'r', encoding="latin-1") except: exit(1, 'Could not open file %s\n' % inputFileName) try: strainFile = open(strainFileName, 'w') except: exit(1, 'Could not open file %s\n' % strainFileName) try: markerFile = open(markerFileName, 'w') except: exit(1, 'Could not open file %s\n' % markerFileName) try: accFile = open(accFileName, 'w') except: exit(1, 'Could not open file %s\n' % accFileName) try: noteFile = open(noteFileName, 'w') except: exit(1, 'Could not open file %s\n' % noteFileName) try: annotFile = open(annotFileName, 'w') except: exit(1, 'Could not open file %s\n' % annotFileName) # Log all SQL db.set_sqlLogFunction(db.sqlLogAll) diagFile.write('Start Date/Time: %s\n' % (mgi_utils.date())) diagFile.write('Server: %s\n' % (db.get_sqlServer())) diagFile.write('Database: %s\n' % (db.get_sqlDatabase())) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) return