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(): # 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(): ''' # 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(): # 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 init(): ''' # requires: # # effects: # 1. Processes command line options # 2. Initializes local DBMS parameters # 3. Initializes global file descriptors/file names # # returns: # ''' global inputFile, diagFile, errorFile, errorFileName, diagFileName global passwordFileName global noteFile, noteFileName, noteChunkFile, noteChunkFileName, sqlFile, sqlFileName global mode global noteTypeName global objectTypeKey, createdByKey global mgiObjects try: optlist, args = getopt.getopt(sys.argv[1:], 'S:D:U:P:M:I:O:T:') except: showUsage() # # Set server, database, user, passwords depending on options # specified by user. # server = None database = None user = None password = None 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] == '-O': objectType = opt[1] elif opt[0] == '-T': noteTypeName = re.sub('"', '', opt[1]) else: showUsage() # Initialize db.py DBMS parameters password = string.strip(open(passwordFileName, 'r').readline()) db.set_sqlLogin(user, password, server, database) db.useOneConnection(1) head, tail = os.path.split(inputFileName) diagFileName = tail + '.diagnostics' errorFileName = tail + '.error' noteFileName = tail + '.' + noteTable + '.bcp' noteChunkFileName = tail + '.' + noteChunkTable + '.bcp' sqlFileName = tail + '.sql' 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: 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: sqlFile = open(sqlFileName, 'w') except: exit(1, 'Could not open file %s\n' % sqlFileName) # Set Log File Descriptor try: db.set_sqlLogFD(diagFile) except: pass 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)) diagFile.write('Object Type: %s\n' % (objectType)) diagFile.write('Note Type: %s\n' % (noteTypeName)) errorFile.write('Start Date/Time: %s\n\n' % (mgi_utils.date())) objectTypeKey = accessionlib.get_MGIType_key(objectType) createdByKey = loadlib.verifyUser(db.get_sqlUser(), 0, errorFile) results = db.sql(''' select accID, _Object_key from ACC_Accession where _MGIType_key = %s and _LogicalDB_key = 1 and prefixPart = 'MGI:' and preferred = 1 ''' % (objectTypeKey), 'auto') for r in results: mgiObjects[r['accID']] = r['_Object_key']
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(): # 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 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()))