def __init__(self): """Initialize brain class of Sara.""" self.log = logging.getLogger() self.log.info('initialize brain...') self.config = configs.default_obj() if os.path.exists('user.json'): self.config = configs.update(self.config, 'user.json') self.speech = Speech(self.config.speech) self.speech.speak("Load language: " + self.config.language.name[self.config.language.code]) self.phrases = configs.language_obj(self.config.language.languages_dir, self.config.language.code) self.help = Help(self.config.language, self.phrases) self.speech.speak(self.phrases.general.start) self.generals = {'quit': False, 'text': '', 'arg': None} self.bd = Databases(self.config.sqlite) self.assist = Assistant(self.speech, self.config, self.phrases, self.bd) if True if "true" == self.config.general.setup else False: self.assist.setup() self.backups = Backups(self.config.backups, self.bd) self.hotkeys = Hotkeys(self.config.hotkeys, self.generals) self.recognizer = Recognizer(self.config.recognition, self.config.language.code, self.generals, self.speech, self.phrases.recognition)
def __init__(self, output_directory, ko, pfam, tigrfam, cog, hypothetical, evalue, bit, id, aln_query, aln_reference, cascaded, c, threads, parallel, suffix): # Define inputs and outputs self.output_directory = output_directory self.gff_directory = os.path.join(output_directory, ) # Define type of annotation to be carried out self.ko = ko self.pfam = pfam self.tigrfam = tigrfam self.cog = cog self.hypothetical = hypothetical # Cutoffs self.evalue = evalue self.bit = bit self.id = id self.aln_query = aln_query self.aln_reference = aln_reference self.cascaded = cascaded self.c = c # Parameters self.threads = threads self.parallel = parallel self.suffix = suffix # Load databases self.databases = Databases()
def __init__(self): d=Databases() self.ko_re = re.compile('^K\d+$') self.signature_modules = d.signature_modules self.m2def = d.m2def self.m = d.m
def __init__(self, metadata_keys): self.d = Databases() self.metadata_keys \ = metadata_keys self.matrix_header \ = ["compound", "reaction"] + \ [key + '_reaction_metagenome' for key in self.metadata_keys] self.transcriptome_header \ = [key + '_reaction_transcriptome' for key in self.metadata_keys] + \ [key + '_reaction_expression' for key in self.metadata_keys] self.compound_header \ = [key + '_compound' for key in self.metadata_keys] self.metadata_header \ = ['node', 'description', 'type', 'module', 'module_descr', 'pathway', 'pathway_descr', 'node_type'] self.query_header \ = ['query', 'step'] self.compound_reaction_index_header \ = [] self.step_header = ['step']
def __init__(self, matrix, transcriptome): d = Databases() self.r2k = d.r2k logging.info("Parsing input matrix: %s" % matrix) self.orthology_matrix \ = self._parse_matrix(matrix) logging.info("Calculating reaction abundances") self.reaction_matrix \ = self._calculate_abundances(self.r2k, self.orthology_matrix) if transcriptome: logging.info("Parsing input transcriptome: %s" % transcriptome) self.orthology_matrix_transcriptome \ = self._parse_matrix(transcriptome) logging.info("Calculating reaction transcriptome abundances") self.reaction_matrix_transcriptome \ = self._calculate_abundances(self.r2k, self.orthology_matrix_transcriptome) logging.info("Calculating normalized expression abundances") self.orthology_matrix_expression \ = self._calculate_expression_matrix(self.orthology_matrix, self.orthology_matrix_transcriptome) logging.info("Calculating reaction expression abundances") self.reaction_matrix_expression \ = self._calculate_abundances(self.r2k, self.orthology_matrix_expression)
def __init__(self, genome_annotations, modules, genomes, groups, annotation_type, threshold, multi_test_correction, pval_cutoff): ''' Parameters ---------- Output ------ ''' d = Databases() self.IVI_OUTPUT = 'ivi_results.tsv' self.IVG_OUTPUT = 'ivg_results.tsv' self.GVG_OUTPUT = 'gvg_results.tsv' self.threshold = threshold self.multi_test_correction = multi_test_correction self.m2def = d.m2def self.m = d.m self.clan2pfam = d.clan2pfam self.clan_to_description = d.clan2name self.modules = modules self.genomes = genomes self.annotation_type = annotation_type self.groups = groups self.pval_cutoff = pval_cutoff if annotation_type == Enrichment.PFAM: self.genome_annotations = {} for key, item in genome_annotations.items(): self.genome_annotations[key] = set( [x.split('.')[0] for x in item]) else: self.genome_annotations = genome_annotations self.pfam = {} self.id2pfam = {} for line in open(d.PFAM_CLAN_DB): sline = line.strip().split() pfam = sline[0] clan = sline[1] id = sline[2] description = "%s; %s" % (id, ' '.join(sline[2:])) self.pfam[pfam] = description self.id2pfam[id] = pfam
class Brain: """The brain class of Sara.""" def __init__(self): """Initialize brain class of Sara.""" self.log = logging.getLogger() self.log.info('initialize brain...') self.config = configs.default_obj() if os.path.exists('user.json'): self.config = configs.update(self.config, 'user.json') self.speech = Speech(self.config.speech) self.speech.speak("Load language: " + self.config.language.name[self.config.language.code]) self.phrases = configs.language_obj(self.config.language.languages_dir, self.config.language.code) self.help = Help(self.config.language, self.phrases) self.speech.speak(self.phrases.general.start) self.generals = {'quit': False, 'text': '', 'arg': None} self.bd = Databases(self.config.sqlite) self.assist = Assistant(self.speech, self.config, self.phrases, self.bd) if True if "true" == self.config.general.setup else False: self.assist.setup() self.backups = Backups(self.config.backups, self.bd) self.hotkeys = Hotkeys(self.config.hotkeys, self.generals) self.recognizer = Recognizer(self.config.recognition, self.config.language.code, self.generals, self.speech, self.phrases.recognition) def mainloop(self): """Run main loop method.""" self.log.info('run brain mainloop...') while True: self.recognizer.recognize() if self.generals['quit']: break self.check(self.generals['text']) self.assist.check(self.generals['text'], self.generals['arg']) self.generals['text'] = '' self.generals['arg'] = None time.sleep(0.1) self.quit() def quit(self): """Quit method from Sara.""" self.log.info('quit Sara...') self.speech.speak(self.phrases.general.finish) self.bd.disconnect() self.hotkeys.clear() self.recognizer.finish() def reset(self): """Reset assistant brain of Sara.""" self.log.info('reset assistant...') self.speech.speak(self.phrases.general.reset) self.assist.reset() def check(self, text): """Check need actions for use.""" if 'abort' == text: self.speech.abort() elif 'help' == text: self.help.show_help() elif 'help_browser' == text: self.help.show_browser() elif 'features' == text: self.help.show_features() elif 'backup_bd' == text: self.speech.speak(self.phrases.backup.bd) self.backups.backup_bd() elif 'backup_user_data' == text: self.speech.speak(self.phrases.backup.user_data) self.backups.backup_user_data() elif 'backup_all' == text: self.speech.speak(self.phrases.backup.all) self.backups.backup_all() elif 'restore_bd' == text: self.speech.speak(self.phrases.restore.bd) self.backups.restore_bd() self.reset() elif 'restore_user_data' == text: self.speech.speak(self.phrases.restore.user_data) self.backups.restore_user_data() elif 'restore_all' == text: self.speech.speak(self.phrases.restore.all) self.backups.restore_all() self.reset()
except RuntimeError: continue else: image_1.save_image() img = Image.open('image_1.png') img.show() break elif command == "2": while True: image_2 = Images("image_2.png", "RGB", 500, 500, "black") try: image_2.draw_on_image_version_2(database, 500, 500) except RuntimeError: continue else: image_2.save_image() img = Image.open('image_2.png') img.show() break else: print("Not a valid number") database = Databases("admin_data.csv", "base_data.sql") try: database.connect_db() except ConnectionError: print("Uh oh, can't connect. Invalid dbname, user or password?") else: main()