Beispiel #1
0
def Main(args):

    # The logger!!
    logger = Logger(DATA_DIR)

    try:

        # Let's set ourselves up for success!
        runtimeArgs = Setup()

        # Let's make the dialog box:
        DialogBox = WgstDlg()
        if not DialogBox.Show():
            bns.Stop()

        # Start the calculation
        Run(runtimeArgs)

    except:
        e = traceback.format_exc()
        logger._log(e)
        MessageBox('Error', e, '')

    finally:
        logger._save()
Beispiel #2
0
def Main(args):
	
	winId = 1
	
	#pick up previously used settings
	tmpNameFieldId = ''
	tmpNameHistoryFieldId = ''
	tmpCharViewId = ''
	tmpThresholds = [0.5, 1, 5, 10]
	tmpSplitNames = False
	tmpMinPresenceThreshold = 0.95

	settingsKey = "hierarchical_strain_nomenclature"
	settings = bns.Database.Db.Info.LoadSetting(settingsKey, True)
	if settings:
		root = ET.fromstring(settings)
		n = root.find('nameFieldId')
		if n is not None: tmpNameFieldId = n.text
		
		n = root.find('nameHistoryFieldId')
		if n is not None: tmpNameHistoryFieldId = n.text
		
		n = root.find('charViewId')
		if n is not None: tmpCharViewId = n.text
		
		n = root.find('thresholds')
		if n is not None: tmpThresholds = [float(f) for f in n.text.split('|')]

		n = root.find('splitNames')
		if n is not None: tmpSplitNames = n.text == '1'
		
		n = root.find('minPresenceThreshold')
		if n is not None: tmpMinPresenceThreshold = float(n.text)
		
		
	#show the dialog
	currSchema = Schema.GetCurrent()
	wgmlstExperType = bns.Database.ExperimentType(currSchema.WgMLSTExperTypeID)
	
	dlg = CalcStrainNamesDlg(wgmlstExperType, tmpNameFieldId, tmpNameHistoryFieldId, tmpCharViewId, tmpThresholds, tmpSplitNames, tmpMinPresenceThreshold)
	if not dlg.Show():
		bns.Stop()
		
	#store the current settings
	settings = ET.Element("hierarchical_strain_nomenclature_settings")
	ET.SubElement(settings, 'nameFieldId').text = dlg.selectedField
	ET.SubElement(settings, 'nameHistoryFieldId').text = dlg.selectedHistoryField
	ET.SubElement(settings, 'charViewId').text = dlg.selectedCharView
	ET.SubElement(settings, 'thresholds').text = '|'.join(str(f) for f in dlg.selectedThresholds)
	ET.SubElement(settings, 'splitNames').text = '1'if  dlg.selectedSplitNames else '0'
	ET.SubElement(settings, 'minPresenceThreshold').text = str(dlg.minPresenceThreshold)
	settings = bns.Database.Db.Info.SaveSetting(settingsKey, ET.tostring(settings), True)
		
	#calculate the damn thing
	allNamesFlName = os.path.join(bns.Database.Db.Info.SourceFilesDir, '9strain_naming_names_{}_{}.txt.gz'.format(wgmlstExperType.ID, dlg.selectedCharView))
	allProfilesFlName = os.path.join(bns.Database.Db.Info.SourceFilesDir, '9strain_naming_profiles_{}_{}.txt.gz'.format(wgmlstExperType.ID, dlg.selectedCharView))
	
	ok = os.path.isfile(allNamesFlName) and os.path.isfile(allProfilesFlName)
	if not ok:
		#put out a warning
		
		#delete files if only one is present
		if os.path.isfile(allNamesFlName): os.remove(allNamesFlName)
		if os.path.isfile(allProfilesFlName): os.remove(allProfilesFlName)
		
	calculator = Calculator(wgmlstExperType, dlg.selectedField, dlg.selectedHistoryField, dlg.selectedCharView, dlg.selectedThresholds, dlg.selectedSplitNames, dlg.minPresenceThreshold, allNamesFlName, allProfilesFlName)
	#calculator.DoCalc({})
	
	bns.Windows.BnsWindow(winId).StartAsyncCalculation(calculator.DoCalc, calculator.DoRefresh, async=False)