Skip to content

Commit b04a2f2

Browse files
Merge pull request #444 from micheldumontier/master
changes around the board
2 parents 83f3c7c + 913d139 commit b04a2f2

File tree

6 files changed

+381
-184
lines changed

6 files changed

+381
-184
lines changed

bioportal/bioportal.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ function OBO2RDF($abbv)
394394
$graph_uri = '<'.parent::getRegistry()->getFQURI(parent::getGraphURI()).'>';
395395
$bid = 1;
396396

397-
while($l = parent::getReadFile()->read()) {
397+
while(FALSE !== ($l = parent::getReadFile()->read())) {
398398
$lt = trim($l);
399399
if(strlen($lt) == 0) continue;
400400
if($lt[0] == '!') continue;
@@ -676,7 +676,8 @@ function OBO2RDF($abbv)
676676
} else {
677677
//header
678678
//format-version: 1.0
679-
$buf .= parent::triplifyString($ouri,"obo_vocabulary:$a[0]",str_replace( array('"','\:'), array('\"',':'), isset($a[1])?$a[1]:""));
679+
$buf .= parent::triplifyString($ouri,"obo_vocabulary:$a[0]",
680+
str_replace( array('"','\:'), array('\"',':'), isset($a[1])?$a[1]:""));
680681
}
681682

682683
if($minimal || $minimalp) parent::getWriteFile()->write($min);

ctd/ctd.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,13 @@ function CTD_chem_pathways_enriched()
420420
return FALSE;
421421
}
422422
$first = false;
423-
}
424-
423+
}
425424
$chemical_id = $a[1];
426425

427426
$this->getRegistry()->parseQName($a[4], $pathway_ns, $pathway_id);
428427
if($pathway_ns == "react") $pathway_ns = "reactome";
429-
428+
if($pathway_ns == "kegg") $pathway_id = "map".$pathway_id;
429+
430430
$pathway_resource_id = parent::getRes().md5($chemical_id.$pathway_ns.$pathway_id.$a[6]);
431431
$pathway_resource_label = "Chemical-pathway association between mesh:".$chemical_id." and ".$pathway_ns.":".$pathway_id." with p-value ".$a[6];
432432

@@ -509,7 +509,8 @@ function CTD_diseases_pathways()
509509
$this->getRegistry()->parseQName($a[1],$disease_ns,$disease_id);
510510
$this->getRegistry()->parseQName($a[3],$pathway_ns,$pathway_id);
511511
if($pathway_ns == 'react') $pathway_ns = 'reactome';
512-
512+
if($pathway_ns == "kegg") $pathway_id = "map".$pathway_id;
513+
513514
$this->AddRDF(
514515
parent::triplify($disease_ns.":".$disease_id, $this->getVoc()."pathway", $pathway_ns.":".$pathway_id).
515516
parent::triplifyString($disease_ns.":".$disease_id, "rdfs:label", $a[0]." [$disease_ns:$disease_id]").
@@ -612,6 +613,7 @@ function CTD_genes_pathways()
612613
$this->getRegistry()->parseQName($a[3],$pathway_ns,$pathway_id);
613614
$pathway_id = trim($pathway_id);
614615
if($pathway_ns == "react") $pathway_ns = "reactome";
616+
if($pathway_ns == "kegg") $pathway_id = "map".$pathway_id;
615617

616618
$this->ADDRDF(
617619
parent::triplify($gene_ns.":".$gene_id, $this->getVoc()."pathway", $pathway_ns.":".$pathway_id).
@@ -645,7 +647,8 @@ function CTD_Pathways()
645647

646648
$this->getRegistry()->parseQName(trim($a[1]),$pathway_ns,$pathway_id);
647649
if($pathway_ns == "react") $pathway_ns = "reactome";
648-
650+
if($pathway_ns == "kegg") $pathway_id = "map".$pathway_id;
651+
649652
$this->AddRDF(
650653
parent::describeIndividual($pathway_ns.":".$pathway_id, $a[0], $this->getVoc()."Pathway").
651654
parent::describeClass($this->getVoc()."Pathway", "CTD Pathway")

drugbank/drugbank.php

+49-3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ function Run()
5656
if(parent::getParameterValue("id_list")) {
5757
$this->id_list = array_flip(explode(",",parent::getParameterValue('id_list')));
5858
}
59+
60+
$go_cache_file = parent::getParameterValue('indir')."go.cache.json";
61+
#unlink($go_cache_file);
62+
if(!file_exists($go_cache_file) or parent::getParameterValue('download') == true) {
63+
$this->getGO();
64+
file_put_contents($go_cache_file,json_encode($this->go));
65+
} else {
66+
// read the file
67+
$this->go = json_decode( file_get_contents($go_cache_file), true);
68+
}
5969

6070
$dataset_description = '';
6171
foreach($files AS $f) {
@@ -241,9 +251,16 @@ function parsePartnerEntry($did, $pid, $x)
241251
parent::triplify($pid, parent::getVoc()."x-pfam","pfam:"."".$v2->identifier)
242252
);
243253
} else if($k2 == "go-classifier") {
244-
parent::addRDF(
245-
parent::triplifyString($pid, parent::getVoc()."go-".$v2->category, $v2->description)
246-
);
254+
$e = array_search($v2->description, $this->go);
255+
if($e !== FALSE) {
256+
parent::addRDF(
257+
parent::triplify($pid, parent::getVoc()."go-".$v2->category, $e)
258+
);
259+
} else {
260+
parent::addRDF(
261+
parent::triplifyString($pid, parent::getVoc()."go-".$v2->category, $v2->description)
262+
);
263+
}
247264
} else {
248265
trigger_error("no handler for $k2",E_USER_WARNING);
249266
/* parent::addRDF(
@@ -773,6 +790,35 @@ function AddList(&$x, $id, $list_name, $item_name, $predicate, $list_item_name =
773790
}
774791
}
775792

793+
function getGO()
794+
{
795+
$this->go = null;
796+
797+
$server = "http://bio2rdf.org/sparql";
798+
$sparql = "PREFIX dct: <http://purl.org/dc/terms/>
799+
SELECT distinct ?id ?title
800+
{
801+
?go a <http://bio2rdf.org/go_vocabulary:Resource> .
802+
?go dct:identifier ?id.
803+
?go dct:title ?title .
804+
} ";
805+
$url = $server."?query=".urlencode($sparql)."&format=".urlencode("text/tab-separated-values");
806+
807+
$results = file_get_contents($url);
808+
if($results === FALSE) {
809+
trigger_error("Unable to get Gene Ontology labels",E_USER_WARNING);
810+
return false;
811+
}
812+
$list = explode("\n",$results);
813+
array_shift($list); array_pop($list); // remove first and last
814+
815+
foreach($list AS $v) {
816+
$b = explode("\t",str_replace('"','',$v));
817+
$this->go[$b[0]] = $b[1];
818+
}
819+
return true;
820+
}
821+
776822
} // end class
777823

778824
?>

kegg/kegg.php

+18-10
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ function run()
5959

6060
// handle genes separately
6161
if(in_array("genes",$files)) {
62-
$orgs = array("hsa"); //,"mmu","eco","dre","dme","ath","sce","ddi");
62+
$orgs = array("hsa","mmu","eco","dre","dme","ath","sce","ddi");
63+
//$orgs = array("hsa");
6364
echo "processing genes".PHP_EOL;
6465

6566
$ofile = "kegg-genes.".parent::getParameterValue('output_format');
@@ -82,7 +83,7 @@ function run()
8283

8384
// get the list of genes for this organims
8485
echo "processing $org".PHP_EOL;
85-
$this->org = $org; // local variable
86+
$this->org = strtoupper($org); // local variable
8687

8788
$lfile = $ldir.$org.".txt";
8889
$rfile = parent::getParameterValue("download_url")."list/$org";
@@ -223,9 +224,10 @@ function process($db)
223224
if(isset($this->idlist) and !in_array($id,$this->idlist)) continue;
224225

225226
if(isset($this->org)) {
226-
$id = $ns."_".$id;
227+
$id = strtoupper($ns)."_".$id;
227228
}
228229
$uri = $this->getNamespace().$id;
230+
229231
parent::addRDF(
230232
parent::describeIndividual($uri,$name,parent::getVoc().ucfirst($db)).
231233
parent::describeClass(parent::getVoc().ucfirst($db),"KEGG $db").
@@ -293,6 +295,7 @@ function parseEntry($lfile)
293295
$uri = parent::getNamespace().$e['id'];
294296
continue;
295297
}
298+
296299
// key with value
297300
if(in_array($k, array("NAME","DESCRIPTION","DEFINITION","EQUATION","COMMENT"))) {
298301
if($k == "NAME") {
@@ -688,14 +691,19 @@ function parseEntry($lfile)
688691
parent::triplify($uri,parent::getVoc().strtolower($k),$id)
689692
);
690693
preg_match_all("/ \[([^\]]+)\]/",$v,$m);
691-
if(isset($m[1])) {
692-
foreach($m[1] AS $item) {
693-
if(!strstr($item,"KO")) $item = "kegg:".str_replace(":","_",$item);
694-
else $item = str_replace("KO:","kegg:",$item);
695-
parent::addRDF(
696-
parent::triplify($id,parent::getVoc()."link",$item)
697-
);
694+
if(isset($m[1]) and !empty($m[1])) {
695+
foreach($m[1] AS $item) {
696+
$a = explode(':',$item); // get the namespace
697+
$b = explode(' ',$a[1]);
698+
foreach($b AS $c) {
699+
if(!strstr($item,"KO")) $i = "kegg:".$a[0].'_'.$c;
700+
else $i = "kegg:".$c;
701+
parent::addRDF(
702+
parent::triplify($id,parent::getVoc()."link",$i)
703+
);
704+
}
698705
}
706+
$test = true;
699707
}
700708
continue;
701709
}

0 commit comments

Comments
 (0)