library(ontologyIndex)
phe_dat = as.matrix(read.csv('/home/starjjbang/Storage/part1/SAAVpedia/data/anno_file/tmp/9_ESP_1000G_pheno_drug_PTM_ontology_function.txt',sep='\t',header = FALSE, row.names = NULL))
of = '/home/starjjbang/Storage/part1/SAAVpedia/data/ontology/efo.obo'
efo = get_OBO(of, propagate_relationships = "is_a", extract_tags = "everything")
data(hpo)
tmp1 = rep('NA',nrow(phe_dat))
for(i in 1:nrow(phe_dat))
{
term = phe_dat[i,41]
if (is.na(term)==FALSE)
{
if(term=="COSMIC"){ tmp1[i] = "cancer" }
else if ( grepl('^Orphanet',term)) { tmp1[i] = "rare disease" }
else if ( grepl('^EFO',term))
{
p_id =get_term_property(ontology=efo, property="ancestors", term=term, as_names=TRUE)
if("EFO:0000408" %in% names(p_id)){tmp1[i] = p_id[which(names(p_id) == "EFO:0000408") +1]}
else if ("EFO:0004725" %in% names(p_id)){tmp1[i] = p_id[which(names(p_id) == "EFO:0004725") +1]}
else {tmp1[i] = 'ETC'}
}
else if ( grepl('^HP',term))
{
if(is.na(hpo$id["HP:0025268"]) == FALSE)
{
p_id =get_term_property(ontology=hpo, property="ancestors", term=term, as_names=TRUE)
if("HP:0000118" %in% names(p_id)){tmp1[i] = p_id[which(names(p_id) == "HP:0000118") +1]}
else {tmp1[i] = 'ETC'}
}
}
else {tmp1[i] = 'ETC'}
}
}