Ejemplo n.º 1
0
def updateDatabase(cmds):
    dbServer = os.environ['MGD_DBSERVER']
    dbName = os.environ['MGD_DBNAME']
    dbUser = os.environ['MGD_DBUSER']
    dbPasswordFile = os.environ['MGD_DBPASSWORDFILE']
    dbPassword = string.strip(open(dbPasswordFile, 'r').readline())
    db.set_sqlLogin(dbUser, dbPassword, dbServer, dbName)

    # process in batches of 100
    total = len(cmds)

    try:
        db.useOneConnection(1)
        while cmds:
            print('Current running time (secs): %s' %
                  (time.time() - STARTTIME))
            db.sql(cmds[:100], 'auto')
            cmds = cmds[100:]
        db.useOneConnection(0)
    except:
        bailout('Failed during database updates')

    print('Processed %d updates to SEQ_Sequence._SequenceStatus_key' % total)
    print('Total running time (secs): %s' % (time.time() - STARTTIME))
    return
Ejemplo n.º 2
0
def init():
    # Purpose: initialize file descriptors, create connection to
    #  the database and load lookups
    # Returns: nothing
    # Assumes: nothing
    # Effects: gives SQL commands to the database
    # Throws: nothing
    global inFile, outFile, nextKey

    print('%s' % mgi_utils.date())
    print('Initializing')

    db.useOneConnection(1)
    db.set_sqlLogin(user, password, mgdServer, mgdDB)

    results = db.sql(
        '''select max(_Assoc_key) + 1 as nextKey from %s''' % table, 'auto')
    nextKey = results[0]['nextKey']
    if nextKey == None:
        nextKey = 1001

    inFilePath = os.environ['INFILE_NAME']
    try:
        inFile = open(inFilePath, 'r')
    except:
        exit('Could not open file for reading %s\n' % inFilePath)

    outFilePath = '%s/%s.bcp' % (os.environ['OUTPUTDIR'], table)
    try:
        outFile = open(outFilePath, 'w')
    except:
        exit('Could not open file for writing %s\n' % outFilePath)

    loadLookups()
Ejemplo n.º 3
0
def init():
    # Purpose: initialize file descriptors, create connection to
    #  the database and load lookups
    # Returns: nothing
    # Assumes: nothing
    # Effects: gives SQL commands to the database
    # Throws: nothing
    global inFile, outFile, nextKey

    print '%s' % mgi_utils.date()
    print 'Initializing'
   
    db.useOneConnection(1)
    db.set_sqlLogin(user, password, mgdServer, mgdDB)
 
    results = db.sql('''select max(_Assoc_key) + 1 as nextKey from %s''' % table, 'auto')
    nextKey = results[0]['nextKey']
    if nextKey == None:
	nextKey = 1001

    inFilePath = os.environ['INFILE_NAME']
    try:
	inFile = open(inFilePath, 'r')
    except:
	exit('Could not open file for reading %s\n' % inFilePath)

    outFilePath = '%s/%s.bcp' % (os.environ['OUTPUTDIR'],  table)
    try:
	outFile = open(outFilePath, 'w')
    except:
        exit('Could not open file for writing %s\n' % outFilePath)

    loadLookups()
Ejemplo n.º 4
0
def setupSql (server,   # str. name of database server
    database,   # str. name of database
    username,   # str. user with full permissions on database
    password    # str. password for 'username'
    ):
    # Purpose: initialize the 'db' module to use the desired database
    #   login information
    # Returns: nothing
    # Assumes: the parameters are all valid
    # Effects: initializes the 'db' module with the given login info, and
    #   tells it to use one connection (rather than a separate
    #   connection for each db.sql() call)
    # Throws: nothing

    db.set_sqlLogin (username, password, server, database)
    db.useOneConnection(1)
    return
Ejemplo n.º 5
0
def parseCommandArgs():
	"""
	Reads in command line args,
		prints usage if necessary
	if successful, inits db and returns assayKey
	"""

	try:
		optlist, args = getopt.getopt(sys.argv[1:], 'S:D:U:P:K:')
	except:
		showUsage()

	server = None
	database = None
	user = None
	password = None
	assayKey = 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':
			password = string.strip(open(opt[1], 'r').readline())
		elif opt[0] == '-K':
			assayKey = string.atoi(opt[1])
		else:
			showUsage()

	if server is None or \
	   database is None or \
	   user is None or \
	   password is None or \
	   assayKey is None:
		showUsage()

	db.set_sqlLogin(user, password, server, database)

	return assayKey
def readCommandLine():
    """
    Read command line input
    returns options
    """
    parser = OptionParser(usage=USAGE)
    
    parser.add_option("-S", dest="dbServer")
    parser.add_option("-D", dest="dbName")
    parser.add_option("-U", dest="dbUser")
    parser.add_option("-P", dest="passwordFile")
    parser.add_option("-K", dest="evidenceKey")

    (options, args) = parser.parse_args()

    if options.dbServer or options.dbName \
        or options.dbUser or options.passwordFile:
        
        if not options.dbServer:
            parser.error('Need to specify -S dbServer')
            
        if not options.dbName:
            parser.error('Need to specify -D dbName')
            
        if not options.dbUser:
            parser.error('Need to specify -U dbUser')
        
        if not options.passwordFile:
            parser.error('Need to specify -P passwordFile')
            
        password = password = open(options.passwordFile, 'r').readline().strip()

        # set the server and database settings
        db.set_sqlLogin(options.dbUser, password, options.dbServer, options.dbName)
        
    else:
        # using default database options
        pass
    
    
    return options
Ejemplo n.º 7
0
		user = opt[1]
	elif opt[0] == '-P':
		password = string.strip(open(opt[1], 'r').readline())
	elif opt[0] == '-K':
		objectKey = opt[1]
	else:
		showUsage()

if server is None or \
   database is None or \
   user is None or \
   password is None or \
   objectKey is None:
	showUsage()

db.set_sqlLogin(user, password, server, database)
db.useOneConnection(1)
userKey = loadlib.verifyUser(user, 0, None)

# call functions based on the way the program is invoked

scriptName = os.path.basename(sys.argv[0])

# all of these invocations will only affect a certain subset of data


if scriptName == 'allelecombination.py':
    processAll()

elif scriptName == 'allelecombinationByAllele.py':
    processByAllele(objectKey)
Ejemplo n.º 8
0
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']
Ejemplo n.º 9
0
def loadLookup():
    global seqsToToggleList

    db.set_sqlLogin(user, password, server, database)
    db.useOneConnection(1)
    cmds = []

    # get eucomm mutant cell lines (MCLs)
    cmds.append('''select c._CellLine_key
        into temporary table eucommCL
        from  ALL_CellLine c, ALL_CellLine_Derivation d
        where d._Creator_key = 4856374
        and d._Derivation_key = c._Derivation_key''')

    cmds.append('create index idx_1 on eucommCL(_CellLine_key)')

    # get sequences associated with  eucomm MCLs (via the allele)
    cmds.append('''select t._CellLine_key, saa._Sequence_key
    into temporary table eucommSeq
    from eucommCL t, ALL_Allele_CellLine aac, SEQ_Allele_Assoc saa
    where t._CellLine_key = aac._MutantCellLine_key
    and aac._Allele_key = saa._Allele_key''')

    cmds.append('create index idx_2 on eucommSeq(_Sequence_key)')

    # filter for just the upstream vector end and get the seqID
    cmds.append('''select t.*, a.accID
    into temporary table eucommUpstSeq
    from eucommSeq t, SEQ_GeneTrap sgt, ACC_Accession a
    where t._Sequence_key = sgt._Sequence_key
    and sgt._VectorEnd_key = 3983010
    and sgt._Sequence_key = a._Object_key
    and a._MGIType_key = 19
    and a._LogicalDB_key = 9
    and a.preferred = 1''')

    # get tigem MCLs
    cmds.append('''select c._CellLine_key
    into temporary table tigemCL
    from  ALL_CellLine c, ALL_CellLine_Derivation d
    where d._Creator_key = 3982963
    and d._Derivation_key = c._Derivation_key''')

    cmds.append('create index idx_3 on tigemCL(_CellLine_key)')

    # get sequences associated with tigem MCLs (via allele)
    cmds.append('''select t._CellLine_key, saa._Sequence_key
    into temporary table tigemSeq
    from tigemCL t, ALL_Allele_CellLine aac, SEQ_Allele_Assoc saa
    where t._CellLine_key = aac._MutantCellLine_key
    and aac._Allele_key = saa._Allele_key''')

    cmds.append('create index idx_4 on tigemSeq(_Sequence_key)')

    # get the seqID
    cmds.append('''select t.*, a.accID
    into temporary table tigemAccid
    from tigemSeq t, ACC_Accession a
    where t._Sequence_key  = a._Object_key
    and a._MGIType_key = 19
    and a._LogicalDB_key = 9
    and a.preferred = 1''')

    # union the eucomm and tigem sets
    cmds.append('''select t.accID
    into temporary table allSets
    from eucommUpstSeq t
    union
    select te.accID
    from tigemAccid te''')

    # load the lookup list
    cmds.append('select distinct * from allSets')
    results = db.sql(cmds, 'auto')
    for r in results[11]:
        seqID = r['accID']
        seqsToToggleList.append(seqID)
Ejemplo n.º 10
0
def processArgs ():
	# Purpose: process the command-line arguments to get us ready for
	#	real processing, including doing error-checking of the parms
	# Returns: tuple with seven items -- list of strings (input lines),
	#	string (vocab name), integer (vocab key), string (J#),
	#	integer (reference key), integer (logical db key), string
	#	(logical db name)
	# Assumes: the user account specified will have write privileges
	# Modifies: reads from the file system, queries the database
	# Throws: propagates SystemExit from bailout() if errors occur

	if len(sys.argv) < 9:
		bailout ('Too few command-line arguments')
	elif len(sys.argv) > 9:
		bailout ('Too many command-line arguments')

	[ file, vocab, jnum, ldb, user, pwd, server, dbname ] = sys.argv[1:]

	# see if we can read the input file, exit if not

	try:
		fp = open (file, 'r')
		inputLines = map (string.strip, fp.readlines())
		fp.close()
	except:
		bailout ('Cannot read input file: %s' % file)

	# see if we can read the password file, exit if not

	try:
		fp = open (pwd, 'r')
		password = fp.readline().strip()
		fp.close()
	except:
		bailout ('Cannot read password file: %s' % pwd)

	# see if we can log in to the database, exit if not

	db.set_sqlLogin (user, password, server, dbname)
	try:
		db.sql ('SELECT COUNT(1) FROM MGI_dbInfo', 'auto')
	except:
		bailout ('Database login failed')

	# try to look up the key for the given vocabulary name

	results = db.sql ('''SELECT _Vocab_key, _Refs_key, _LogicalDB_key
		FROM VOC_Vocab 
		WHERE name = '%s' ''' % vocab, 'auto')
	if not results:
		vocabKey = None
		dbRefsKey = None
		dbLdbKey = None
	else:
		vocabKey = results[0]['_Vocab_key']
		dbRefsKey = results[0]['_Refs_key']
		dbLdbKey =  results[0]['_LogicalDB_key']

	# try to look up the key for the given J#

	results = db.sql ('''SELECT _Object_key
		FROM ACC_Accession
		WHERE _MGIType_key = 1		-- reference
			AND _LogicalDB_key = 1	-- MGI
			AND accID = '%s' ''' % jnum, 'auto')
	if not results:
		bailout ('Unknown reference ID: %s' % jnum)
	refsKey = results[0]['_Object_key']

	if dbRefsKey and (dbRefsKey != refsKey):
		bailout ('Mismatching _Refs_key: %s has %d, vocab has %d' % \
			(jnum, refsKey, dbRefsKey))

	# confirm that ldb is a valid logical database key

	try:
		ldbKey = int(ldb)
	except:
		bailout ('Invalid _LogicalDB_key: %s not an integer' % ldb)

	results = db.sql ('''SELECT name
		FROM ACC_LogicalDB
		WHERE _LogicalDB_key = %d''' % ldbKey, 'auto')
	if not results:
		bailout ('Unknown _LogicalDB_key: %d' % ldbKey)
	ldbName = results[0]['name']

	if dbLdbKey and (dbLdbKey != ldbKey):
		bailout ('Mismatching _LogicalDB_key: vocab has %d, not %d' \
			% (dbLdbKey, ldbKey))

	return inputLines, vocab, vocabKey, jnum, refsKey, ldbKey, ldbName
Ejemplo n.º 11
0
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()))
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
#	- Added FILETYPE
#

import sys
import os
import db

#
# Main
#

server = os.environ['RADAR_DBSERVER']
database = os.environ['RADAR_DBNAME']
user = os.environ['RADAR_DBUSER']
passwordFileName = os.environ['RADAR_DBPASSWORDFILE']
password = str.strip(open(passwordFileName, 'r').readline())
jobStreamKey = os.environ['JOBSTREAMKEY']
fileName = os.environ['FILENAME']
fileType = os.environ['FILETYPE']

# Initialize db.py DBMS parameters
db.set_sqlLogin(user, password, server, database)
db.useOneConnection(1)

# Log the processed file
db.sql(
    "select * from APP_logProcessedFile( %s, '%s', '%s')" %
    (jobStreamKey, fileName, fileType), None)
db.commit()
db.useOneConnection(0)
Ejemplo n.º 14
0
def main():
    global userKey

    try:
	    optlist, args = getopt.getopt(sys.argv[1:], 'S:D:U:P:K:')
    except:
	    showUsage()

    server = None
    database = None
    user = None
    password = None
    objectKey = 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':
		    password = string.strip(open(opt[1], 'r').readline())
	    elif opt[0] == '-K':
		    objectKey = opt[1]
	    else:
		        showUsage()

    if server is None or \
       database is None or \
       user is None or \
       password is None or \
       objectKey is None:
	    showUsage()

    db.set_sqlLogin(user, password, server, database)
    db.useOneConnection(1)

    userKey = loadlib.verifyUser(user, 0, None)

    # call functions based on the way the program is invoked

    scriptName = os.path.basename(sys.argv[0])

    # initialize the cre-system lookups
    initCreSystems()

    # all of these invocations will only affect a certain subset of data

    if scriptName == 'allelecrecache.py':
        processAll()
    
    elif scriptName == 'allelecrecacheByAllele.py':
        processByAllele(objectKey)
    
    elif scriptName == 'allelecrecacheByAssay.py':
        processByAssay(objectKey)

    db.commit()
    db.useOneConnection(0)

    return
Ejemplo n.º 15
0
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()))