def _generate_code_concepts(self): try: self.code_cui=shelve.open(self._concepts_file + ".by_code", flag='r') except: self.code_cui=shelve.open(self._concepts_file + ".by_code") for c in self.concepts: self.code_cui[self.concepts[c].RxCUI]=c self.code_cui.close() self.code_cui=shelve.open(self._concepts_file + ".by_code", flag='r') return
def __init__(self, concepts_file, relations_file, ingredients_file): self._concepts_file = concepts_file self._relations_file = relations_file self._ingredients_file = ingredients_file # 'concepts' is a dictionary of Drug objects indexed by CUI self.concepts = shelve.open(self._concepts_file) # 'relations' is a list of Relation objects self._relations = shelve.open(self._relations_file) # 'formulas' is a dictionary of sets of Drug objects indexed # by the CUI of the drug of which they are a formulation self.formulas = shelve.open(self._ingredients_file) self._tradename_relations = None self._generate_code_concepts()
def __setstate__(self, state): global type_kinds global reverse_type_kinds curdir=os.path.dirname(__file__) self._concepts_file=state['c'] self._relations_file=state['r'] self._ingredients_file=state['f'] try: self.concepts = shelve.open(self._concepts_file, flag='r') except: # If the file wasn't found, try the current directory (necessary for the WSGI version). self._concepts_file=os.path.join(curdir, self._concepts_file) self.concepts = shelve.open(self._concepts_file, flag='r') try: self._relations = shelve.open(self._relations_file, flag='r') except: self._relations_file = os.path.join(curdir, self._relations_file) self._relations = shelve.open(self._relations_file, flag='r') try: self.formulas = shelve.open(self._ingredients_file, flag='r') except: self._ingredients_file=os.path.join(curdir, self._ingredients_file) self.formulas=shelve.open(self._ingredients_file, flag='r') type_kinds = state['t'] reverse_type_kinds = state['rt'] self._tradename_relations = None self._generate_code_concepts()
def __init__(self, rxnorm, treatment, drug_problem=None, concept_name_index=None): self._rxnorm = rxnorm self._treatment = treatment self._drug_problem = drug_problem concept_names = {} if concept_name_index is not None: self._concept_names = shelve.open(concept_name_index, flag='r') return for c in rxnorm.concepts: cn = rxnorm.concepts[c]._name.lower() cn = cn.split('@')[0].strip() # Just use stuff to the left of a @ for a concept name if cn in concept_names: concept_names[cn].add(c) else: concept_names[cn] = set([c]) # Use a shelf for self._concept_names = concept_names
def __init__(self, rxnorm, treatment, drug_problem=None, concept_name_index=None): self._rxnorm = rxnorm self._treatment = treatment self._drug_problem = drug_problem concept_names = {} if concept_name_index is not None: self._concept_names = shelve.open(concept_name_index, flag='r') return for c in rxnorm.concepts: cn = rxnorm.concepts[c]._name.lower() cn = cn.split('@')[0].strip( ) # Just use stuff to the left of a @ for a concept name if cn in concept_names: concept_names[cn].add(c) else: concept_names[cn] = set([c]) # Use a shelf for self._concept_names = concept_names
print >> sys.stderr, "Ingredients for 10 random drugs:" for x in [random.choice(ingredients.keys()) for x in xrange(10)]: print >> sys.stderr, "Ingredients for", concepts[x]._name, ":", [y for y in ingredients[x]] print >> sys.stderr, "Ingredients that are Pharmacologic Substances for", concepts[x]._name, ":", ', '.join( y._name for y in ingredients[x] if 'Pharmacologic Substance' in y.semtypes) print zoloft = concept_names['zoloft'] for z in zoloft: print >> sys.stderr, "Ingredients for", concepts[z]._name, ":", [y for y in ingredients[z]] conc_file = "concepts." + save_file print >> sys.stderr, "Shelving concepts to", conc_file #conc_shelf = dbmaccess.open(conc_file, protocol=pickle.HIGHEST_PROTOCOL) conc_shelf = shelve.open(conc_file, protocol=pickle.HIGHEST_PROTOCOL) count = 0 for c in concepts: conc_shelf[c] = concepts[c] count += 1 display_count(count) conc_shelf.close() print >> sys.stderr ing_file = "ingredients." + save_file print >> sys.stderr, "Shelving ingredients to", ing_file ing_shelf = shelve.open(ing_file, protocol=pickle.HIGHEST_PROTOCOL) count = 0 for i in ingredients: ing_shelf[i] = ingredients[i]