def gen_pdm_from_indfile(ont_url, outfile):
    """Reads an owl file from ont_url; Writes a JSON file (outfile) of 
    types and annotations on individuals in the file.
    JSON structure: 
    id: 
       label: string
       def: string
       types:
         - isAnonymous:boolean; 
         - relId:URI_string; 
         - objectId:URI_string.
    """
    
    ont = Brain()
    ont.learn(ont_url)
    axioms = {}
    if ont.knowsClass("CARO_0030002"):
        axioms.update(gen_pdm(ont, ont.getInstances("CARO_0030002", 0), "CARO_0030002")) # expression_patterns
    if ont.knowsClass("FBbt_00005106"):
        axioms.update(gen_pdm(ont, ont.getInstances("FBbt_00005106", 0), "FBbt_00005106")) # neurons
    if ont.knowsClass("FBbt_00007683"):
        axioms.update(gen_pdm(ont, ont.getInstances("FBbt_00007683", 0), "FBbt_00007683")) # clones
    jfile = open(outfile, "w")
    jfile.write(json.dumps(axioms, sort_keys=True, indent=4))
    ont.sleep()
Beispiel #2
0
def entity_check(SFID_list, cursor):
    class owl_entity(): # v.simple object for storing attributes of class
        ont = ''
        base = ''
        sfid = ''
        typ = ''
        
    ont_dict = {} # Dict to make a uniq'd list of ontologies
    sfid_oe = {} # Dict of owl_entities - as specified by DB
    for SFID in SFID_list:
        cursor.execute("SELECT DISTINCT ontology_URI AS ont, owl_type as typ, baseURI as base FROM owl_entity WHERE shortFormID = '%s'" % SFID)
        
        dc = dict_cursor(cursor)
        brain = Brain()
        sfo = owl_entity()
        for d in dc:
            ont = d['ont']
            if not ont in ont_dict:
                brain.learn(ont)
                ont_dict[ont] = brain
            sfo.ont = d['ont']
            sfo.base = d['base']
            sfo.typ = d['typ']
            
        sfid_oe[SFID] =  sfo

    for idt in sfid_oe.items():
        SFID = idt[0]
        owlEnt = idt[1]
        ont = owlEnt.ont
        brain = ont_dict[ont]
        #        if brain.getAnnotation(SFID, 'deprecated'): # Need to cope with cases where it is not deprecated!
        #            print SFID + ' is obsolete!' 
        if owlEnt.typ == 'class':
            if not brain.knowsClass(SFID):
                print 'Unknown Class SFID in ' + owlEnt.ont
        elif owlEnt.brain == 'objectProperty':
            if not ont.knowsClass(SFID):
                print 'Unknown objectProperty SFID in ' + owlEnt.ont
Beispiel #3
0
known_term_list = []

for term in tc:
	oboid = term["extId"][0]
	known_term_list.append(oboid)
	if oboid in oboid_domId:
		if "domainId" in term["domainData"]:
			term["domainData"]["domainId"] = oboid_domId[oboid] # Terns that didn't formerly have domainId will not, at the point
		else:
			term["domainData"] = {"domainColour": [0,128,128,127],"domainId": oboid_domId[oboid],"domainSelected": "false"} # Setting default colour - will need to fix.
	else:
		if "domainId" in term["domainData"]:
			term["domainData"]["domainId"] = '' # Remove old domain_id, if present.
		owl_id = re.sub(':','_',oboid)
		name = '';
		if fbbt.knowsClass(owl_id):
			name = fbbt.getLabel(owl_id)
		print "Ignoring %s %s as , according to the mapping file, it is not a painted domain." % (oboid, name)
	new_tc.append(term)

    
	# Adding records for any new terms
for oboid, domid in oboid_domId.items():
	if oboid not in known_term_list:
		new_tc.append({"domainData":{"domainColour": [0,128,128,127],"domainId": domid,"domainSelected": "false"}, "extId": [oboid],"nodeState": {"open": "false", "selected": "false"} }) # Anything generated here will need a new nodeId.

update_names(new_tc, fbbt)

fbbt.sleep()

write_json(new_tc, "../json/treeContent_JFRC_BN_final.jso")    
	query = "SELECT DISTINCT f.uniquename AS fbid, synonym_sgml AS uc_name, f.is_obsolete as obstat " \
	"FROM synonym s " \
	"JOIN cvterm typ ON (typ.cvterm_id=s.type_id) " \
	"JOIN feature_synonym fs ON (fs.synonym_id=s.synonym_id) " \
	"JOIN feature f ON (f.feature_id=fs.feature_id) " \
	"WHERE f.uniquename in (%s) and fs.is_current IS TRUE and typ.name = 'symbol'" % (class_list_string)
	
	fb_cursor.execute(query)  # 
	
	fb_dc = dict_cursor(fb_cursor)
	for fb in fb_dc:
#		print "\nProcessing:" + fb['uc_name']
		if fb['obstat']:
			warnings.warn(fb['fbid'] +" " + fb['uc_name'] + " is obsolete !  Not adding to fb_feature.owl.") 
		else:
			if not fb_feature.knowsClass(fb['fbid']): # Only add class if not obsolete.
				fb_feature.addClass(fb['fbid'])
				tmp = re.sub("<up\>", "[",fb['uc_name'])
				uc_name = re.sub("<\/up>", "]", tmp)
				fb_feature.label(fb['fbid'], uc_name)
				if re.match('FBtp\d+', fb['fbid']):
					fb_feature.subClassOf(fb['fbid'], 'SO_0000796')
				elif re.match('FBti\d+', fb['fbid']):
					fb_feature.subClassOf(fb['fbid'], 'SO_0001218')
				elif re.match('FBgn\d+', fb['fbid']):
					fb_feature.subClassOf(fb['fbid'], 'SO_0000704')
				elif re.match('FBal\d+', fb['fbid']):
					fb_feature.subClassOf(fb['fbid'], 'SO_0001023')
				else:
					warnings.warn("Ignoring this, as doesn't look like an FB feature: %s."  % fb['fbid'])
					continue