Exemplo n.º 1
0
 function Run()
 {
     $ldir = parent::getParameterValue('indir');
     $odir = parent::getParameterValue('outdir');
     //check dependencies
     $d = $this->checkDependencies();
     if ($d) {
         //build pdb2rdf
         echo "building pdb2rdf..." . PHP_EOL;
         $cmd = "mvn clean install -DskipTests -f " . __DIR__ . "/pom.xml";
         $build_out = shell_exec($cmd);
         $out_ver = $this->verifyMavenBuildOutput($build_out);
         if ($out_ver) {
             //now check if download is desired
             if ($this->getParameterValue('download')) {
                 if (!$this->downloadFiles($ldir)) {
                     trigger_error("Not all files downloaded!", E_USER_WARNING);
                 }
             }
             //extract pdb2rdf-cli from the target directory
             if (!$this->extractCli()) {
                 trigger_error("Could not extract pdb2rdf!", E_USER_ERROR);
             }
             //now get ready to run pdb2rdf.sh
             if (!$this->runPdb2Rdf($ldir, $odir)) {
                 trigger_error("Could not run Pdb2RDF correctly!", E_USER_ERROR);
                 exit;
             } else {
                 echo "done!\n";
             }
         } else {
             trigger_error("Could not build pdb2rdf. Please try manually!", E_USER_ERROR);
         }
     } else {
         trigger_error("Dependencies not met!", E_USER_ERROR);
         exit;
     }
 }
Exemplo n.º 2
0
 private function citations()
 {
     while ($l = $this->getReadFile()->read(2000000)) {
         $a = explode("\t|\t", rtrim($l, "\t|\n"));
         if (!isset($a[1]) or !isset($a[2])) {
             continue;
         }
         $c = parent::getRes() . "citation-id-" . $a[0];
         $seealso = isset($a[4]) ? trim($a[4]) : "";
         if ($seealso) {
             $seealso = str_replace(array("lx: DOI ", "http;//"), array("http://dx.doi.org/", "http://"), $seealso);
             if (strlen($seealso) > 2 and !strstr($seealso, "http")) {
                 $seealso = "http://" . $seealso;
             }
             $seealso = parent::triplify($c, "rdfs:seeAlso", $seealso);
         }
         parent::addRDF(parent::describeIndividual($c, $a[1], $this->getVoc() . "Citation") . parent::describeClass($this->getVoc() . "Citation", "Citation") . parent::triplifyString($c, parent::getVoc() . "citation-key", $a[1]) . ($a[2] == "0" ? "" : parent::triplify($c, parent::getVoc() . "x-pubmed", "pubmed:" . $a[2])) . $seealso . ((isset($a[5]) and $a[5]) ? parent::triplifyString($c, parent::getVoc() . "text", str_replace("\"", "", $a[5])) : ""));
         if (isset($a[6])) {
             $taxids = explode(" ", trim($a[6]));
             if (count($taxids)) {
                 foreach ($taxids as $taxid) {
                     parent::addRDF(parent::triplify("taxonomy:{$taxid}", $this->getVoc() . "citation", $c));
                 }
             }
         }
         $this->writeRDFBufferToWriteFile();
     }
     //while
 }
Exemplo n.º 3
0
 public function makeDescription($title, $type)
 {
     if (!$title) {
         return null;
     }
     $uri = parent::getRes() . md5($title);
     $type_uri = parent::getVoc() . str_replace(" ", "-", $type);
     parent::addRDF(parent::describeIndividual($uri, $title, $type_uri) . parent::describeClass($type_uri, $type));
     return $uri;
 }
Exemplo n.º 4
0
 function gene_interactions()
 {
     while ($l = parent::getReadFile()->Read()) {
         if ($l[0] == '#') {
             continue;
         }
         $data = explode("\t", $l);
         if (count($data) != 11) {
             trigger_error("Found " . count($data) . " columns, expecting 11");
             continue;
         }
         $interaction = $data[0];
         $interaction_type = str_replace("_", "-", $data[1]);
         $interaction_type_label = str_replace("_", " ", $data[1]);
         $int_additional_info = $data[2];
         $gene1 = $data[5];
         $gene2 = $data[8];
         $interaction_id = parent::getNamespace() . $interaction;
         if ($interaction_type == "Genetic") {
             $int_pred = parent::getVoc() . "genetically-interacts-with";
         } elseif ($interaction_type == "Physical") {
             $int_pred = parent::getVoc() . "physically-interacts-with";
         } elseif ($interaction_type == "Predicted") {
             $int_pred = parent::getVoc() . "predicted-to-interact-with";
         } elseif ($interaction_type == "Regulatory") {
             $int_pred = parent::getVoc() . "regulates";
         }
         //elseif
         if ($int_additional_info == "No_interaction") {
             $interaction_label = "No " . strtolower($interaction_type) . " interaction between " . $gene1 . " and " . $gene2;
             parent::addRDF(parent::describeIndividual($interaction_id, $interaction_label, parent::getVoc() . $interaction_type . "-Non-Interaction") . parent::describeClass(parent::getVoc() . $interaction_type . "-Non-Interaction", $interaction_type_label . " non-interaction") . parent::triplify($interaction_id, parent::getVoc() . "involves", parent::getNamespace() . $gene1) . parent::triplify($interaction_id, parent::getVoc() . "involves", parent::getNamespace() . $gene2));
             $npa_id = parent::getRes() . md5($interaction_id . "negative property assertion");
             $npa_label = "Negative property assertion stating that " . $gene1 . " and " . $gene2 . " do not have a " . $interaction_type_label . " interaction";
             parent::addRDF(parent::describeIndividual($npa_id, $npa_label, "owl:NegativeObjectPropertyAssertion") . parent::triplify($npa_id, "owl:sourceIndividual", parent::getNamespace() . $gene1) . parent::triplify($npa_id, "owl:targetIndividual", parent::getNamespace() . $gene2) . parent::triplify($npa_id, "owl:assertionProperty", $int_pred));
         } elseif ($int_additional_info == "N/A" || $int_additional_info == "Genetic_interaction") {
             $interaction_label = $interaction_type . " interaction between " . $gene1 . " and " . $gene2;
             parent::addRDF(parent::describeIndividual($interaction_id, $interaction_label, parent::getVoc() . $interaction_type . "-Interaction") . parent::describeClass(parent::getVoc() . $interaction_type . "-Interaction", $interaction_type_label . " Interaction") . parent::triplify($interaction_id, parent::getVoc() . "involves", parent::getNamespace() . $gene1) . parent::triplify($interaction_id, parent::getVoc() . "involves", parent::getNamespace() . $gene2) . parent::triplify(parent::getNamespace() . $gene1, $int_pred, parent::getNamespace() . $gene2));
         } else {
             $interaction_label = ($int_additional_info != "" ? $int_additional_info . " " : "") . strtolower($interaction_type) . " interaction between " . $gene1 . " and " . $gene2;
             $type = parent::getVoc() . ($int_additional_info != "" ? $int_additional_info . "-" : "") . $interaction_type . "-Interaction";
             $type_label = ($int_additional_info != "" ? $int_additional_info . " " : "") . $interaction_type_label . " Interaction";
             parent::addRDF(parent::describeIndividual($interaction_id, $interaction_label, $type) . parent::describeClass($type, $type_label, parent::getVoc() . $interaction_type . "-Interaction") . parent::describeClass(parent::getVoc() . $interaction_type . "-Interaction", $interaction_type . " Interation") . parent::triplify($interaction_id, parent::getVoc() . "involves", parent::getNamespace() . $gene1) . parent::triplify($interaction_id, parent::getVoc() . "involves", parent::getNamespace() . $gene2) . parent::triplify(parent::getNamespace() . $gene1, $int_pred, parent::getNamespace() . $gene2));
         }
         //else
         parent::WriteRDFBufferToWriteFile();
     }
     //while
 }
Exemplo n.º 5
0
 private function process()
 {
     $z = 0;
     $y = 1;
     while ($l = $this->getReadFile()->Read(200000)) {
         if ($z++ % 1000000 == 0) {
             echo $z . PHP_EOL;
             $odir = parent::getParameterValue('outdir');
             $ofile = 'iproclass.' . $y++ . "." . parent::getParameterValue('output_format');
             $gz = strstr(parent::getParameterValue('output_format'), "gz") ? true : false;
             if (parent::getWriteFile() != null) {
                 parent::getWriteFile()->close();
                 parent::clear();
             }
             // generate a new file
             parent::setWriteFile($odir . $ofile, $gz);
         }
         $fields = explode("\t", $l);
         @($uniprot_acc = $fields[0]);
         @($uniprot = $fields[1]);
         @($gene = $fields[2]);
         @($refseq = $fields[3]);
         @($gi = $fields[4]);
         @($pdb = $fields[5]);
         @($pfam = $fields[6]);
         @($go = $fields[7]);
         @($pirsf = $fields[8]);
         @($ipi = $fields[9]);
         @($uniref_100 = $fields[10]);
         @($uniref_90 = $fields[11]);
         @($uniref_50 = $fields[12]);
         @($uniparc = $fields[13]);
         //skipping pir-psd because db no longer maintained
         @($ncbi_taxonomy = $fields[15]);
         @($mim = $fields[16]);
         @($unigene = $fields[17]);
         @($ensembl = $fields[18]);
         @($pubmed = $fields[19]);
         @($embl_genbank_ddbj = $fields[20]);
         @($embl_protein = trim($fields[21]));
         $id = $uniprot_acc;
         $id_res = $this->getNamespace() . $id;
         $id_label = "iproclass entry for uniprot:{$uniprot_acc}";
         parent::addRDF(parent::triplify($id_res, $this->getVoc() . "x-uniprot", "uniprot:" . $uniprot_acc));
         if (!empty($uniprot)) {
             $uniprot_ids = explode("; ", $uniprot);
             foreach ($uniprot_ids as $uniprot_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-uniprot", "uniprot:" . $uniprot_id));
             }
         }
         if (!empty($gene)) {
             $gene_ids = explode("; ", $gene);
             foreach ($gene_ids as $gene_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-ncbigene", "geneid:" . $gene_id));
             }
         }
         if (!empty($refseq)) {
             $refseq_ids = explode("; ", $refseq);
             foreach ($refseq_ids as $refseq_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-refseq", "refseq:" . $refseq_id));
             }
         }
         if (!empty($gi)) {
             $gi_ids = explode("; ", $gi);
             foreach ($gi_ids as $gi_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-gi", "gi:" . $gi_id));
             }
         }
         if (!empty($pdb)) {
             $pdb_ids = explode("; ", $pdb);
             foreach ($pdb_ids as $pdb_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-pdb", "pdb:" . $pdb_id));
             }
         }
         if (!empty($pfam)) {
             $pfam_ids = explode("; ", $pfam);
             foreach ($pfam_ids as $pfam_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-pfam", "pfam:" . $pfam_id));
             }
         }
         if (!empty($go)) {
             $go_ids = explode("; ", $go);
             foreach ($go_ids as $go_id) {
                 $go_id = substr($go_id, 3);
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-go", "go:" . $go_id));
             }
         }
         if (!empty($pirsf)) {
             $pirsf_ids = explode("; ", $pirsf);
             foreach ($pirsf_ids as $pirsf_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-pirsf", "pirsf:" . $pirsf_id));
             }
         }
         if (!empty($ipi)) {
             $ipi_ids = explode("; ", $ipi);
             foreach ($ipi_ids as $ipi_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-ipi", "ipi:" . $ipi_id));
             }
         }
         if (!empty($uniref_100)) {
             $uniref_100_ids = explode("; ", $uniref_100);
             foreach ($uniref_100_ids as $uniref_100_id) {
                 parent::AddRDF(parent::QQuadO_URL($id_res, "rdfs:seeAlso", "http://uniprot.org/uniref/" . $uniref_100_id));
             }
         }
         if (!empty($uniref_90)) {
             $uniref_90_ids = explode("; ", $uniref_90);
             foreach ($uniref_90_ids as $uniref_90_id) {
                 parent::AddRDF(parent::QQuadO_URL($id_res, "rdfs:seeAlso", "http://uniprot.org/uniref/" . $uniref_90_id));
             }
         }
         if (!empty($uniref_50)) {
             $uniref_50_ids = explode("; ", $uniref_50);
             foreach ($uniref_50_ids as $uniref_50_id) {
                 parent::AddRDF(parent::QQuadO_URL($id_res, "rdfs:seeAlso", "http://uniprot.org/uniref/" . $uniref_50_id));
             }
         }
         if (!empty($uniparc)) {
             $uniparc_ids = explode("; ", $uniparc);
             foreach ($uniparc_ids as $uniparc_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-uniparc", "uniparc:" . $uniparc_id) . parent::QQuadO_URL($id_res, "rdfs:seeAlso", "http://uniprot.org/uniparc/" . $uniparc_id));
             }
         }
         if (!empty($ncbi_taxonomy)) {
             $taxonomy_ids = explode("; ", $ncbi_taxonomy);
             foreach ($taxonomy_ids as $taxonomy_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-taxon", "taxon:" . $taxonomy_id));
             }
         }
         if (!empty($mim)) {
             $mim_ids = explode("; ", $mim);
             foreach ($mim_ids as $mim_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-omim", "omim:" . $mim_id));
             }
         }
         if (!empty($unigene)) {
             $unigene_ids = explode("; ", $unigene);
             foreach ($unigene_ids as $unigene_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-unigene", "unigene:" . $unigene_id));
             }
         }
         if (!empty($ensembl)) {
             $ensembl_ids = explode("; ", $ensembl);
             foreach ($ensembl_ids as $ensembl_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-ensembl", "ensembl:" . $ensembl_id));
             }
         }
         if (!empty($pubmed)) {
             $pubmed_ids = explode("; ", $pubmed);
             foreach ($pubmed_ids as $pubmed_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-pubmed", "pubmed:" . $pubmed_id));
             }
         }
         if (!empty($embl_genbank_ddbj)) {
             $genbank_ids = explode("; ", $embl_genbank_ddbj);
             foreach ($genbank_ids as $genbank_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-genbank", "genbank:" . $genbank_id));
             }
         }
         if (!empty($embl_protein)) {
             $embl_protein_ids = explode(";", $embl_protein);
             foreach ($embl_protein_ids as $embl_protein_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-genbank", "genbank:" . $embl_protein_id));
             }
         }
         //write rdf to file
         $this->WriteRDFBufferToWriteFile();
     }
     //while
 }
Exemplo n.º 6
0
 private function geneinfo()
 {
     $i = 1;
     $header = $this->GetReadFile()->Read(200000);
     while ($aLine = $this->GetReadFile()->Read(200000)) {
         if ($i++ % 1000 == 0) {
             parent::clear();
         }
         $a = $splitLine = explode("\t", $aLine);
         if (count($splitLine) == 15) {
             $taxid = "taxon:" . trim($splitLine[0]);
             if (isset($this->taxids) and !isset($this->taxids[trim($splitLine[0])])) {
                 continue;
             }
             $aGeneId = trim($splitLine[1]);
             $geneid = "ncbigene:" . trim($splitLine[1]);
             $symbol = addslashes(stripslashes(trim($splitLine[2])));
             $symbolid = "symbol:{$symbol}";
             $locusTag = trim($splitLine[3]);
             $symbols_arr = explode("|", $splitLine[4]);
             $dbxrefs_arr = explode("|", $splitLine[5]);
             $chromosome = trim($splitLine[6]);
             $map_location = trim($splitLine[7]);
             $description = addslashes(stripslashes(trim($splitLine[8])));
             $type_of_gene = trim($splitLine[9]);
             $symbol_authority = addslashes(stripslashes(trim($splitLine[10])));
             $symbol_auth_full_name = addslashes(stripslashes(trim($splitLine[11])));
             $nomenclature_status = addslashes(stripslashes(trim($splitLine[12])));
             $other_designations = addslashes(stripslashes(trim($splitLine[13])));
             $mod_date = date_parse(trim($splitLine[14]));
             //check for a valid symbol
             if ($symbol != "NEWENTRY") {
                 $this->AddRDF(parent::describeIndividual($geneid, "{$description} ({$symbolid}, {$taxid})", $this->getVoc() . "Gene") . parent::triplify($geneid, $this->getVoc() . "x-taxonomy", $taxid) . parent::triplifyString($geneid, $this->getVoc() . "symbol", $symbol) . parent::triplifyString($geneid, $this->getVoc() . "locus", addslashes(stripslashes($locusTag))) . parent::describeClass($this->getVoc() . "Gene", "NCBI Gene gene"));
                 if ($type_of_gene != '-') {
                     $this->AddRDF(parent::triplify($geneid, "rdf:type", $this->getVoc() . ucfirst($type_of_gene) . "-Gene") . parent::describeClass($this->getVoc() . ucfirst($type_of_gene) . "-Gene", ucfirst($type_of_gene) . " Gene"));
                 }
                 //symbol synonyms
                 foreach ($symbols_arr as $s) {
                     if ($s != "-") {
                         $this->AddRDF(parent::triplifyString($geneid, $this->getVoc() . "symbol-synonym", addslashes(stripslashes($s))));
                     }
                 }
                 //dbxrefs
                 foreach ($dbxrefs_arr as $dbx) {
                     if ($dbx != "-") {
                         $this->AddRDF(parent::triplifyString($geneid, $this->getVoc() . "dbxref", $dbx));
                     }
                 }
                 //chromosome
                 if ($chromosome != "-") {
                     $this->AddRDF(parent::triplifyString($geneid, $this->getVoc() . "chromosome", $chromosome));
                 }
                 //map location
                 if ($map_location != "-") {
                     $this->AddRDF(parent::triplifyString($geneid, $this->getVoc() . "map-location", $map_location));
                 }
                 //description
                 if ($description != "-") {
                     $this->AddRDF(parent::triplifyString($geneid, "dc:description", $description));
                 }
                 //nomenclature authority
                 if ($symbol_authority != "-") {
                     $this->AddRDF(parent::triplifyString($geneid, $this->getVoc() . "nomenclature-authority", $symbol_authority));
                     if ($symbol_auth_full_name != "-") {
                         $this->AddRDF(parent::triplifyString($geneid, $this->getVoc() . "nomenclature-authority-fullname", $symbol_auth_full_name));
                     }
                 }
                 //nomenclature status
                 if ($nomenclature_status != "-") {
                     $this->AddRDF(parent::triplifyString($geneid, $this->getVoc() . "nomenclature-status", $nomenclature_status));
                 }
                 //other designations
                 if ($other_designations != "-") {
                     foreach (explode("|", $other_designations) as $d) {
                         $this->AddRDF(parent::triplifyString($geneid, $this->getVoc() . "other-designation", $d));
                     }
                 }
                 //modification date
                 if ($mod_date != "-") {
                     $this->AddRDF(parent::triplifyString($geneid, $this->getVoc() . "modification-date", $mod_date["year"] . "-" . $mod_date["month"] . "-" . $mod_date["day"]));
                 }
             }
         }
         parent::writeRDFBufferToWriteFile();
     }
     // while
 }
Exemplo n.º 7
0
 function Run()
 {
     $idir = parent::getParameterValue('indir');
     $odir = parent::getParameterValue('outdir');
     $files = parent::getParameterValue('files');
     // set the work
     if ($files != 'all') {
         // check if comma-separated, or hyphen-range
         $list = explode(",", $files);
         if (count($list) == 1) {
             // try hyphen separated
             $range = explode("-", $files);
             if (count($range) == 2) {
                 for ($i = $range[0]; $i <= $range[1]; $i++) {
                     $myfiles[] = $i;
                 }
             } else {
                 // must a single entry
                 $myfiles[] = $files;
             }
         } else {
             $myfiles = $list;
         }
     }
     $rest_uri = 'http://sabiork.h-its.org/sabioRestWebServices/';
     $getReactionIds_url = $rest_uri . "suggestions/SABIOReactionIDs";
     $reaction_list_file = $idir . "reactions.xml";
     if (!file_exists($reaction_list_file) || parent::getParameterValue('download') == 'true') {
         $xml = file_get_contents($getReactionIds_url);
         if (FALSE === $reaction_list_file) {
             exit;
         }
         $f = new FileFactory($reaction_list_file);
         $f->Write($xml);
         $f->Close();
     }
     $xml = simplexml_load_file($reaction_list_file);
     $total = count($xml->SABIOReactionID);
     if (isset($myfiles)) {
         $total = count($myfiles);
     }
     $i = 0;
     parent::setCheckpoint('dataset');
     $graph_uri = parent::getGraphURI();
     if (parent::getParameterValue('dataset_graph') == true) {
         parent::setGraphURI(parent::getDatasetURI());
     }
     $suffix = parent::getParameterValue('output_format');
     $ofile = "sabiork." . $suffix;
     $gz = strstr(parent::getParameterValue('output_format'), "gz") ? true : false;
     parent::setWriteFile($odir . $ofile, $gz);
     foreach ($xml->SABIOReactionID as $rid) {
         parent::setCheckpoint('file');
         if (isset($myfiles)) {
             if (!in_array($rid, $myfiles)) {
                 continue;
             }
         }
         $i++;
         echo "{$i} / {$total} : reaction {$rid}" . PHP_EOL;
         $reaction_file = $idir . "reaction_" . $rid . ".owl.gz";
         if (!file_exists($reaction_file) || $this->GetParameterValue('download') == 'true') {
             $url = $rest_uri . 'searchKineticLaws/biopax?q=SabioReactionID:' . $rid;
             $data = file_get_contents($url);
             if ($data === FALSE) {
                 continue;
             }
             $f = new FileFactory($reaction_file, true);
             $f->Write($data);
             $f->Close();
         }
         $buf = file_get_contents("compress.zlib://" . $reaction_file);
         // send for parsing
         $p = new BioPAX2Bio2RDF($this);
         $p->SetBuffer($buf)->SetBioPAXVersion(3)->SetBaseNamespace("http://sabio.h-its.org/biopax#")->SetBio2RDFNamespace("http://bio2rdf.org/sabiork:")->SetDatasetURI($this->GetDatasetURI());
         $rdf = $p->Parse();
         parent::getWriteFile()->Write($rdf);
     }
     parent::getWriteFile()->Close();
     //generate dataset description
     echo "Generating dataset description... ";
     $source_file = (new DataResource($this))->setURI("http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax")->setTitle("SABIO-RK Biochemical Reaction Kinetics Database")->setRetrievedDate(date("Y-m-d\\TG:i:s\\Z", filemtime($odir . $ofile)))->setFormat("text/xml")->setPublisher("http://sabio.villa-bosch.de/")->setHomepage("http://sabio.villa-bosch.de/")->setRights("use-share-modify")->setRights("no-commercial")->setLicense("http://sabio.villa-bosch.de/layouts/content/termscondition.gsp")->setDataset("http://identifiers.org/sabiork.reaction/");
     $prefix = parent::getPrefix();
     $bVersion = parent::getParameterValue('bio2rdf_release');
     $date = date("Y-m-d\\TG:i:s\\Z");
     $output_file = (new DataResource($this))->setURI("http://download.bio2rdf.org/release/{$bVersion}/{$prefix}/")->setTitle("Bio2RDF v{$bVersion} RDF version of {$prefix} (generated at {$date})")->setSource($source_file->getURI())->setCreator("https://github.com/bio2rdf/bio2rdf-scripts/blob/master/sabiork/sabiork.php")->setCreateDate($date)->setHomepage("http://download.bio2rdf.org/release/{$bVersion}/{$prefix}/{$prefix}.html")->setPublisher("http://bio2rdf.org")->setRights("use-share-modify")->setRights("by-attribution")->setRights("restricted-by-source-license")->setLicense("http://creativecommons.org/licenses/by/3.0/")->setDataset(parent::getDatasetURI());
     if ($gz) {
         $output_file->setFormat("application/gzip");
     }
     if (strstr(parent::getParameterValue('output_format'), "nt")) {
         $output_file->setFormat("application/n-triples");
     } else {
         $output_file->setFormat("application/n-quads");
     }
     $dataset_description = $source_file->toRDF() . $output_file->toRDF();
     //write dataset description to file
     parent::setGraphURI($graph_uri);
     parent::setWriteFile($odir . parent::getBio2RDFReleaseFile());
     parent::getWriteFile()->write($dataset_description);
     parent::getWriteFile()->close();
     echo "done!" . PHP_EOL;
 }
Exemplo n.º 8
0
 function twosides()
 {
     $items = null;
     $id = 0;
     $this->GetReadFile()->Read();
     while ($l = $this->GetReadFile()->Read()) {
         $a = explode("\t", $l);
         $id++;
         if ($id % 10000 == 0) {
             $this->WriteRDFBufferToWriteFile();
         }
         $uid = "twosides:{$id}";
         $d1 = "pubchemcompound:" . (int) sprintf("%d", substr($a[0], 4));
         $d1_name = $a[2];
         $d2 = "pubchemcompound:" . (int) sprintf("%d", substr($a[1], 4));
         $d2_name = $a[3];
         $e = "umls:" . $a[4];
         $e_name = strtolower($a[5]);
         $uid_label = "DDI between {$d1_name} and {$d2_name} leading to {$e_name}";
         if (!isset($items[$d1])) {
             parent::addRDF(parent::describeIndividual($d1, $d1_name, parent::getVoc() . "Chemical") . parent::describeClass(parent::getVoc() . "Chemical", "PharmGKB Chemical"));
             $items[$d1] = '';
         }
         if (!isset($items[$d2])) {
             parent::addRDF(parent::describeIndividual($d2, $d2_name, parent::getVoc() . "Chemical") . parent::describeClass(parent::getVoc() . "Chemical", "PharmGKB Chemical"));
             $items[$d2] = '';
         }
         if (!isset($items[$e])) {
             parent::addRDF(parent::describeIndividual($e, $e_name, parent::getVoc() . "Event") . parent::describeClass(parent::getVoc() . "Event", "PharmGKB side effect event"));
             $items[$e] = '';
         }
         parent::addRDF(parent::describeIndividual($uid, $uid_label, parent::getVoc() . "Drug-Drug-Association") . parent::describeClass(parent::getVoc() . "Drug-Drug-Association", "PharmGKB Twosides Drug-Drug Association") . parent::triplify($uid, parent::getVoc() . "chemical", $d1) . parent::triplify($uid, parent::getVoc() . "chemical", $d2) . parent::triplify($uid, parent::getVoc() . "event", $e) . parent::triplifyString($uid, parent::getVoc() . "p-value", $a[7]));
     }
     parent::writeRDFBufferToWriteFile();
 }
Exemplo n.º 9
0
 function process()
 {
     $gb_record_str = "";
     while ($aLine = $this->getReadFile()->Read(4096)) {
         preg_match("/^\\/\\/\$/", $aLine, $matches);
         if (count($matches)) {
             //now remove the header if it is there
             $gb_record_str = $this->removeHeader($gb_record_str);
             $sectionsRaw = $this->parseGenbankRaw($gb_record_str);
             /**
              * SECTIONS being parsed:
              * locus, definition, accession, version, keywords, segment, source, reference, features
              */
             //get locus section(s)
             $locus = $this->retrieveSections("LOCUS", $sectionsRaw);
             $parsed_locus_arr = $this->parseLocus($locus);
             //get the definition section
             $definition = $this->retrieveSections("DEFINITION", $sectionsRaw);
             $parsed_definition_arr = $this->parseDefinition($definition);
             //get the accession
             $accessions = $this->retrieveSections("ACCESSION", $sectionsRaw);
             $parsed_accession_arr = $this->parseAccession($accessions);
             //get the version
             $versions = $this->retrieveSections("VERSION", $sectionsRaw);
             $parsed_version_arr = $this->parseVersion($versions);
             //get the keywords
             $keywords = $this->retrieveSections("KEYWORDS", $sectionsRaw);
             $parsed_keyword_arr = $this->parseKeywords($keywords);
             //may not be any segment section
             $segments = $this->retrieveSections("SEGMENT", $sectionsRaw);
             if (!empty($segments)) {
                 $parsed_segments_arr = $this->parseSegment($segments);
             }
             $features = $this->retrieveSections("FEATURES", $sectionsRaw);
             $parsed_features_arr = $this->parseFeatures($features);
             //get the source section
             $source = $this->retrieveSections("SOURCE", $sectionsRaw);
             $parsed_source_arr = $this->parseSource($source);
             $contig = $this->retrieveSections("CONTIG", $sectionsRaw);
             if (!empty($contig)) {
                 $parsed_contig_arr = $this->parseContig($contig);
             }
             //get the reference section
             $references = $this->retrieveSections("REFERENCE", $sectionsRaw);
             $parsed_refs_arr = $this->parseReferences($references);
             $gb_res = "gi:" . $parsed_version_arr['gi'];
             $gb_label = utf8_encode(htmlspecialchars($parsed_definition_arr[0]));
             parent::AddRDF(parent::describeIndividual($gb_res, $gb_label, $this->getVoc() . "genbank-record") . parent::triplifyString($gb_res, $this->getVoc() . 'sequence-length', $parsed_locus_arr[0]['sequence_length']) . parent::triplifyString($gb_res, $this->getVoc() . 'strandedness', $parsed_locus_arr[0]['strandedness']) . parent::triplify($gb_res, "rdf:type", $this->getRes() . $parsed_locus_arr[0]['mol_type']) . parent::triplifyString($gb_res, $this->getVoc() . 'chromosome-shape', $parsed_locus_arr[0]['chromosome_shape']) . parent::triplifyString($gb_res, $this->getVoc() . 'division-name', $parsed_locus_arr[0]['division_name']) . parent::triplifyString($gb_res, $this->getVoc() . 'date-of-entry', $parsed_locus_arr[0]['date']) . parent::triplifyString($gb_res, $this->getVoc() . 'source', utf8_encode($parsed_source_arr[0])) . parent::QQuadO_URL($gb_res, $this->getVoc() . 'fasta-seq', 'https://www.ncbi.nlm.nih.gov/sviewer/viewer.cgi?sendto=on&db=nucest&dopt=fasta&val=' . $parsed_version_arr['gi']));
             foreach ($parsed_features_arr as $aFeature) {
                 //getFeatures
                 $type = $aFeature['type'];
                 $feat_desc = $this->getFeatures($type);
                 $label = preg_replace('/\\s\\s*/', ' ', $feat_desc['definition']);
                 $comment = null;
                 $value = $aFeature['value'];
                 $value_arr = explode("/", $value);
                 $location = preg_replace('/\\n/', '', $value_arr[0]);
                 $class_id = parent::getVoc() . md5($type);
                 $feat_res = parent::getRes() . md5($type . $location . $gb_res);
                 $feat_label = utf8_encode($type . " " . $location . " for " . $gb_res);
                 if (isset($feat_desc['comment'])) {
                     $comment = $feat_desc['comment'];
                     $comment = preg_replace('/\\s\\s*/', ' ', $comment);
                     $label .= " " . $comment;
                 }
                 parent::AddRDF(parent::describeClass($class_id, $label, parent::getVoc() . "Feature") . parent::describeIndividual($feat_res, $feat_label, $class_id) . parent::triplify($gb_res, $this->getVoc() . "has-feature", $feat_res));
                 foreach ($value_arr as $aL) {
                     //check if aL has an equals in it
                     $p = "/(\\S+)\\=(.*)/";
                     preg_match($p, $aL, $m);
                     if (count($m)) {
                         if ($m[1] == "db_xref") {
                             parent::AddRDF(parent::triplify($feat_res, "rdfs:seeAlso", str_replace("\"", "", $m[2])));
                         } else {
                             parent::AddRDF(parent::triplifyString($feat_res, $this->getVoc() . $m[1], utf8_encode(str_replace("\"", "", $m[2]))));
                         }
                     }
                 }
             }
             foreach ($parsed_accession_arr[0] as $acc) {
                 parent::AddRDF(parent::triplifyString($gb_res, $this->getVoc() . "accession", $acc));
             }
             if (isset($parsed_version_arr['versioned_accession'])) {
                 parent::AddRDF(parent::triplifyString($gb_res, $this->getVoc() . "versioned-accession", $parsed_version_arr['versioned_accession']));
             }
             if (isset($parsed_contig_arr)) {
                 foreach ($parsed_contig_arr as $aContig) {
                     parent::AddRDF(parent::triplifyString($gb_res, $this->getVoc() . "contig", parent::safeLiteral($aContig)));
                 }
             }
             foreach ($parsed_keyword_arr as $akw) {
                 parent::AddRDF(parent::triplifyString($gb_res, $this->getVoc() . "keyword", $akw));
             }
             if (isset($parsed_segments_arr)) {
                 foreach ($parsed_segments_arr as $aSeg) {
                     parent::AddRDF(parent::triplifyString($gb_res, $this->getVoc() . "segment-number", $aSeg['segment_number']) . parent::triplifyString($gb_res, $this->getVoc() . "total-segments", $aSeg['total_segments']));
                 }
             }
             foreach ($parsed_refs_arr as $aRef) {
                 $r = rand();
                 $ref_res = $this->getRes() . md5($r);
                 $ref_label = "reference for " . $gb_res;
                 if (isset($aRef['TITLE'])) {
                     parent::AddRDF(parent::describeIndividual($ref_res, $ref_label, $this->getVoc() . "reference") . parent::triplifyString($ref_res, $this->getVoc() . "title", $aRef['TITLE']));
                 }
                 if (isset($aRef['PUBMED'])) {
                     parent::AddRDF(parent::triplify($ref_res, $this->getVoc() . "x-pubmed", 'pubmed:' . $aRef['PUBMED']));
                 }
                 if (isset($aRef['AUTHORS'])) {
                     parent::AddRDF(parent::triplifyString($ref_res, $this->getVoc() . "authors", $aRef['AUTHORS']));
                 }
                 parent::AddRDF(parent::triplify($gb_res, $this->getVoc() . "reference", $ref_res) . parent::triplifyString($ref_res, $this->getVoc() . "coordinates", $aRef['COORDINATES']) . parent::triplifyString($ref_res, $this->getVoc() . "citation", $aRef['JOURNAL']));
             }
             $gb_record_str = "";
             $this->WriteRDFBufferToWriteFile();
             continue;
         }
         preg_match("/^\n\$/", $aLine, $matches);
         if (count($matches) == 0) {
             $gb_record_str .= $aLine;
         }
     }
     //while
 }
Exemplo n.º 10
0
 function process()
 {
     while ($aLine = $this->GetReadFile()->Read(200000)) {
         $parsed_line = $this->parse_homologene_tab_line($aLine);
         $hid = "homologene:" . $parsed_line["hid"];
         $hid_label = "homologene group " . $parsed_line['hid'];
         parent::AddRDF(parent::describeIndividual($hid, $hid_label, $this->getVoc() . "Homologene-Group") . parent::describeClass($this->getVoc() . "Homologene-Group", "Homologene Group"));
         $geneid = "ncbigene:" . $parsed_line["geneid"];
         $taxid = "taxid:" . $parsed_line["taxid"];
         $gi = "gi:" . $parsed_line["gi"];
         $genesymbol = str_replace("\\", "", $parsed_line["genesymbol"]);
         $refseq = "refseq:" . $parsed_line["refseq"];
         parent::AddRDF(parent::triplify($hid, $this->getVoc() . "x-taxid", $taxid) . parent::describeProperty($this->getVoc() . "x-taxid", "Link to NCBI taxonomy"));
         parent::AddRDF(parent::triplify($hid, $this->getVoc() . "x-ncbigene", $geneid) . parent::describeProperty($this->getVoc() . "x-ncbigene", "Link to NCBI GeneId"));
         parent::AddRDF(parent::triplifyString($hid, $this->getVoc() . "gene-symbol", utf8_encode(htmlspecialchars($genesymbol)), "xsd:string") . parent::describeProperty($this->getVoc() . "gene-symbol", "Link to gene symbol"));
         parent::AddRDF(parent::triplify($hid, $this->getVoc() . "x-gi", $gi) . parent::describeProperty($this->getVoc() . "x-gi", "Link to NCBI GI"));
         parent::AddRDF(parent::triplify($hid, $this->getVoc() . "x-refseq", $refseq) . parent::describeProperty($this->getVoc() . "x-refseq", "Link to NCBI Refseq"));
         $this->WriteRDFBufferToWriteFile();
     }
 }
Exemplo n.º 11
0
 function MGI_Geno_NotDisease()
 {
     $line = 1;
     while ($l = $this->getReadFile()->read(248000)) {
         $a = explode("\t", $l);
         if (count($a) != 8) {
             trigger_error("Incorrect number of columns", E_USER_WARNING);
             continue;
         }
         $genotype = $a[0];
         $alleles = explode("|", strtolower($a[2]));
         $diseases = explode(",", $a[7]);
         foreach ($diseases as $d) {
             $disease = "omim:{$d}";
             foreach ($alleles as $allele) {
                 $id = parent::getRes() . md5($allele . $disease);
                 $label = "{$allele} {$disease} absent association";
                 parent::addRDF(parent::describeIndividual($id, $label, $this->getVoc() . "Allele-Disease-Non-Association") . parent::describeClass($this->getVoc() . "Allele-Disease-Non-Association", "MGI Allele-Disease Non-Association") . parent::triplify($id, $this->getVoc() . "allele", $allele) . parent::triplifyString($id, $this->getVoc() . "genotype-string", $genotype) . parent::triplify($id, $this->getVoc() . "disease", $disease) . parent::triplifyString($id, $this->getVoc() . "is-negated", "true"));
                 if ($a[5]) {
                     $pmids = explode(",", $a[5]);
                     foreach ($pmids as $pmid) {
                         parent::addRDF(parent::triplify($id, $this->getVoc() . "x-pubmed", "pubmed:" . $pmid));
                     }
                 }
             }
         }
         $this->writeRDFBufferToWriteFile();
     }
 }
Exemplo n.º 12
0
 function parseKGML($lfile)
 {
     $pathway = simplexml_load_file($lfile);
     if ($pathway === false) {
         echo "Error in parsing {$lfile}" . PHP_EOL;
         return;
     }
     $pathway_id = str_replace("path", "kegg", $pathway['name']);
     $base_id = str_replace("kegg", "kegg_resource", $pathway_id) . ".";
     parent::addRDF(parent::describeIndividual($pathway_id, $pathway['title'], parent::getVoc() . "Pathway") . parent::triplify($pathway_id, "rdfs:seeAlso", $pathway['link']) . parent::triplify($pathway_id, "foaf:depiction", $pathway['image']));
     // get the entries
     foreach ($pathway->children() as $type => $item) {
         if ($type == "entry") {
             $eid = $base_id . $item['id'];
             $entries["" . $item['id']] = "" . $item['name'];
             parent::addRDF(parent::describeIndividual($eid, $item['name'], parent::getVoc() . "Ortholog-Group") . parent::describeClass(parent::getVoc() . "Ortholog-Group", "KEGG Ortholog Group"));
             $mids = explode(" ", $item['name']);
             foreach ($mids as $mid) {
                 if ($item['type'] == 'path') {
                     $mid = str_replace($mid, ":", "_");
                 } else {
                     $mid = substr($mid, strpos($mid, ":") + 1);
                 }
                 parent::addRDF(parent::triplify($eid, parent::getVoc() . "member", "kegg:" . $mid));
             }
         }
     }
     // iterate over the relations, reactions
     foreach ($pathway->children() as $type => $item) {
         if ($type == "relation") {
             /*
             	<relation entry1="70" entry2="73" type="ECrel">
             		<subtype name="compound" value="86"/>
             	</relation>
                 <relation entry1="26" entry2="25" type="PPrel">
             		<subtype name="compound" value="17"/>
             		<subtype name="activation" value="--&gt;"/>
             	</relation>
             */
             $id1 = "" . $item['entry1'];
             $id2 = "" . $item['entry2'];
             $type = "" . $type;
             $relation_id = str_replace("kegg", "kegg_resource", $pathway_id) . "." . $id1 . "." . $id2 . "." . $type;
             $label = $type . " relation between " . $entries[$id1] . " and " . $entries[$id2];
             parent::addRDF(parent::describeIndividual($relation_id, $label, parent::getVoc() . "Pathway-Relation") . parent::describeClass(parent::getVoc() . "Pathway-Relation", "KEGG Pathway Relation") . parent::triplify($relation_id, parent::getVoc() . "source", $base_id . $id1) . parent::triplify($relation_id, parent::getVoc() . "target", $base_id . $id2) . parent::triplify($relation_id, parent::getVoc() . "pathway", $pathway_id) . parent::triplifyString($relation_id, parent::getVoc() . "type", $item['type']));
             foreach ($item->children() as $subtype) {
                 parent::addRDF(parent::triplifyString($relation_id, parent::getVoc() . "subtype", '' . $subtype['name']));
             }
         } else {
             if ($type == "reaction") {
                 /*     <reaction id="133" name="rn:R09085" type="irreversible">
                 							<substrate id="86" name="cpd:C00267"/>
                 							<product id="90" name="cpd:C00668"/>
                 						</reaction>
                 				*/
                 $reaction_id = str_replace("kegg", "kegg_resource", $pathway_id) . "." . substr($item['name'], strpos($item['name'], ":") + 1);
                 $reaction_type = parent::getVoc() . ucfirst($item['type']) . "-Reaction";
                 parent::addRDF(parent::describeIndividual($reaction_id, $item['name'], parent::getVoc() . "Reaction") . parent::describeClass(parent::getVoc() . "Reaction", "KEGG Reaction") . parent::triplify($reaction_id, "rdf:type", $reaction_type));
                 foreach ($item->children() as $k => $v) {
                     $cid = str_replace("cpd:", "kegg:", $v['name']);
                     parent::addRDF(parent::triplify($reaction_id, parent::getVoc() . $k, $cid));
                 }
             }
         }
     }
     return;
 }
Exemplo n.º 13
0
 function ParseStringArray($string)
 {
     parent::getRegistry()->parseQName($string, $ns, $str);
     $rm = $this->ParseIDLabelArray($str);
     if ($rm !== null) {
         $id = trim($rm["id"]);
         $label = trim($rm["label"]);
         if ($ns == 'other' || $ns == 'xx') {
             $ns = '';
         }
         if ($ns == 'complex') {
             $ns = 'rogid';
         }
         $returnMe = array();
         $returnMe["label"] = $label;
         $returnMe["id"] = $id;
         $returnMe["ns"] = $ns;
         return $returnMe;
     } else {
         return null;
     }
 }
Exemplo n.º 14
0
 function ParseEntry($obj, $type)
 {
     $o = $obj["omim"]["entryList"][0]["entry"];
     $omim_id = $o['mimNumber'];
     $omim_uri = parent::getNamespace() . $o['mimNumber'];
     if (isset($o['version'])) {
         parent::setDatasetVersion($o['version']);
     }
     // add the links
     parent::addRDF($this->QQuadO_URL($omim_uri, "rdfs:seeAlso", "http://omim.org/entry/" . $omim_id));
     parent::addRDF($this->QQuadO_URL($omim_uri, "owl:sameAs", "http://identifiers.org/omim/" . $omim_id));
     // parse titles
     $titles = $o['titles'];
     parent::addRDF(parent::describeIndividual($omim_uri, $titles['preferredTitle'], parent::getVoc() . str_replace(array(" ", "/"), "-", ucfirst($type))) . parent::describeClass(parent::getVoc() . str_replace(array(" ", "/"), "-", ucfirst($type)), $type));
     if (isset($titles['preferredTitle'])) {
         parent::addRDF(parent::triplifyString($omim_uri, parent::getVoc() . "preferred-title", $titles['preferredTitle']));
     }
     if (isset($titles['alternativeTitles'])) {
         $b = explode(";;", $titles['alternativeTitles']);
         foreach ($b as $title) {
             parent::addRDF(parent::triplifyString($omim_uri, parent::getVoc() . "alternative-title", trim($title)));
         }
     }
     // parse text sections
     if (isset($o['textSectionList'])) {
         foreach ($o['textSectionList'] as $i => $section) {
             if ($section['textSection']['textSectionTitle'] == "Description") {
                 parent::addRDF(parent::triplifyString($omim_uri, "dc:description", $section['textSection']['textSectionContent']));
             } else {
                 $p = str_replace(" ", "-", strtolower($section['textSection']['textSectionTitle']));
                 parent::addRDF(parent::triplifyString($omim_uri, parent::getVoc() . "{$p}", $section['textSection']['textSectionContent']));
             }
             // parse the omim references
             preg_match_all("/\\{([0-9]{6})\\}/", $section['textSection']['textSectionContent'], $m);
             if (isset($m[1][0])) {
                 foreach ($m[1] as $oid) {
                     parent::addRDF(parent::triplify($omim_uri, parent::getVoc() . "refers-to", "omim:{$oid}"));
                 }
             }
         }
     }
     // allelic variants
     if (isset($o['allelicVariantList'])) {
         foreach ($o['allelicVariantList'] as $i => $v) {
             $v = $v['allelicVariant'];
             $uri = parent::getRes() . "{$omim_id}" . "_allele_" . $i;
             $label = str_replace("\n", " ", $v['name']);
             parent::addRDF(parent::describeIndividual($uri, $label, parent::getVoc() . "Allelic-Variant") . parent::describeClass(parent::getVoc() . "Allelic-Variant", "Allelic Variant"));
             if (isset($v['alternativeNames'])) {
                 $names = explode(";;", $v['alternativeNames']);
                 foreach ($names as $name) {
                     $name = str_replace("\n", " ", $name);
                     parent::addRDF(parent::triplifyString($uri, parent::getVoc() . "alternative-names", $name));
                 }
             }
             if (isset($v['text'])) {
                 parent::addRDF(parent::triplifyString($uri, "dc:description", $v['text']));
             }
             if (isset($v['mutations'])) {
                 parent::addRDF(parent::triplifyString($uri, parent::getVoc() . "mutation", $v['mutations']));
             }
             if (isset($v['dbSnps'])) {
                 $snps = explode(",", $v['dbSnps']);
                 foreach ($snps as $snp) {
                     parent::addRDF(parent::triplify($uri, parent::getVoc() . "x-dbsnp", "dbsnp:" . $snp));
                 }
             }
             parent::addRDF(parent::triplify($omim_uri, parent::getVoc() . "variant", $uri));
         }
     }
     // clinical synopsis
     if (isset($o['clinicalSynopsis'])) {
         $cs = $o['clinicalSynopsis'];
         $cs_uri = parent::getRes() . "" . $omim_id . "_cs";
         parent::addRDF(parent::describeIndividual($cs_uri, "Clinical synopsis for omim {$omim_id}", parent::getVoc() . "Clinical-Synopsis") . parent::describeClass(parent::getVoc() . "Clinical-Synopsis", "Clinical Synopsis") . parent::triplify($omim_uri, parent::getVoc() . "clinical-synopsis", $cs_uri));
         foreach ($cs as $k => $v) {
             if (!strstr($k, "Exists")) {
                 // ignore the boolean assertion.
                 // @todo ignore provenance for now
                 if (in_array($k, array('contributors', 'creationDate', 'editHistory', 'epochCreated', 'dateCreated', 'epochUpdated', 'dateUpdated'))) {
                     continue;
                 }
                 if (!is_array($v)) {
                     $v = array($k => $v);
                 }
                 foreach ($v as $k1 => $v1) {
                     $phenotypes = explode(";", $v1);
                     foreach ($phenotypes as $coded_phenotype) {
                         // parse out the codes
                         $coded_phenotype = trim($coded_phenotype);
                         if (!$coded_phenotype) {
                             continue;
                         }
                         $phenotype = preg_replace("/\\{.*\\}/", "", $coded_phenotype);
                         $phenotype_id = parent::getRes() . "" . md5(strtolower($phenotype));
                         $entity_id = parent::getRes() . "" . $k1;
                         parent::addRDF(parent::describeIndividual($phenotype_id, $phenotype, parent::getVoc() . 'Characteristic') . parent::describeClass(parent::getVoc() . 'Characteristic', 'Characteristic') . parent::triplify($cs_uri, parent::getVoc() . "feature", $phenotype_id) . parent::describeIndividual($entity_id, $k1, parent::getVoc() . "Entity") . parent::describeClass(parent::getVoc() . "Entity", "Entity") . parent::triplify($phenotype_id, parent::getVoc() . "characteristic-of", $entity_id));
                         // parse out the vocab references
                         preg_match_all("/\\{([0-9A-Za-z \\:\\-\\.]+)\\}|;/", $coded_phenotype, $codes);
                         //preg_match_all("/((UMLS|HPO HP|SNOMEDCT|ICD10CM|ICD9CM|EOM ID)\:[A-Z0-9]+)/",$coded_phenotype,$m);
                         if (isset($codes[1][0])) {
                             foreach ($codes[1] as $entry) {
                                 $entries = explode(" ", trim($entry));
                                 foreach ($entries as $e) {
                                     if ($e == "HPO" || $e == "EOM") {
                                         continue;
                                     }
                                     $this->getRegistry()->parseQName($e, $ns, $id);
                                     if (!isset($ns) || $ns == '') {
                                         $b = explode(".", $id);
                                         $ns = "omim";
                                         $id = $b[0];
                                     } else {
                                         $ns = str_replace(array("hpo", "id", "icd10cm", "icd9cm", "snomedct"), array("hp", "eom", "icd10", "icd9", "snomed"), $ns);
                                     }
                                     parent::addRDF(parent::triplify($phenotype_id, parent::getVoc() . "x-{$ns}", "{$ns}:{$id}"));
                                 }
                                 // foreach
                             }
                             // foreach
                         }
                         // codes
                     }
                     //foreach
                 }
                 // foreach
             }
             // exists
         }
     }
     // clinical synopsis
     // genemap
     if (isset($o['geneMap'])) {
         $map = $o['geneMap'];
         if (isset($map['chromosome'])) {
             parent::addRDF(parent::triplifyString($omim_uri, parent::getVoc() . "chromosome", (string) $map['chromosome']));
         }
         if (isset($map['cytoLocation'])) {
             parent::addRDF(parent::triplifyString($omim_uri, parent::getVoc() . "cytolocation", (string) $map['cytoLocation']));
         }
         if (isset($map['geneSymbols'])) {
             $b = preg_split("/[,;\\. ]+/", $map['geneSymbols']);
             foreach ($b as $symbol) {
                 parent::addRDF(parent::triplify($omim_uri, parent::getVoc() . "gene-symbol", "symbol:" . trim($symbol)));
             }
         }
         if (isset($map['geneName'])) {
             $b = explode(",", $map['geneName']);
             foreach ($b as $name) {
                 parent::addRDF(parent::triplifyString($omim_uri, parent::getVoc() . "gene-name", trim($name)));
             }
         }
         if (isset($map['mappingMethod'])) {
             $b = explode(",", $map['mappingMethod']);
             foreach ($b as $c) {
                 $mapping_method = trim($c);
                 $method_uri = $this->get_method_type($mapping_method);
                 if ($method_uri !== false) {
                     parent::addRDF(parent::triplify($omim_uri, parent::getVoc() . "mapping-method", $method_uri));
                 }
             }
         }
         if (isset($map['mouseGeneSymbol'])) {
             $b = explode(",", $map['mouseGeneSymbol']);
             foreach ($b as $c) {
                 parent::addRDF(parent::triplify($omim_uri, parent::getVoc() . "mouse-gene-symbol", "symbol:" . strtoupper($c)));
             }
         }
         if (isset($map['mouseMgiID'])) {
             $b = explode(",", $map['mouseMgiID']);
             foreach ($b as $c) {
                 parent::addRDF(parent::triplify($omim_uri, parent::getVoc() . "x-mgi", $c));
             }
         }
         if (isset($map['geneInheritance']) && $map['geneInheritance'] != '') {
             parent::addRDF(parent::triplifyString($omim_uri, parent::getVoc() . "gene-inheritance", $map['geneInheritance']));
         }
     }
     if (isset($o['phenotypeMapList'])) {
         foreach ($o['phenotypeMapList'] as $i => $phenotypeMap) {
             $phenotypeMap = $phenotypeMap['phenotypeMap'];
             $pm_uri = parent::getRes() . $omim_id . "_pm_" . ($i + 1);
             parent::addRDF(parent::describeIndividual($pm_uri, "phenotype mapping for {$omim_id}", parent::getVoc() . "Phenotype-Map") . parent::describeClass(parent::getVoc() . "Phenotype-Map", "OMIM Phenotype-Map") . parent::triplify($omim_uri, parent::getVoc() . "phenotype-map", $pm_uri));
             foreach (array_keys($phenotypeMap) as $k) {
                 if (in_array($k, array("mimNumber", "phenotypeMimNumber", "phenotypicSeriesMimNumber"))) {
                     parent::addRDF(parent::triplify($pm_uri, parent::getVoc() . $k, "omim:" . $phenotypeMap[$k]));
                 } else {
                     if ($k == "geneSymbols") {
                         $l = explode(", ", $phenotypeMap[$k]);
                         foreach ($l as $gene) {
                             parent::addRDF(parent::triplify($pm_uri, parent::getVoc() . "gene-symbol", "hgnc.symbol:" . $gene));
                         }
                     } else {
                         if ($k == "phenotypeMappingKey") {
                             $l = $this->get_phenotype_mapping_method_type($phenotypeMap[$k]);
                             parent::addRDF(parent::triplify($pm_uri, parent::getVoc() . "mapping-method", $l));
                         } else {
                             parent::addRDF(parent::triplifyString($pm_uri, parent::getVoc() . $k, $phenotypeMap[$k]));
                         }
                     }
                 }
             }
         }
     }
     // references
     if (isset($o['referenceList'])) {
         foreach ($o['referenceList'] as $i => $r) {
             $r = $r['reference'];
             if (isset($r['pubmedID'])) {
                 $pubmed_uri = "pubmed:" . $r['pubmedID'];
                 parent::addRDF(parent::triplify($omim_uri, parent::getVoc() . "article", $pubmed_uri));
                 $title = 'article';
                 if (isset($r['title'])) {
                     $title = $r['title'];
                 }
                 parent::addRDF(parent::describe($pubmed_uri, addslashes($r['title'])));
                 if (isset($r['articleUrl'])) {
                     parent::addRDF($this->QQuadO_URL($pubmed_uri, "rdfs:seeAlso", htmlentities($r['articleUrl'])));
                 }
             }
         }
     }
     // external ids
     if (isset($o['externalLinks'])) {
         foreach ($o['externalLinks'] as $k => $id) {
             if ($id === false) {
                 continue;
             }
             $ns = '';
             switch ($k) {
                 case 'approvedGeneSymbols':
                     $ns = 'symbol';
                     break;
                 case 'geneIDs':
                     $ns = 'ncbigene';
                     break;
                 case 'ncbiReferenceSequences':
                     $ns = 'gi';
                     break;
                 case 'genbankNucleotideSequences':
                     $ns = 'gi';
                     break;
                 case 'proteinSequences':
                     $ns = 'gi';
                     break;
                 case 'uniGenes':
                     $ns = 'unigene';
                     break;
                 case 'ensemblIDs':
                     $ns = 'ensembl';
                     break;
                 case 'swissProtIDs':
                     $ns = 'uniprot';
                     break;
                 case 'mgiIDs':
                     $ns = 'mgi';
                     $b = explode(":", $id);
                     $id = $b[1];
                     break;
                 case 'flybaseIDs':
                     $ns = 'flybase';
                     break;
                 case 'zfinIDs':
                     $ns = 'zfin';
                     break;
                 case 'hprdIDs':
                     $ns = 'hprd';
                     break;
                 case 'orphanetDiseases':
                     $ns = 'orphanet';
                     break;
                 case 'refSeqAccessionIDs':
                     $ns = 'refseq';
                     break;
                 case 'ordrDiseases':
                     $ns = 'ordr';
                     $b = explode(";;", $id);
                     $id = $b[0];
                     break;
                 case 'snomedctIDs':
                     $ns = 'snomed';
                     break;
                 case 'icd10cmIDs':
                     $ns = 'icd10';
                     break;
                 case 'icd9cmIDs':
                     $ns = 'icd9';
                     break;
                 case 'umlsIDs':
                     $ns = 'umls';
                     break;
                 case 'wormbaseIDs':
                     $ns = 'wormbase';
                     break;
                 case 'diseaseOntologyIDs':
                     $ns = 'do';
                     break;
                     // specifically ignorning
                 // specifically ignorning
                 case 'geneTests':
                 case 'cmgGene':
                 case 'geneticAllianceIDs':
                     // #
                 // #
                 case 'nextGxDx':
                 case 'nbkIDs':
                     // NBK1207;;Alport Syndrome and Thin Basement Membrane Nephropathy
                 // NBK1207;;Alport Syndrome and Thin Basement Membrane Nephropathy
                 case 'newbornScreeningUrls':
                 case 'decipherUrls':
                 case 'geneReviewShortNames':
                 case 'locusSpecificDBs':
                 case 'geneticsHomeReferenceIDs':
                 case 'omiaIDs':
                 case 'coriellDiseases':
                 case 'clinicalDiseaseIDs':
                 case 'possumSyndromes':
                 case 'keggPathways':
                 case 'gtr':
                 case 'gwasCatalog':
                 case 'mgiHumanDisease':
                 case 'wormbaseDO':
                 case 'dermAtlas':
                     // true/false
                     break;
                 default:
                     echo "unhandled external link {$k} {$id}" . PHP_EOL;
             }
             $ids = explode(",", $id);
             foreach ($ids as $id) {
                 if ($ns) {
                     if (strstr($id, ";;") === FALSE) {
                         parent::addRDF(parent::triplify($omim_uri, parent::getVoc() . "x-{$ns}", $ns . ':' . $id));
                     } else {
                         $b = explode(";;", $id);
                         // multiple ids//names
                         foreach ($b as $c) {
                             preg_match("/([a-z])/", $c, $m);
                             if (!isset($m[1])) {
                                 parent::addRDF(parent::triplify($omim_uri, parent::getVoc() . "x-{$ns}", $ns . ':' . $c));
                             }
                         }
                     }
                 }
             }
         }
     }
     //external links
 }
Exemplo n.º 15
0
 function models()
 {
     $tax_ids = array("Caenorhabditis elegans" => "6239", "Mus musculus" => "10090", "Saccharomyces cerevisiae" => "4932", "Drosophila melanogaster" => "7227", "Podospora anserina" => "5145", "Mesocricetus auratus" => "10036", "Schizosaccharomyces pombe" => "4896", "Danio rerio" => "7955");
     $h = explode(",", parent::getReadFile()->read());
     $expected_columns = 8;
     if (($n = count($h)) != $expected_columns) {
         trigger_error("Found {$n} columns in gene file - expecting {$expected_columns}!", E_USER_WARNING);
         return false;
     }
     /*
     [0] GenAge ID
     [1] symbol	
     [2] name	
     [3] organism	
     [4] entrez gene id	
     [5] avg lifespan change (max obsv)	
     [6] lifespan effect	
     [7] longevity influence
     */
     while ($l = parent::getReadFile()->read(200000)) {
         $data = str_getcsv($l);
         $genage = str_pad($data[0], 4, "0", STR_PAD_LEFT);
         $gene_symbol = $data[1];
         $name = $data[2];
         $organism = $data[3];
         $ncbi_gene_id = $data[4];
         $max_percent_obsv_avg_lifespan_change = $data[5];
         $lifespan_effect = $data[6];
         $longevity_influence = $data[7];
         $genage_id = parent::getNamespace() . $genage;
         parent::addRDF(parent::describeIndividual($genage_id, $name, parent::getVoc() . "Aging-Related-Gene") . parent::describeClass(parent::getVoc() . "Aging-Related-Gene", "Aging Related Gene"));
         parent::addRDF(parent::triplifyString($genage_id, parent::getVoc() . "gene-symbol", parent::safeLiteral($gene_symbol)));
         parent::addRDF(parent::triplify($genage_id, parent::getVoc() . "taxon", "ncbitaxon:" . $tax_ids[$organism]));
         if ($ncbi_gene_id !== "") {
             parent::addRDF(parent::triplify($genage_id, parent::getVoc() . "x-ncbigene", "ncbigene:" . $ncbi_gene_id));
         }
         if ($max_percent_obsv_avg_lifespan_change !== "") {
             parent::addRDF(parent::triplifyString($genage_id, parent::getVoc() . "maximum-percent-observed-average-lifespan-change", parent::safeLiteral($max_percent_obsv_avg_lifespan_change)));
         }
         if ($lifespan_effect == "Increase and Decrease") {
             parent::addRDF(parent::triplifyString($genage_id, parent::getVoc() . "lifespan-effect", "increase") . parent::triplifyString($genage_id, parent::getVoc() . "lifespan-effect", "decrease"));
         } else {
             parent::addRDF(parent::triplifyString($genage_id, parent::getVoc() . "lifespan-effect", strtolower($lifespan_effect)));
         }
         parent::addRDF(parent::triplifyString($genage_id, parent::getVoc() . "longevity-influence", strtolower($longevity_influence)));
         parent::WriteRDFBufferToWriteFile();
     }
 }
Exemplo n.º 16
0
 function gene_expression()
 {
     $h = explode(",", parent::getReadFile()->read());
     $expected_columns = 8;
     if (($n = count($h)) != $expected_columns) {
         trigger_error("Found {$n} columns in gene file - expecting {$expected_columns}!", E_USER_WARNING);
         return false;
     }
     while ($l = parent::getReadFile()->read(200000)) {
         $data = str_getcsv($l);
         $mgi_symbol = $data[0];
         $mgi_description = $data[1];
         $geneid = $data[2];
         $total_datasets = $data[3];
         $total_ovexp = $data[4];
         $total_underexp = $data[5];
         $p_value = $data[6];
         $expression = $data[7];
         $id = parent::getRes() . md5($geneid . $total_datasets . $total_ovexp . $total_underexp . $p_value . $expression);
         $evidence_id = parent::getRes() . md5($geneid . $total_datasets . $total_ovexp . $total_underexp . $p_value . $expression . "_evidence");
         $label = "Dietary restriction induced " . $expression . "-expression of " . $mgi_symbol . " based on microarray results from " . $total_datasets . " datasets, with p-value " . $p_value;
         $type_label = "Gene " . ucfirst($expression) . " Expression";
         $type = parent::getVoc() . str_replace(" ", "-", $type_label);
         parent::addRDF(parent::describeIndividual($id, $label, $type) . parent::describeClass($type, $type_label) . parent::triplify($id, parent::getVoc() . "gene", "ncbigene:" . $geneid) . parent::triplifyString("ncbigene:" . $geneid, parent::getVoc() . "mgi-gene-symbol", $mgi_symbol) . parent::triplifyString("ncbigene:" . $geneid, parent::getVoc() . "mgi-gene-description", $mgi_description) . parent::triplify($id, parent::getVoc() . "evidence", $evidence_id) . parent::triplifyString($id, parent::getVoc() . "perturbation-context", "dietary restriction") . parent::triplifyString($evidence_id, parent::getVoc() . "total-number-datasets", $total_datasets) . parent::triplifyString($evidence_id, parent::getVoc() . "total-number-datasets-overexpressed", $total_ovexp) . parent::triplifyString($evidence_id, parent::getVoc() . "total-number-datasets-underexpressed", $total_underexp) . parent::triplifyString($evidence_id, parent::getVoc() . "p-value", $p_value));
         parent::writeRDFBufferToWriteFile();
     }
     //while
 }
Exemplo n.º 17
0
 function Parse($file)
 {
     parent::getReadFile()->read();
     // skip the first comment line
     $line = 1;
     $first = true;
     while ($l = parent::getReadFile()->read(500000)) {
         if ($l[0] == "#") {
             // dataset attributes
             $a = explode('=', trim($l));
             $r = $this->getVoc() . substr($a[0], 2);
             if (isset($a[1])) {
                 $v = $a[1];
                 if ($r == "affymetrix_vocabulary:genome-version-create_date") {
                     $x = explode("-", $a[1]);
                     if ($x[2] == "00") {
                         $x[2] = "01";
                     }
                     $v = implode("-", $x);
                 }
                 parent::addRDF(parent::triplifyString(parent::getDatasetURI(), $r, $v) . parent::describe($r, "{$r}"));
             }
             continue;
         }
         if ($first == true) {
             $first = false;
             // header
             $header = explode(",", str_replace('"', '', trim($l)));
             //				print_r($header);exit;
             $n = count($header);
             if ($n != 41) {
                 trigger_error("Expecting 41 columns, found {$n} in header on line {$line}!", E_USER_ERROR);
                 exit;
             }
             continue;
         }
         $a = explode('","', substr($l, 1, -2));
         $n = count($a);
         if ($n != 41) {
             trigger_error("Expecting 41 columns, found {$n} on line {$line}!", E_USER_ERROR);
             exit;
         }
         parent::writeRDFBufferToWriteFile();
         $id = $a[0];
         $qname = "affymetrix:{$id}";
         $label = "probeset {$a['0']} on GeneChip {$a['1']} ({$a['2']})";
         parent::addRDF(parent::describeIndividual($qname, $label, $this->getVoc() . "Probeset") . parent::describeClass($this->getVoc() . "Probeset", "Affymetrix probeset"));
         trigger_error($id, E_USER_NOTICE);
         // now process the entries
         foreach ($a as $k => $v) {
             if (trim($v) == '---') {
                 continue;
             }
             // multi-valued entries are separated by ////
             $b = explode(" /// ", $v);
             $r = $this->Map($k);
             if (isset($r)) {
                 foreach ($b as $c) {
                     $d = explode(" // ", $c);
                     if ($r == 'symbol') {
                         $d[0] = str_replace(" ", "-", $d[0]);
                     }
                     $s = $this->getRegistry()->getPreferredPrefix($r);
                     if ($s == "ec") {
                         $e = explode(":", $d[0]);
                         $d[0] = $e[1];
                     }
                     $this->addRDF(parent::triplify($qname, $this->getVoc() . "x-{$s}", "{$s}:" . $d[0]) . parent::describeProperty($this->getVoc() . "x-{$s}", "a relation to {$s}"));
                 }
             } else {
                 // we handle manually
                 unset($rel);
                 $label = $header[$k];
                 switch ($label) {
                     case 'GeneChip Array':
                         $array_id = parent::getRes() . str_replace(" ", "-", $v);
                         parent::addRDF(parent::triplify($qname, $this->getVoc() . "genechip-array", $array_id) . parent::describeIndividual($array_id, "Affymetrix {$v} GeneChip array", $this->getVoc() . "Genechip-Array") . parent::describeClass($this->getVoc() . "Genechip-Array", "Affymetrix GeneChip array"));
                         break;
                     case 'Gene Ontology Biological Process':
                         if (!isset($rel)) {
                             $rel = 'go-process';
                             $prefix = "go";
                         }
                     case 'Gene Ontology Cellular Component':
                         if (!isset($rel)) {
                             $rel = 'go-location';
                             $prefix = "go";
                         }
                     case 'Gene Ontology Molecular Function':
                         if (!isset($rel)) {
                             $rel = 'go-function';
                             $prefix = "go";
                         }
                         $b = explode(" /// ", $v);
                         foreach ($b as $c) {
                             $d = explode(" // ", $c);
                             parent::addRDF($this->triplify($qname, $this->getVoc() . $rel, "{$prefix}:" . $d[0]) . $this->describeProperty($this->getVoc() . $rel, "{$rel}"));
                         }
                         break;
                     case 'Transcript Assignments':
                         $b = explode(" /// ", $v);
                         foreach ($b as $c) {
                             $d = explode(" // ", $c);
                             $id = $d[0];
                             $prefix = $d[2];
                             if ($prefix == '---' || $id == '---') {
                                 continue;
                             } else {
                                 if ($prefix == 'gb' || $prefix == 'gb_htc') {
                                     $prefix = 'genbank';
                                 } else {
                                     if ($prefix == 'ncbibacterial') {
                                         $prefix = 'gi';
                                     } else {
                                         if ($prefix == 'ncbi_bacterial') {
                                             $prefix = 'gi';
                                         } else {
                                             if ($prefix == 'ens') {
                                                 $prefix = 'ensembl';
                                             } else {
                                                 if ($prefix == 'ncbi_mito' || $prefix == 'ncbi_organelle' || $prefix == 'organelle') {
                                                     $prefix = 'refseq';
                                                 } else {
                                                     if ($prefix == 'affx' || $prefix == 'unknown' || $prefix == "prop") {
                                                         $prefix = 'affymetrix';
                                                     } else {
                                                         if ($prefix == 'tigr_2004_08') {
                                                             $prefix = 'tigr';
                                                         } else {
                                                             if ($prefix == 'tigr-plantta') {
                                                                 $prefix = 'genbank';
                                                             } else {
                                                                 if ($prefix == 'newrs.gi') {
                                                                     $prefix = 'gi';
                                                                 } else {
                                                                     if ($prefix == 'newRS.gi') {
                                                                         $prefix = 'gi';
                                                                     } else {
                                                                         if ($prefix == 'primate_viral') {
                                                                             $prefix = 'genbank';
                                                                         } else {
                                                                             if ($prefix == 'jgi-bacterial') {
                                                                                 $prefix = 'ncbigene';
                                                                             } else {
                                                                                 if ($prefix == 'tb') {
                                                                                     $prefix = 'tuberculist';
                                                                                 } else {
                                                                                     if ($prefix == 'pa') {
                                                                                         $prefix = 'pseudomonas';
                                                                                     } else {
                                                                                         if ($prefix == 'gi|53267') {
                                                                                             $prefix = 'gi';
                                                                                             $id = '53267';
                                                                                         } else {
                                                                                             if ($prefix == 'broad-tcup') {
                                                                                                 $e = explode("-", $id);
                                                                                                 $id = $e[0];
                                                                                             } else {
                                                                                                 if ($prefix == 'organelle') {
                                                                                                     $e = explode("-", $id);
                                                                                                     $prefix = 'genbank';
                                                                                                     $id = $e[0];
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             parent::addRDF(parent::triplify($qname, $this->getVoc() . "transcript-assignment", "{$prefix}:{$id}") . parent::describeProperty($this->getVoc() . "transcript-assignment", "transcript assignment"));
                         }
                         break;
                     case 'Annotation Transcript Cluster':
                         /*
                         							$id = substr($v,0,strpos($v,"("));
                         								
                         
                         							$rel = str_replace(" ","-",strtolower($label));
                         							$this->AddRDF($this->triplify($qname,parent::getVoc()."$rel", "refseq:$id"));
                         */
                         break;
                     case 'Annotation Date':
                         // Jun 9, 2011
                         $rel = "annotation-date";
                         preg_match("/^([A-Za-z]+) ([0-9]+), ([0-9]{4})\$/", $v, $m);
                         if (count($m) == 4) {
                             array_shift($m);
                             list($m, $day, $year) = $m;
                             $month = $this->getMonth($m);
                             if (!$day || $day == "0") {
                                 $day = "01";
                             }
                             $date = $year . "-" . $month . "-" . str_pad($day, 2, "0", STR_PAD_LEFT) . "T00:00:00Z";
                             parent::addRDF(parent::triplifyString($qname, $this->getVoc() . $rel, $date, "xsd:dateTime") . parent::describeProperty($this->getVoc() . $rel, "{$rel}"));
                         } else {
                             trigger_error("could not match date from {$v}", E_USER_ERROR);
                         }
                         break;
                     case 'Species Scientific Name':
                         break;
                     case 'Transcript ID(Array Design)':
                         if (!isset($rel)) {
                             $rel = 'transcript';
                         }
                     case 'Sequence type':
                     default:
                         if (!isset($rel)) {
                             $rel = str_replace(" ", "-", strtolower($label));
                         }
                         $b = explode(" /// ", $v);
                         foreach ($b as $c) {
                             parent::addRDF(parent::triplifyString($qname, $this->getVoc() . $rel, stripslashes($c)) . parent::describeProperty($this->getVoc() . $rel, "{$rel}"));
                         }
                         break;
                 }
                 //  switch
             }
             // else
         }
         $this->WriteRDFBufferToWriteFile();
     }
 }
Exemplo n.º 18
0
 function process($file)
 {
     $z = 1;
     while ($l = parent::getReadFile()->read(100000)) {
         if ($z % 100000 == 0) {
             parent::clear();
         }
         if ($l[0] == "!") {
             continue;
         }
         $fields = explode("\t", $l);
         if (count($fields) != 17) {
             trigger_error("Expected 17 columns, but found " . count($fields), E_USER_ERROR);
             return false;
         }
         //get the Go id
         $db = $fields[0];
         $id = $fields[1];
         $symbol = $fields[2];
         $qualifier = $fields[3];
         $goid = substr($fields[4], 3);
         $refs = $this->getDbReferences($fields[5]);
         $eco = $this->getEvidenceCodeLabelArr($fields[6]);
         $aspect = $this->getAspect($fields[8]);
         $label = $fields[9];
         $synonyms = explode("|", $fields[10]);
         $taxid = $fields[12];
         $date = $this->parseDate($fields[13]);
         $assignedBy = $fields[14];
         //entity id
         $eid = $this->getdbURI($db, $id);
         if (!$eid) {
             print_r($fields);
             continue;
         }
         parent::addRDF(parent::describeIndividual($eid, $label, parent::getVoc() . "GO-Annotation") . parent::describeClass(parent::getVoc() . "GO-Annotation", "GO Annotation") . parent::triplifyString($eid, parent::getVoc() . "symbol", $symbol));
         parent::addRDF(parent::triplify($eid, parent::getVoc() . "x-taxonomy", $taxid));
         foreach ($synonyms as $s) {
             if (!empty($s)) {
                 parent::addRDF(parent::triplifyString($eid, parent::getVoc() . "synonym", $s));
             }
         }
         $rel = $aspect;
         if ($qualifier == 'NOT') {
             if ($aspect == 'process') {
                 $rel = 'not-in-process';
             }
             if ($aspect == 'function') {
                 $rel = 'not-has-function';
             }
             if ($aspect == 'component') {
                 $rel = 'not-in-component';
             }
         }
         parent::addRDF(parent::describeObjectProperty(parent::getVoc() . $rel, str_replace("-", " ", $rel)) . parent::triplify($eid, parent::getVoc() . $rel, "go:" . $goid));
         $type = key($eco);
         $aid = parent::getRes() . $file . "_" . $z++;
         parent::addRDF(parent::describeObjectProperty(parent::getVoc() . "go-annotation", "GO annotation") . parent::triplify($eid, parent::getVoc() . "go-annotation", $aid));
         $cat = parent::getRes() . md5($aspect);
         parent::addRDF(parent::describeIndividual($aid, "{$id}-go:{$goid} association", parent::getVoc() . "GO-Annotation") . parent::triplify($aid, parent::getVoc() . "target", $eid) . parent::triplify($aid, parent::getVoc() . "go-term", "go:" . $goid) . parent::triplify($aid, parent::getVoc() . "evidence", "eco:" . $eco[$type][1]) . parent::triplify($aid, parent::getVoc() . "go-category", $cat) . parent::describeClass($cat, $aspect) . parent::triplifyString($aid, parent::getVoc() . "assigned-by", $assignedBy));
         if ($date != '') {
             parent::addRDF(parent::triplifyString($aid, parent::getVoc() . "entry-date", $date . "T00:00:00Z", "xsd:dateTime"));
         }
         foreach ($refs as $ref) {
             $b = explode(":", $ref);
             if ($b[0] == 'PMID') {
                 parent::addRDF(parent::triplify($aid, parent::getVoc() . "article", "pubmed:" . $b[1]));
             }
         }
         //write RDF to file
         parent::writeRDFBufferToWriteFile();
     }
 }
Exemplo n.º 19
0
 function process()
 {
     $header = $this->GetReadFile()->Read(200000);
     $header_arr = explode("\t", $header);
     $n = 41;
     $c = count($header_arr);
     if ($c != $n) {
         echo PHP_EOL;
         print_r($header_arr);
         trigger_error("Expected {$n} columns, found {$c} . please update the script", E_USER_ERROR);
         exit;
     }
     while ($l = $this->GetReadFile()->Read(4096)) {
         $fields = explode("\t", $l);
         $id = strtolower($fields[0]);
         $approved_symbol = $fields[1];
         $approved_name = $fields[2];
         $status = $fields[3];
         $locus_type = $fields[4];
         $locus_group = $fields[5];
         $previous_symbols = $fields[6];
         $previous_names = $fields[7];
         $synonyms = $fields[8];
         $name_synonyms = $fields[9];
         $chromosome = $fields[10];
         $date_approved = $fields[11];
         $date_modified = $fields[12];
         $date_symbol_changed = $fields[13];
         $date_name_changed = $fields[14];
         $accession_numbers = $fields[15];
         $enzyme_ids = $fields[16];
         $entrez_gene_id = $fields[17];
         $ensembl_gene_id = $fields[18];
         $mouse_genome_database_id = $fields[19];
         $specialist_database_links = $fields[20];
         $specialist_database_ids = $fields[21];
         $pubmed_ids = $fields[22];
         $refseq_ids = $fields[23];
         $gene_family_tag = $fields[24];
         $gene_family_description = $fields[25];
         $record_type = $fields[26];
         $primary_ids = $fields[27];
         $secondary_ids = $fields[28];
         $ccd_ids = $fields[29];
         $vega_ids = $fields[30];
         $locus_specific_databases = $fields[31];
         $entrez_gene_id_mappeddatasuppliedbyNCBI = $fields[32];
         $omim_id_mappeddatasuppliedbyNCBI = $fields[33];
         $refseq_mappeddatasuppliedbyNCBI = $fields[34];
         $uniprot_id_mappeddatasuppliedbyUniProt = $fields[35];
         $ensembl_id_mappeddatasuppliedbyEnsembl = $fields[36];
         $vega_id_mappeddatasuppliedbyVega = $fields[37];
         $ucsc_id_mappeddatasuppliedbyUCSC = $fields[38];
         $mouse_genome_database_id_mappeddatasuppliedbyMGI = $fields[39];
         $rat_genome_database_id_mappeddatasuppliedbyRGD = $fields[40];
         $id_res = $id;
         $id_label = "Gene Symbol for " . $approved_symbol;
         parent::AddRDF(parent::triplify($id_res, "rdf:type", $this->getVoc() . "Gene-Symbol") . parent::describeIndividual($id_res, $id_label, $this->getVoc() . "Gene-Symbol") . parent::describeClass($this->getVoc() . "Gene-Symbol", "HGNC Official Gene Symbol"));
         if (!empty($approved_symbol)) {
             $s = "hgnc.symbol:" . $approved_symbol;
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "approved-symbol", utf8_encode(htmlspecialchars($approved_symbol))) . parent::describeProperty($this->getVoc() . "approved-symbol", "HGNC approved gene symbol", "The official gene symbol that has been approved by the HGNC and is publicly available. Symbols are approved based on specific HGNC nomenclature guidelines. In the HTML results page this ID links to the HGNC Symbol Report for that gene") . parent::describeIndividual($s, $approved_symbol, parent::getVoc() . "Approved-Gene-Symbol") . parent::describeClass(parent::getVoc() . "Approved-Gene-Symbol", "Approved Gene Symbol") . parent::triplify($id_res, parent::getVoc() . "has-approved-symbol", $s) . parent::triplify($s, parent::getVoc() . "is-approved-symbol-of", $id_res));
         }
         if (!empty($approved_name)) {
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "approved-name", utf8_encode(htmlspecialchars($approved_name))) . parent::describeProperty($this->getVoc() . "approved-name", "HGNC approved name", "The official gene name that has been approved by the HGNC and is publicly available. Names are approved based on specific HGNC nomenclature guidelines."));
         }
         if (!empty($status)) {
             $s = $this->getVoc() . str_replace(" ", "-", $status);
             parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "status", $s) . parent::describeProperty($this->getVoc() . "status", "HGNC status", "Indicates whether the gene is classified as: Approved - these genes have HGNC-approved gene symbols. Entry withdrawn - these previously approved genes are no longer thought to exist. Symbol withdrawn - a previously approved record that has since been merged into a another record.") . parent::describeClass($s, $status, $this->getVoc() . "Status"));
         }
         if (!empty($locus_id)) {
             $locus_res = $this->getRes() . $id . "_LOCUS";
             parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "locus", $locus_res) . parent::triplifyString($locus_res, $this->getVoc() . "locus-type", utf8_encode(htmlspecialchars($locus_type))) . parent::triplifyString($locus_res, $this->getVoc() . "locus-group", utf8_encode(htmlspecialchars($locus_group))) . parent::describeProperty($this->getVoc() . "locus-type", "locus type", "Specifies the type of locus described by the given entry") . parent::describeProperty($this->getVoc() . "locus-group", "locus group", "Groups locus types together into related sets. Below is a list of groups and the locus types within the group"));
         }
         if (!empty($previous_symbols)) {
             $previous_symbols = explode(", ", $previous_symbols);
             foreach ($previous_symbols as $previous_symbol) {
                 $previous_symbol_uri = "hgnc.symbol:" . $previous_symbol;
                 parent::AddRDF(parent::describeIndividual($previous_symbol_uri, $previous_symbol, parent::getVoc() . "Previous-Symbol") . parent::describeClass(parent::getVoc() . "Previous-Symbol", "Previous Symbol") . parent::triplify($id_res, $this->getVoc() . "previous-symbol", $previous_symbol_uri) . parent::describeProperty($this->getVoc() . "previous-symbol", "HGNC previous symbol", "Symbols previously approved by the HGNC for this gene"));
             }
         }
         if (!empty($previous_names)) {
             $previous_names = explode(", ", $previous_names);
             foreach ($previous_names as $previous_name) {
                 $previous_name = str_replace("\"", "", $previous_name);
                 parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "previous-name", utf8_encode(htmlspecialchars($previous_name))) . parent::describeProperty($this->getVoc() . "previous-name", "HGNC previous name", "Gene names previously approved by the HGNC for this gene"));
             }
         }
         if (!empty($synonyms)) {
             $synonyms = explode(", ", $synonyms);
             foreach ($synonyms as $synonym) {
                 parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "synonym", utf8_encode(htmlspecialchars($synonym))) . parent::describeProperty($this->getVoc() . "synonym", "synonym", "Other symbols used to refer to this gene"));
             }
         }
         if (!empty($name_synonyms)) {
             $name_synonyms = explode(", ", $name_synonyms);
             foreach ($name_synonyms as $name_synonym) {
                 $name_synonym = str_replace("\"", "", $name_synonym);
                 parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "name-synonym", utf8_encode(htmlspecialchars($name_synonym))) . parent::describeProperty($this->getVoc() . "name-synonym", "name synonym", "Other names used to refer to this gene"));
             }
         }
         if (!empty($chromosome)) {
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "chromosome", utf8_encode(htmlspecialchars($chromosome))) . parent::describeProperty($this->getVoc() . "chromosome", "chromosome", "Indicates the location of the gene or region on the chromosome"));
         }
         if (!empty($date_approved)) {
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "date-approved", $date_approved, "xsd:date") . parent::describeProperty($this->getVoc() . "date-approved", "date approved", "Date the gene symbol and name were approved by the HGNC"));
         }
         if (!empty($date_modified)) {
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "date-modified", $date_modified, "xsd:date") . parent::describeProperty($this->getVoc() . "date-modified", "date modified", "the date the entry was modified by the HGNC"));
         }
         if (!empty($date_symbol_changed)) {
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "date-symbol-changed", $date_symbol_changed, "xsd:date") . parent::describeProperty($this->getVoc() . "date-symbol-changed", "date symbol changed", "The date the gene symbol was last changed by the HGNC from a previously approved symbol. Many genes receive approved symbols and names which are viewed as temporary (eg C2orf#) or are non-ideal when considered in the light of subsequent information. In the case of individual genes a change to the name (and subsequently the symbol) is only made if the original name is seriously misleading"));
         }
         if (!empty($date_name_changed)) {
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "date-name-changed", $date_name_changed, "xsd:date") . parent::describeProperty($this->getVoc() . "date-name-changed", "date name changed", "The date the gene name was last changed by the HGNC from a previously approved name"));
         }
         if (!empty($accession_numbers)) {
             $accession_numbers = explode(", ", $accession_numbers);
             foreach ($accession_numbers as $accession_number) {
                 parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "accession", utf8_encode(htmlspecialchars($accession_number))) . parent::describeProperty($this->getVoc() . "accession", "accession number", "Accession numbers for each entry selected by the HGNC"));
             }
         }
         if (!empty($enzyme_ids)) {
             $enzyme_ids = explode(", ", $enzyme_ids);
             foreach ($enzyme_ids as $enzyme_id) {
                 parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "x-ec", utf8_encode(htmlspecialchars($enzyme_id))) . parent::describeProperty($this->getVoc() . "x-ec", "Enzyme Commission (EC) number", "Enzyme entries have Enzyme Commission (EC) numbers associated with them that indicate the hierarchical functional classes to which they belong"));
             }
         }
         if (!empty($entrez_gene_id)) {
             parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-ncbigene", "ncbigene:{$entrez_gene_id}") . parent::describeProperty($this->getVoc() . "x-ncbigene", "NCBI Gene", "NCBI Gene provides curated sequence and descriptive information about genetic loci including official nomenclature, synonyms, sequence accessions, phenotypes, EC numbers, MIM numbers, UniGene clusters, homology, map locations, and related web sites"));
         }
         if (!empty($ensembl_gene_id)) {
             parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-ensembl", "ensembl:{$ensembl_gene_id}") . parent::describeProperty($this->getVoc() . "x-ensembl", "Ensembl Gene"));
         }
         if (!empty($mouse_genome_database_id)) {
             if (strpos($mouse_genome_database_id, "MGI:") !== FALSE) {
                 $mouse_genome_database_id = substr($mouse_genome_database_id, 4);
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-mgi", "mgi:{$mouse_genome_database_id}") . parent::describeProperty($this->getVoc() . "x-mgi", "MGI entry"));
             }
         }
         if (!empty($specialist_database_links)) {
             $specialist_database_links = explode(", ", $specialist_database_links);
             foreach ($specialist_database_links as $specialist_database_link) {
                 preg_match('/href="(\\S+)"/', $specialist_database_link, $matches);
                 if (!empty($matches[1])) {
                     parent::AddRDF(parent::QQuadO_URL($id_res, $this->getVoc() . "xref", $matches[1]) . parent::describeProperty($this->getVoc() . "xref", "Specialist database references."));
                 }
             }
         }
         if (!empty($pubmed_ids)) {
             $pubmed_ids = explode(", ", $pubmed_ids);
             foreach ($pubmed_ids as $pubmed_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-pubmed", "pubmed:" . trim($pubmed_id)) . parent::describeProperty($this->getVoc() . "x-pubmed", "NCBI PubMed entry", "Identifier that links to published articles relevant to the entry in the NCBI's PubMed database."));
             }
         }
         if (!empty($refseq_ids)) {
             $refseq_ids = explode(", ", $refseq_ids);
             foreach ($refseq_ids as $refseq_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-refseq", "refseq:" . trim($refseq_id)) . parent::describeProperty($this->getVoc() . "x-refseq", "NCBI Refseq entry", "The Reference Sequence (RefSeq) identifier for that entry, provided by the NCBI. As we do not aim to curate all variants of a gene only one selected RefSeq is displayed per gene report. RefSeq aims to provide a comprehensive, integrated, non-redundant set of sequences, including genomic DNA, transcript (RNA), and protein products. RefSeq identifiers are designed to provide a stable reference for gene identification and characterization, mutation analysis, expression studies, polymorphism discovery, and comparative analyses. In the HTML results page this ID links to the RefSeq page for that entry."));
             }
         }
         if (!empty($gene_family_tag)) {
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "gene-family-tag", utf8_encode(htmlspecialchars($gene_family_tag))) . parent::describeProperty($this->getVoc() . "gene-family-tag", "Gene Family Tag", "Tag used to designate a gene family or group the gene has been assigned to, according to either sequence similarity or information from publications, specialist advisors for that family or other databases. Families/groups may be either structural or functional, therefore a gene may belong to more than one family/group. These tags are used to generate gene family or grouping specific pages at genenames.org and do not necessarily reflect an official nomenclature. Each gene family has an associated gene family tag and gene family description. If a particular gene is a member of more than one gene family, the tags and the descriptions will be shown in the same order."));
         }
         if (!empty($gene_family_description)) {
             $gene_family_description = str_replace("\"", "", $gene_family_description);
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "gene-family-description", utf8_encode(htmlspecialchars($gene_family_description))) . parent::describeProperty($this->getVoc() . "gene-family-description", "gene family name", "Name given to a particular gene family. The gene family description has an associated gene family tag. Gene families are used to group genes according to either sequence similarity or information from publications, specialist advisors for that family or other databases. Families/groups may be either structural or functional, therefore a gene may belong to more than one family/group."));
         }
         if (!empty($record_type)) {
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "record-type", utf8_encode(htmlspecialchars($record_type))));
         }
         if (!empty($primary_ids)) {
             $primary_ids = explode(", ", $primary_ids);
             foreach ($primary_ids as $primary_id) {
                 parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "primary-id", utf8_encode(htmlspecialchars($primary_id))) . parent::describeProperty($this->getVoc() . "primary-id", "primary identifier"));
             }
         }
         if (!empty($secondary_ids)) {
             $secondary_ids = explode(", ", $secondary_ids);
             foreach ($secondary_ids as $secondary_id) {
                 parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "secondary-id", utf8_encode(htmlspecialchars($secondary_id))) . parent::describeProperty($this->getVoc() . "secondary-id", "secondary identifier"));
             }
         }
         if (!empty($ccd_ids)) {
             $ccd_ids = explode(", ", $ccd_ids);
             foreach ($ccd_ids as $ccd_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-ccds", "ccds:" . trim($ccd_id)) . parent::describeProperty($this->getVoc() . "x-ccds", "consensus CDS entry", "The Consensus CDS (CCDS) project is a collaborative effort to identify a core set of human and mouse protein coding regions that are consistently annotated and of high quality. The long term goal is to support convergence towards a standard set of gene annotations."));
             }
         }
         if (!empty($vega_ids)) {
             $vega_ids = explode(", ", $vega_ids);
             foreach ($vega_ids as $vega_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-vega", "vega:" . trim($vega_id)) . parent::describeProperty($this->getVoc() . "x-vega", "VEGA gene entry"));
             }
         }
         if (!empty($locus_specific_databases)) {
             parent::AddRDF(parent::triplifyString($id_res, $this->getVoc() . "locus-specific-xref", utf8_encode(htmlspecialchars($locus_specific_databases))) . parent::describeProperty($this->getVoc() . "locus-specific-xref", "locus specific xref", "This contains a list of links to databases or database entries pertinent to the gene"));
         }
         if (!empty($entrez_gene_id_mappeddatasuppliedbyNCBI)) {
             $entrez_gene_id_mappeddatasuppliedbyNCBI = explode(", ", $entrez_gene_id_mappeddatasuppliedbyNCBI);
             foreach ($entrez_gene_id_mappeddatasuppliedbyNCBI as $gene_id) {
                 if (strstr($gene_id, ":") !== FALSE) {
                     $a = explode(":", $gene_id);
                     $gene_id = $a[1];
                 }
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-ncbigene", "ncbigene:" . trim($gene_id)) . parent::describeProperty($this->getVoc() . "x-ncbigene", "NCBI Gene entry"));
             }
         }
         if (!empty($omim_id_mappeddatasuppliedbyNCBI)) {
             $omim_id_mappeddatasuppliedbyNCBI = explode(", ", $omim_id_mappeddatasuppliedbyNCBI);
             foreach ($omim_id_mappeddatasuppliedbyNCBI as $omim_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-omim", "omim:" . trim($omim_id)) . parent::describeProperty($this->getVoc() . "x-omim", "OMIM entry", "Identifier provided by Online Mendelian Inheritance in Man (OMIM) at the NCBI. This database is described as a catalog of human genes and genetic disorders containing textual information and links to MEDLINE and sequence records in the Entrez system, and links to additional related resources at NCBI and elsewhere. In the HTML results page this ID links to the OMIM page for that entry."));
             }
         }
         if (!empty($refseq_mappeddatasuppliedbyNCBI)) {
             $refseq_mappeddatasuppliedbyNCBI = explode(", ", $refseq_mappeddatasuppliedbyNCBI);
             foreach ($refseq_mappeddatasuppliedbyNCBI as $refseq_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-refseq", "refseq:" . trim($refseq_id)) . parent::describeProperty($this->getVoc() . "x-refseq", "NCBI Refseq entry", "The Reference Sequence (RefSeq) identifier for that entry, provided by the NCBI. As we do not aim to curate all variants of a gene only one selected RefSeq is displayed per gene report. RefSeq aims to provide a comprehensive, integrated, non-redundant set of sequences, including genomic DNA, transcript (RNA), and protein products. RefSeq identifiers are designed to provide a stable reference for gene identification and characterization, mutation analysis, expression studies, polymorphism discovery, and comparative analyses. In the HTML results page this ID links to the RefSeq page for that entry."));
             }
         }
         if (!empty($uniprot_id_mappeddatasuppliedbyUniProt)) {
             $uniprot_id_mappeddatasuppliedbyUniProt = explode(", ", $uniprot_id_mappeddatasuppliedbyUniProt);
             foreach ($uniprot_id_mappeddatasuppliedbyUniProt as $uniprot_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-uniprot", "uniprot:" . trim($uniprot_id)) . parent::describeProperty($this->getVoc() . "x-uniprot", "Uniprot entry", "The UniProt identifier, provided by the EBI. The UniProt Protein Knowledgebase is described as a curated protein sequence database that provides a high level of annotation, a minimal level of redundancy and high level of integration with other databases. In the HTML results page this ID links to the UniProt page for that entry."));
             }
         }
         if (!empty($ensembl_id_mappeddatasuppliedbyEnsembl)) {
             $ensembl_id_mappeddatasuppliedbyEnsembl = explode(", ", $ensembl_id_mappeddatasuppliedbyEnsembl);
             foreach ($ensembl_id_mappeddatasuppliedbyEnsembl as $ensembl_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-ensembl", "ensembl:" . trim($refseq_id)) . parent::describeProperty($this->getVoc() . "x-ensembl", "Ensembl entry", "The Ensembl ID is derived from the current build of the Ensembl database and provided by the Ensembl team."));
             }
         }
         if (!empty($ucsc_id_mappeddatasuppliedbyVega)) {
             $ucsc_id_mappeddatasuppliedbyVega = explode(", ", $ucsc_id_mappeddatasuppliedbyVega);
             foreach ($ucsc_id_mappeddatasuppliedbyVega as $vega_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-vega", "vega:" . trim($vega_id)) . parent::describeProperty($this->getVoc() . "x-vega", "Vega entry"));
             }
         }
         if (!empty($ucsc_id_mappeddatasuppliedbyUCSC)) {
             $ucsc_id_mappeddatasuppliedbyUCSC = explode(", ", $ucsc_id_mappeddatasuppliedbyUCSC);
             foreach ($ucsc_id_mappeddatasuppliedbyUCSC as $ucsc_id) {
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-ucsc", "ucsc:" . trim($ucsc_id)) . parent::describeProperty($this->getVoc() . "x-ucsc", "UCSC entry"));
             }
         }
         if (!empty($mouse_genome_database_id_mappeddatasuppliedbyMGI)) {
             $mouse_genome_database_id_mappeddatasuppliedbyMGI = explode(", ", $mouse_genome_database_id_mappeddatasuppliedbyMGI);
             foreach ($mouse_genome_database_id_mappeddatasuppliedbyMGI as $mgi_id) {
                 if (strpos($mgi_id, "MGI:") !== FALSE) {
                     $mgi_id = substr($mgi_id, 4);
                 }
                 parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-mgi", "mgi:" . trim($mgi_id)) . parent::describeProperty($this->getVoc() . "x-mgi", "MGI entry"));
             }
         }
         if (!empty($rat_genome_database_id_mappeddatasuppliedbyRGD)) {
             $rat_genome_database_id_mappeddatasuppliedbyRGD = explode(", ", trim($rat_genome_database_id_mappeddatasuppliedbyRGD));
             foreach ($rat_genome_database_id_mappeddatasuppliedbyRGD as $rgd_id) {
                 $rgd_id = trim($rgd_id);
                 if (!empty($rgd_id)) {
                     parent::AddRDF(parent::triplify($id_res, $this->getVoc() . "x-rgd", trim($rgd_id)) . parent::describeProperty($this->getVoc() . "x-rgd", "RGD entry"));
                 }
             }
         }
         //write RDF to file
         $this->WriteRDFBufferToWriteFile();
     }
     //while
 }
Exemplo n.º 20
0
 /**
  * add an RDF representation of the incoming param to the model.
  * @$qual_record_arr is an assoc array with the contents of one qualifier record
  */
 private function makeQualifierRecordRDF($qual_record_arr)
 {
     //get the UI of the qualifier record
     $qr_ui = $qual_record_arr["UI"][0];
     $qr_res = $this->getNamespace() . $qr_ui;
     $qr_label = $qual_record_arr['SH'][0];
     parent::AddRDF(parent::describeIndividual($qr_res, $qr_label, $this->getVoc() . "Qualifier-Descriptor", $qr_label) . parent::describeClass($this->getVoc() . "Qualifier-Descriptor", "MeSH Qualifier Descriptor"));
     //now get the descriptor_data_elements
     $qde = $this->getQualifierDataElements();
     //iterate over the properties
     foreach ($qual_record_arr as $k => $v) {
         if (array_key_exists($k, $qde)) {
             if ($k == "AN") {
                 foreach ($v as $kv => $vv) {
                     //explode by semicolon
                     $vvrar = explode(";", $vv);
                     foreach ($vvrar as $anAn) {
                         parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde["AN"], $anAn) . parent::describeProperty($this->getVoc() . $qde["AN"], "Relationship between a qualifier record and its annotation"));
                     }
                     //foreach
                 }
                 //foreach
             }
             //if
             if ($k == "DA") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['DA'], $this->formatDate($vv), "xsd:date") . parent::describeProperty($this->getVoc() . $qde['DA'], "Relationship between a qualifier record and its date of entry"));
                 }
             }
             //if
             if ($k == "DQ") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['DQ'], $this->formatDate($vv), "xsd:date") . parent::describeProperty($this->getVoc() . $qde['DQ'], "Relationship between a qualifier record and its date qualifier established"));
                 }
             }
             //if
             if ($k == "GM") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['GM'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['GM'], "Relationship between a qualifier record and its grateful med note"));
                 }
             }
             if ($k == "HN") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['HN'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['HN'], "Relationship between a qualifier record and its history note"));
                 }
             }
             if ($k == "HN") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['HN'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['HN'], "Relationship between a qualifier record and its history note"));
                 }
             }
             if ($k == "MED") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['MED'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['MED'], "Relationship between a qualifier record and its backfile postings"));
                 }
             }
             if ($k == "M94") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['M94'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['M94'], "Relationship between a qualifier record and its backfile postings"));
                 }
             }
             if ($k == "M90") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['M90'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['M90'], "Relationship between a qualifier record and its backfile postings"));
                 }
             }
             if ($k == "M85") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['M85'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['M85'], "Relationship between a qualifier record and its backfile postings"));
                 }
             }
             if ($k == "M80") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['M80'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['M80'], "Relationship between a qualifier record and its backfile postings"));
                 }
             }
             if ($k == "M75") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['M75'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['M75'], "Relationship between a qualifier record and its backfile postings"));
                 }
             }
             if ($k == "M66") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['M66'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['M66'], "Relationship between a qualifier record and its backfile postings"));
                 }
             }
             if ($k == "MR") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['MR'], $this->formatDate($vv), "xsd:date") . parent::describeProperty($this->getVoc() . $qde['MR'], "Relationship between a qualifier record and its major revision date"));
                 }
             }
             //if
             if ($k == "MS") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['MS'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['MS'], "Relationship between a qualifier record and its MeSH scope note"));
                 }
             }
             if ($k == "OL") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['OL'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['OL'], "Relationship between a qualifier record and its online note"));
                 }
             }
             if ($k == "QA") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['QA'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['QA'], "Relationship between a qualifier record and its toplical qualifier abbreviation"));
                 }
             }
             if ($k == "QE") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['QE'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['QE'], "Relationship between a qualifier record and its qualifier entry version"));
                 }
             }
             if ($k == "QS") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['QS'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['QS'], "Relationship between a qualifier record and its qualifier sort version"));
                 }
             }
             if ($k == "QT") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['QT'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['QT'], "Relationship between a qualifier record and its qualifier type"));
                 }
             }
             if ($k == "QX") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['QX'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['QX'], "Relationship between a qualifier record and its qualifier cross reference"));
                 }
             }
             if ($k == "RECTYPE") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['RECTYPE'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['RECTYPE'], "Relationship between a qualifier record and its record type"));
                 }
             }
             if ($k == "SH") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['SH'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['SH'], "Relationship between a qualifier record and its subheading"));
                 }
             }
             if ($k == "TN") {
                 foreach ($v as $kv => $vv) {
                     parent::AddRDF(parent::triplifyString($qr_res, $this->getVoc() . $qde['TN'], utf8_encode(htmlspecialchars($vv))) . parent::describeProperty($this->getVoc() . $qde['TN'], "Relationship between a qualifier record and its tree node allowed"));
                 }
             }
         } else {
             trigger_error("Please add key to qualifier record map: " . $k . PHP_EOL, E_USER_ERROR);
         }
         //else
         $this->WriteRDFBufferToWriteFile();
     }
     //foreach
     $this->WriteRDFBufferToWriteFile();
 }
Exemplo n.º 21
0
 function product($fpin)
 {
     $z = 0;
     $list = '';
     fgets($fpin);
     // header
     while ($l = fgets($fpin, 100000)) {
         $a = explode("\t", $l);
         if (count($a) != 18) {
             trigger_error("Expected 18 coloumns, instead found" . count($a));
             continue;
         }
         $product_id = parent::getNamespace() . $a[0];
         $product_label = $a[3];
         $product_type_label = ucfirst(strtolower($a[2]));
         $product_type = parent::getVoc() . str_replace(" ", "-", $product_label);
         parent::addRDF(parent::describeIndividual($product_id, $a[3], parent::getVoc() . "Product") . parent::describeClass(parent::getVoc() . "Product", "NDC Product") . parent::triplify($product_id, parent::getVoc() . "product-type", $product_type) . parent::describeIndividual($product_type, $product_type_label, parent::getVoc() . "Product-Type") . parent::describeClass(parent::getVoc() . "Product-Type", "Product Type") . parent::triplifyString($product_id, parent::getVoc() . "product-id", $a[1]) . parent::triplifyString($product_id, parent::getVoc() . "proprietary-name", $a[3]) . parent::triplifyString($product_id, parent::getVoc() . "trade-name-suffix", $a[4]));
         if ($a[5]) {
             $b = explode(";", $a[5]);
             foreach ($b as $c) {
                 parent::addRDF(parent::triplifyString($product_id, parent::getVoc() . "non-proprietary-name", trim($c)));
             }
         }
         if ($a[6]) {
             $b = explode(",", $a[6]);
             foreach ($b as $c) {
                 $dosageform = strtolower($c);
                 $dosageform_id = parent::getVoc() . str_replace(" ", "-", ucfirst(strtolower($c)));
                 parent::addRDF(parent::describeIndividual($dosageform_id, $dosageform, parent::getVoc() . "Dosage-Form") . parent::describeClass(parent::getVoc() . "Dosage-Form", "NDC Dosage Form") . parent::triplify($product_id, parent::getVoc() . "dosage-form", $dosageform_id));
             }
         }
         if ($a[7]) {
             //  MV
             $b = explode("; ", $a[7]);
             foreach ($b as $c) {
                 $route = strtolower(trim($c));
                 $route_id = parent::getVoc() . str_replace(" ", "-", ucfirst(strtolower($c)));
                 parent::addRDF(parent::describeIndividual($route_id, $route, parent::getVoc() . "Route") . parent::describeClass(parent::getVoc() . "Route", "NDC Drug Route") . parent::triplify($product_id, parent::getVoc() . "route", $route_id));
             }
         }
         if ($a[8]) {
             $date = substr(0, 4, $a[8]) . "-" . substr(4, 2, $a[8]) . "-" . substr(6, 2, $a[8]);
             parent::addRDF(parent::triplifyString($product_id, parent::getVoc() . "start-marketing-date", $date));
         }
         if ($a[9]) {
             $date = substr(0, 4, $a[9]) . "-" . substr(4, 2, $a[9]) . "-" . substr(6, 2, $a[9]);
             parent::addRDF(parent::triplifyString($product_id, parent::getVoc() . "end-marketing-date", $date));
         }
         if ($a[10]) {
             parent::addRDF(parent::triplifyString($product_id, parent::getVoc() . "marketing-category", $a[10]));
         }
         if ($a[11]) {
             parent::addRDF(parent::triplifyString($product_id, parent::getVoc() . "application-number", $a[11]));
         }
         // create a labeller node
         if ($a[12]) {
             $labeller_id = parent::getRes() . md5($a[12]);
             $label = addslashes($a[12]);
             parent::addRDF(parent::describeIndividual($labeller_id, $label, parent::getVoc() . "Labeller") . parent::describeClass(parent::getVoc() . "Labeller", "NDC Labeller") . parent::triplify($product_id, parent::getVoc() . "labeller", $labeller_id));
         }
         // the next three are together
         if ($a[13]) {
             // MV
             $substances = explode(";", $a[13]);
             $strengths = explode(";", $a[14]);
             $units = explode(";", $a[15]);
             $l = '';
             foreach ($substances as $i => $substance) {
                 // list the active ingredient
                 $ingredient_label = strtolower($substance);
                 $strength = '';
                 if (isset($strengths[$i])) {
                     $strength = $strengths[$i];
                 }
                 $unit = $units[$i];
                 $ingredient_id = parent::getRes() . md5($ingredient_label);
                 parent::addRDF(parent::describeIndividual($ingredient_id, $ingredient_label, parent::getVoc() . "Ingredient") . parent::describeClass(parent::getVoc() . "Ingredient", "NDC Ingredient") . parent::triplify($product_id, parent::getVoc() . "ingredient", $ingredient_id));
                 // describe the substance composition
                 $substance_label = "{$strength} {$unit} {$ingredient_label}";
                 $substance_id = parent::getRes() . md5($substance_label);
                 parent::addRDF(parent::describeIndividual($substance_id, $substance_label, parent::getVoc() . "Substance") . parent::triplifyString($substance_id, parent::getVoc() . "amount", $strength) . parent::describeClass(parent::getVoc() . "Substance", "NDC Substance"));
                 $unit_id = parent::getVoc() . md5($unit);
                 parent::addRDF(parent::describeIndividual($unit_id, $unit, parent::getVoc() . "Unit") . parent::describeClass(parent::getVoc() . "Unit", "NDC Unit") . parent::triplify($substance_id, parent::getVoc() . "amount_unit", $unit_id) . parent::triplify($product_id, parent::getVoc() . "has-part", $substance_id));
             }
         }
         if ($a[16]) {
             // MV
             $b = explode(",", $a[16]);
             foreach ($b as $c) {
                 $cat_id = parent::getVoc() . md5($c);
                 parent::addRDF(parent::describeIndividual($cat_id, $c, parent::getVoc() . "Pharmacological-Class") . parent::describeClass(parent::getVoc() . "Pharmacological-Class", "NDC Pharmacological Class") . parent::triplify($product_id, parent::getVoc() . "pharmacological-class", $cat_id));
             }
         }
         parent::WriteRDFBufferToWriteFile();
     }
 }
Exemplo n.º 22
0
 function Run()
 {
     // directory shortcuts
     $ldir = parent::getParameterValue('indir');
     $odir = parent::getParameterValue('outdir');
     // get the work specified
     $list = trim(parent::getParameterValue('files'));
     if ($list == 'all') {
         // call the getAllModelsId webservice
         $file = $ldir . "all_models.json";
         if (!file_exists($file)) {
             try {
                 $x = @new SoapClient("http://www.ebi.ac.uk/biomodels-main/services/BioModelsWebServices?wsdl");
             } catch (Exception $e) {
                 echo $e->getMessage();
             }
             $entries = $x->getAllModelsId();
             file_put_contents($file, json_encode($entries));
         } else {
             $entries = json_decode(file_get_contents($file));
         }
     } elseif ($list == 'curated') {
         // call the getAllCuratedModelsId webservice
         $file = $ldir . "curated_models.json";
         if (!file_exists($file)) {
             try {
                 $x = @new SoapClient("http://www.ebi.ac.uk/biomodels-main/services/BioModelsWebServices?wsdl");
             } catch (Exception $e) {
                 echo $e->getMessage();
             }
             $entries = $x->getAllCuratedModelsId();
             file_put_contents($file, json_encode($entries));
         } else {
             $entries = json_decode(file_get_contents($file));
         }
     } else {
         // check if a hyphenated list was provided
         if (($pos = strpos($list, "-")) !== FALSE) {
             $start_range = substr($list, 0, $pos);
             $end_range = substr($list, $pos + 1);
             for ($i = $start_range; $i <= $end_range; $i++) {
                 $entries[] = "BIOMD" . str_pad($i, 10, "0", STR_PAD_LEFT);
             }
         } else {
             // for comma separated list
             $b = explode(",", $this->GetParameterValue('files'));
             foreach ($b as $e) {
                 $entries[] = "BIOMD" . str_pad($e, 10, "0", STR_PAD_LEFT);
             }
         }
     }
     $graph_uri = parent::getGraphURI();
     if (parent::getParameterValue('dataset_graph') == true) {
         parent::setGraphURI(parent::getDatasetURI());
     }
     // set the write file
     $suffix = parent::getParameterValue('output_format');
     $outfile = 'biomodels' . '.' . $suffix;
     $gz = false;
     if (strstr(parent::getParameterValue('output_format'), "gz")) {
         $gz = true;
     }
     $dataset_description = '';
     parent::setWriteFile($odir . $outfile, $gz);
     // iterate over the entries
     $i = 0;
     $total = count($entries);
     foreach ($entries as $id) {
         echo "processing " . ++$i . " of {$total} - biomodel# " . $id;
         $download_file = $ldir . $id . ".owl.gz";
         $url = parent::getParameterValue('download_url') . "publ/{$id}/{$id}-biopax3.owl";
         // download if the file doesn't exist or we are told to
         if (!file_exists($download_file) || $this->GetParameterValue('download') == 'true') {
             // download
             echo " - downloading";
             $ret = utils::downloadsingle($url, 'compress.zlib://' . $download_file, true);
             if ($ret === false) {
                 echo "\nTrying non-curated model";
                 $url = parent::getParametervalue('download_url') . "uncura_publ/{$id}/{$id}-biopax3.owl";
                 $ret = utils::downloadsingle($url, 'compress.zlib://' . $download_file, true);
                 if ($ret === false) {
                     continue;
                 }
             }
             echo " - downloaded";
         }
         // load entry, parse and write to file
         echo " - parsing... ";
         // $this->SetReadFile($download_file,true);
         $buf = file_get_contents("compress.zlib://" . $download_file);
         $converter = new BioPAX2Bio2RDF($this);
         $converter->SetBuffer($buf)->SetBioPAXVersion(3)->SetBaseNamespace("http://identifiers.org/biomodels.db/{$id}/")->SetBio2RDFNamespace("http://bio2rdf.org/biomodels:" . $id . "_")->SetDatasetURI($this->GetDatasetURI());
         $rdf = $converter->Parse();
         parent::addRDF($rdf);
         parent::writeRDFBufferToWriteFile();
         //generate dataset description
         $source_file = (new DataResource($this))->setURI($url)->setTitle("EBI BioModels Database - BioModel # {$id}")->setRetrievedDate(date("Y-m-d\\TG:i:s\\Z", filemtime($download_file)))->setFormat("rdf/xml")->setPublisher("http://www.ebi.ac.uk/")->setHomepage("http://www.ebi.ac.uk/biomodels-main/")->setRights("use-share-modify")->setLicense("http://www.ebi.ac.uk/biomodels-main/termsofuse")->setDataset("http://identifiers.org/biomodels.db/");
         $dataset_description .= $source_file->toRDF();
         echo "done!" . PHP_EOL;
     }
     //foreach
     parent::getWriteFile()->close();
     $prefix = parent::getPrefix();
     $bVersion = parent::getParameterValue('bio2rdf_release');
     $date = date("Y-m-d\\TG:i:s\\Z");
     $output_file = (new DataResource($this))->setURI("http://download.bio2rdf.org/release/{$bVersion}/{$prefix}/")->setTitle("Bio2RDF v{$bVersion} RDF version of {$prefix} (generated at {$date})")->setSource($source_file->getURI())->setCreator("https://github.com/bio2rdf/bio2rdf-scripts/blob/master/biomodels/biomodels.php")->setCreateDate($date)->setHomepage("http://download.bio2rdf.org/release/{$bVersion}/{$prefix}/{$prefix}.html")->setPublisher("http://bio2rdf.org")->setRights("use-share-modify")->setRights("by-attribution")->setRights("restricted-by-source-license")->setLicense("http://creativecommons.org/licenses/by/3.0/")->setDataset(parent::getDatasetURI());
     if ($gz) {
         $output_file->setFormat("application/gzip");
     }
     if (strstr(parent::getParameterValue('output_format'), "nt")) {
         $output_file->setFormat("application/n-triples");
     } else {
         $output_file->setFormat("application/n-quads");
     }
     $dataset_description .= $output_file->toRDF();
     //write dataset description to file
     parent::setGraphURI($graph_uri);
     parent::setWriteFile($odir . parent::getBio2RDFReleaseFile());
     parent::getWriteFile()->write($dataset_description);
     parent::getWriteFile()->close();
     echo "done!" . PHP_EOL;
 }
Exemplo n.º 23
0
 function process()
 {
     $refseq_record_str = "";
     while ($aLine = $this->getReadFile()->Read(40960)) {
         preg_match("/^\\/\\/\$/", $aLine, $matches);
         if (!count($matches)) {
             preg_match("/^\n\$/", $aLine, $matches);
             if (count($matches) == 0) {
                 $refseq_record_str .= $aLine . PHP_EOL;
             }
             continue;
         } else {
             //now remove the header if it is there
             $refseq_record_str = $this->removeHeader($refseq_record_str);
             $sectionsRaw = $this->parseGenbankRaw($refseq_record_str);
             /**
              * SECTIONS being parsed:
              * locus, definition, accession, version, keywords, source
              * features
              **/
             //get the locus section
             $locus = $this->retrieveSections("LOCUS", $sectionsRaw);
             $parsed_locus_arr = $this->parseLocus($locus);
             //get the definition
             $definition = $this->retrieveSections("DEFINITION", $sectionsRaw);
             $parsed_definition_arr = $this->parseDefinition($definition);
             //get the accession
             $accessions = $this->retrieveSections("ACCESSION", $sectionsRaw);
             $parsed_accession_arr = $this->parseAccession($accessions);
             //get the version
             $versions = $this->retrieveSections("VERSION", $sectionsRaw);
             $parsed_version_arr = $this->parseVersion($versions);
             //get the keywords
             $keywords = $this->retrieveSections("KEYWORDS", $sectionsRaw);
             $parsed_keyword_arr = $this->parseKeywords($keywords);
             //get the reference section
             $references = $this->retrieveSections("REFERENCE", $sectionsRaw);
             $parsed_refs_arr = $this->parseReferences($references);
             //get the source section
             $source = $this->retrieveSections("SOURCE", $sectionsRaw);
             $parsed_source_arr = $this->parseSource($source);
             //get the features
             $features = $this->retrieveSections("FEATURES", $sectionsRaw);
             $parsed_features_arr = $this->parseFeatures($features);
             //lets make some rdf
             $refseq_res = $this->getNamespace() . $parsed_version_arr['versioned_accession'];
             $refseq_label = utf8_encode(htmlspecialchars($parsed_definition_arr[0]));
             parent::AddRDF(parent::describeIndividual($refseq_res, $refseq_label, $this->getVoc() . 'refseq-record') . parent::triplifyString($refseq_res, $this->getVoc() . 'sequence-length', $parsed_locus_arr[0]['sequence_length']) . parent::triplifyString($refseq_res, $this->getVoc() . 'chromosome-shape', $parsed_locus_arr[0]['chromosome_shape']) . parent::triplifyString($refseq_res, $this->getVoc() . 'date-of-entry', $parsed_locus_arr[0]['date']) . parent::triplifyString($refseq_res, $this->getVoc() . 'source', utf8_encode($parsed_source_arr[0])) . parent::triplify($refseq_res, $this->getVoc() . 'fasta-seq', 'https://www.ncbi.nlm.nih.gov/sviewer/viewer.cgi?sendto=on&db=nucest&dopt=fasta&val=' . $parsed_version_arr['gi']) . parent::triplify('https://www.ncbi.nlm.nih.gov/sviewer/viewer.cgi?sendto=on&db=nucest&dopt=fasta&val=' . $parsed_version_arr['gi'], "rdf:type", $this->getVoc() . 'fasta-sequence'));
             //add the features to the rdf
             foreach ($parsed_features_arr as $aFeature) {
                 $type = $aFeature['type'];
                 $feat_desc = $this->getFeatures($type);
                 $label = $type;
                 $def = '';
                 if (isset($feat_desc['definition'])) {
                     $def = preg_replace('/\\s\\s*/', ' ', $feat_desc['definition']);
                 }
                 $comment = null;
                 //					$value = $aFeature['value'];
                 $value = str_replace("UniProtKB/Swiss-Prot", "UniProt", $aFeature['value']);
                 // imperfect solution.
                 $value_arr = explode("/", $value);
                 $location = preg_replace('/\\n/', '', $value_arr[0]);
                 $class_id = parent::getVoc() . md5($type);
                 $feat_res = parent::getRes() . md5($type . $location . $refseq_res);
                 $feat_label = utf8_encode($type . " " . $location . " for " . $refseq_res);
                 if (isset($feat_desc['comment'])) {
                     $comment = $feat_desc['comment'];
                     $comment = preg_replace('/\\s\\s*/', ' ', $comment);
                     $label .= " " . $comment;
                 }
                 parent::AddRDF(parent::describeClass($class_id, $label, parent::getVoc() . "Feature", $label, $def) . parent::describeIndividual($feat_res, $feat_label, $class_id) . parent::triplify($refseq_res, $this->getVoc() . "has-feature", $feat_res));
                 foreach ($value_arr as $aL) {
                     //check if aL has an equals in it
                     $p = "/(\\S+)\\=(.*)/";
                     preg_match($p, $aL, $m);
                     if (count($m)) {
                         if ($m[1] == "db_xref") {
                             parent::AddRDF(parent::triplify($feat_res, "rdfs:seeAlso", str_replace("\"", "", $m[2])));
                         } else {
                             parent::AddRDF(parent::triplifyString($feat_res, $this->getVoc() . $m[1], utf8_encode(str_replace("\"", "", $m[2]))));
                         }
                     }
                 }
             }
             //add the accession
             foreach ($parsed_accession_arr[0] as $acc) {
                 parent::AddRDF(parent::triplifyString($refseq_res, $this->getVoc() . "accession", $acc));
             }
             //versioned accession
             if (isset($parsed_version_arr['versioned_accession'])) {
                 parent::AddRDF(parent::triplifyString($refseq_res, $this->getVoc() . "versioned-accession", $parsed_version_arr['versioned_accession']));
             }
             //keywords
             foreach ($parsed_keyword_arr as $akw) {
                 parent::AddRDF(parent::triplifyString($refseq_res, $this->getVoc() . "keyword", $akw));
             }
             //references
             foreach ($parsed_refs_arr as $aRef) {
                 $r = rand();
                 $ref_res = $this->getRes() . md5($r);
                 $ref_label = "reference for " . $refseq_res;
                 if (isset($aRef['TITLE'])) {
                     parent::AddRDF(parent::describeIndividual($ref_res, $ref_label, $this->getVoc() . "reference") . parent::triplifyString($ref_res, $this->getVoc() . "title", $aRef['TITLE']));
                 }
                 if (isset($aRef['PUBMED'])) {
                     parent::AddRDF(parent::triplify($ref_res, $this->getVoc() . "x-pubmed", 'pubmed:' . $aRef['PUBMED']));
                 }
                 if (isset($aRef['AUTHORS'])) {
                     parent::AddRDF(parent::triplifyString($ref_res, $this->getVoc() . "authors", $aRef['AUTHORS']));
                 }
                 if (isset($aRef['COORDINATES'])) {
                     parent::AddRDF(parent::triplify($refseq_res, $this->getVoc() . "reference", $ref_res) . parent::triplifyString($ref_res, $this->getVoc() . "coordinates", $aRef['COORDINATES']) . parent::triplifyString($ref_res, $this->getVoc() . "citation", $aRef['JOURNAL']));
                 } else {
                     parent::AddRDF(parent::triplify($refseq_res, $this->getVoc() . "reference", $ref_res) . parent::triplifyString($ref_res, $this->getVoc() . "citation", $aRef['JOURNAL']));
                 }
             }
             $refseq_record_str = "";
             $this->WriteRDFBufferToWriteFile();
             continue;
         }
     }
     //while
 }
Exemplo n.º 24
0
 function addDate($id, $field, $dateobj)
 {
     if ($dateobj == null) {
         return FALSE;
     }
     $year = $dateobj->Year;
     $month = $dateobj->Month;
     $day = $dateobj->Day;
     parent::addRDF(parent::triplifyString($id, parent::getVoc() . $field, "{$year}-{$month}-{$day}", "xsd:date"));
 }
Exemplo n.º 25
0
 /**
  *	Convert pubchem substance XML record to RDF
  **/
 function parse_substance_record(&$xml)
 {
     $root = $xml->GetXMLRoot();
     // pubchem identifier and version
     $sid = array_shift($root->xpath('//PC-Substance_sid/PC-ID/PC-ID_id'));
     $sid_version = array_shift($root->xpath('//PC-Substance_sid/PC-ID/PC-ID_version'));
     $psid = $this->getPcsNs() . $sid;
     parent::addRDF(parent::describeIndividual($psid, null, $this->getPcsVoc() . "Substance"));
     parent::addRDF(parent::triplifyString($psid, $this->getPcsVoc() . "version", parent::safeLiteral($sid_version)));
     // reference to pubchem compounds
     $pc_compounds = $root->xpath('//PC-Substance_compound/PC-Compounds/PC-Compound');
     foreach ($pc_compounds as $compound) {
         $cid = array_shift($compound->xpath('./PC-Compound_id/PC-CompoundType/PC-CompoundType_id/PC-CompoundType_id_cid'));
         $cid_type = array_shift($compound->xpath('./PC-Compound_id/PC-CompoundType/PC-CompoundType_type'));
         if ($cid != "") {
             $pcid = $this->getPccNs() . $cid;
             parent::addRDF(parent::triplify($psid, $this->getPcsVoc() . "compound", $pcid));
         }
     }
     // database cross references (xref)
     // source identifier
     $source_id = array_shift($root->xpath('//PC-Substance_source/PC-Source/PC-Source_db/PC-DBTracking/PC-DBTracking_source-id/Object-id/Object-id_str'));
     parent::addRDF(parent::triplifyString($psid, $this->getPcsVoc() . "source-identifier", parent::safeLiteral($source_id)));
     // synonyms
     $synonyms = $root->xpath('//PC-Substance_synonyms/PC-Substance_synonyms_E');
     foreach ($synonyms as $synonym) {
         parent::addRDF(parent::triplifyString($psid, $this->getPcsVoc() . "synonym", parent::safeLiteral($synonym)));
     }
     //comment
     $comments = $root->xpath('//PC-Substance_comment/PC-Substance_comment_E');
     foreach ($comments as $comment) {
         if ($comment !== "") {
             parent::addRDF(parent::triplifyString($psid, "rdfs:comment", parent::safeLiteral($comment)));
         }
     }
 }
Exemplo n.º 26
0
 private function process()
 {
     //read the file into a string
     $xml_str = '';
     while ($l = $this->getReadFile()->Read(4096)) {
         $xml_str .= $l;
     }
     $xml = new SimpleXMLElement($xml_str);
     foreach ($xml->{'sts'} as $sts) {
         $uid = (string) $sts->uid;
         $uid_res = $this->getNamespace() . $uid;
         $name = (string) $sts->name;
         $uid_label = $name;
         parent::AddRDF(parent::describeIndividual($uid_res, $uid_label, $this->getVoc() . "sequence_tagged_site"));
         //split by semicolon
         $genbank_accession_arr = explode(";", (string) $sts->gbacc);
         foreach ($genbank_accession_arr as $gb) {
             parent::AddRDF(parent::triplify($uid_res, $this->getVoc() . 'x-genbank', 'genbank:' . $gb));
         }
         //split by semicolon
         $gi_arr = explode(';', (string) $sts->gi);
         foreach ($gi_arr as $gi) {
             parent::AddRDF(parent::triplify($uid_res, $this->getVoc() . 'x-gi', 'gi:' . $gi));
         }
         $links = (string) $sts->links;
         if (isset($links)) {
             parent::AddRDF(parent::triplifyString($uid_res, $this->getVoc() . 'links', utf8_encode($links)));
         }
         $forward_primer = (string) $sts->pcrfor;
         if (isset($forward_primer)) {
             parent::AddRDF(parent::triplifyString($uid_res, $this->getVoc() . 'forward-primer', $forward_primer));
         }
         $reverse_primer = (string) $sts->pcrrev;
         if (isset($reverse_primer)) {
             parent::AddRDF(parent::triplifyString($uid_res, $this->getVoc() . 'reverse-primer', $reverse_primer));
         }
         $epcr_summary = (string) $sts->EPCR_Summary;
         if (isset($epcr_summary)) {
             parent::AddRDF(parent::triplifyString($uid_res, $this->getVoc() . 'epcr-summary', $epcr_summary));
         }
         $dbsts = (string) $sts->dbsts;
         if (isset($dbsts)) {
             parent::AddRDF(parent::triplifyString($uid_res, $this->getVoc() . 'dbsts', $dbsts));
         }
         foreach ($sts->{'Map_Gene_Summary_List'} as $gsl) {
             foreach ($gsl->{'Map_Gene_Summary'} as $mgs) {
                 $r = rand();
                 $org = (string) $mgs->Org;
                 $taxid = (string) $mgs->taxid;
                 $chromosome = (string) $mgs->Chr;
                 $locus = (string) $mgs->Locus;
                 $polymorphic = (string) $mgs->Polymorphic;
                 $lbl = "map gene summary for :" . $org . " " . $taxid;
                 $u_res = $this->getRes() . md5($r . $org);
                 parent::AddRDF(parent::describeIndividual($u_res, $lbl, $this->getVoc() . "map-gene-summary") . parent::triplify($uid_res, $this->getVoc() . "has-map-gene-summary", $u_res));
                 if (isset($polymorphic)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "polymorphic", $polymorphic));
                 }
                 if (isset($locus)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "locus", $locus));
                 }
                 if (isset($chromosome)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "chromosome", $chromosome));
                 }
                 if (isset($taxid)) {
                     parent::AddRDF(parent::triplify($u_res, $this->getVoc() . "x-taxonomy", "taxon:" . $taxid));
                 }
                 if (isset($org)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "org-name", $org));
                 }
             }
         }
         foreach ($sts->{'org'} as $anOrg) {
             $r = rand();
             $taxname = (string) $anOrg->taxname;
             $taxid = (string) $anOrg->taxid;
             $name = (string) $anOrg->name;
             $keyword = (string) $anOrg->keyword;
             $alias = (string) $anOrg->alias;
             $polymorphic = (string) $anOrg->polymorphic;
             $dseg = (string) $anOrg->dseg;
             $gdb = (string) $anOrg->gdb;
             $rgd = (string) $anOrg->rgd;
             $mgd = (string) $anOrg->mgd;
             $zfin = (string) $anOrg->zfin;
             $pcrsize = (string) $anOrg->pcrsize;
             $dbsnp = (string) $anOrg->dbsnp;
             $warn = (string) $anOrg->warn;
             $wloc = (string) $anOrg->wloc;
             $wmap = (string) $anOrg->wmap;
             $wctg = (string) $anOrg->wctg;
             $wdrift = (string) $anOrg->wdrift;
             $mapview = (string) $anOrg->mapview;
             $u_res = $this->getRes() . md5($r . $taxname . $taxid);
             $u_lbl = "org entry for " . $taxname . " " . $taxid;
             parent::AddRDF(parent::describeIndividual($u_res, $u_lbl, $this->getVoc() . "organism") . parent::triplify($uid_res, $this->getVoc() . "has-organism", $u_res));
             if (isset($mapview) && strlen($mapview)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "mapview", $mapview));
             }
             if (isset($wdrift) && strlen($wdrift)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "wdrift", $wdrift));
             }
             if (isset($wctg) && strlen($wctg)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "wctg", $wctg));
             }
             if (isset($wmap) && strlen($wmap)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "wmap", $wmap));
             }
             if (isset($wloc) && strlen($wloc)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "wloc", $wloc));
             }
             if (isset($warn) && strlen($warn)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "warn", $warn));
             }
             if (isset($taxname) && strlen($taxname)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "taxname", $taxname));
             }
             if (isset($name)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "name", $name));
             }
             if (isset($keyword) && strlen($keyword)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "keyword", $keyword));
             }
             if (isset($alias) && strlen($alias)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "alias", $alias));
             }
             if (isset($polymorphic) && strlen($polymorphic)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "polymorphic", $polymorphic));
             }
             if (isset($dseg) && strlen($dseg)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "dseg", $dseg));
             }
             if (isset($gdb) && strlen($gdb)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "gdb", $gdb));
             }
             if (isset($rgd) && strlen($rgd)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "rgd", $rgd));
             }
             if (isset($mgd) && strlen($mgd)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "mgd", $mgd));
             }
             if (isset($zfin) && strlen($zfin)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "zfin", $zfin));
             }
             if (isset($pcrsize) && strlen($pcrsize)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "pcrsize", $pcrsize));
             }
             if (isset($dbsnp) && strlen($dbsnp)) {
                 parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . "dbsnp", $dbsnp));
             }
             foreach ($anOrg->{'rhdb'} as $rh) {
                 $id = (string) $rh->id;
                 $panel = (string) $rh->panel;
                 $r = rand();
                 $u_res = $this->getRes() . md5($r . $id . $panel);
                 $u_label = "rhdb for " . $id . " " . $panel;
                 parent::AddRDF(parent::describeIndividual($u_res, $u_label, $this->getVoc() . "rhdb") . parent::triplify($uid_res, $this->getVoc() . 'has-rhdb', $u_res) . parent::triplifyString($u_res, $this->getVoc() . 'id', $id) . parent::triplifyString($u_res, $this->getVoc() . 'panel', $panel));
             }
             foreach ($anOrg->{'unigene'} as $u) {
                 $ugid = (string) $u->unigene;
                 $ugname = (string) $u->ugname;
                 $r = rand();
                 $u_res = $this->getRes() . md5($r . $ugid . $ugname);
                 $u_label = "unigene for " . $ugid . " " . $ugname;
                 if (strlen($ugid) > 0 && strlen($ugname) > 0) {
                     parent::AddRDF(parent::describeIndividual($u_res, $u_label, $this->getVoc() . "unigene") . parent::triplify($uid_res, $this->getVoc() . 'has-unigene', $u_res) . parent::triplify($u_res, $this->getVoc() . 'x-unigene', $ugid) . parent::triplifyString($u_res, $this->getVoc() . 'ugname', $ugname));
                 }
             }
             foreach ($anOrg->{'locus'} as $aLocus) {
                 $lid = (string) $aLocus->lid;
                 $lsymbol = (string) $aLocus->lsymbol;
                 $lname = (string) $aLocus->lname;
                 $lcyto = (string) $aLocus->lcyto;
                 $ltype = (string) $aLocus->ltype;
                 $r = rand();
                 $u_res = $this->getRes() . md5($r . $lid);
                 $u_label = "locus for " . $lid . " " . $lname . " " . $lsymbol;
                 parent::AddRDF(parent::describeIndividual($u_res, $u_label, $this->getVoc() . "locus") . parent::triplify($uid_res, $this->getVoc() . 'has-locus', $u_res));
                 if (isset($lcyto) && strlen($lcyto)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'cyto', $lcyto));
                 }
                 if (isset($ltype) && strlen($ltype)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'ltype', $ltype));
                 }
                 if (isset($lname) && strlen($lname)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'name', $lname));
                 }
             }
             foreach ($anOrg->{'mappos'} as $aMapPos) {
                 $map = (string) $aMapPos->map;
                 $marker = (string) $aMapPos->marker;
                 $chr = (string) $aMapPos->chr;
                 $chrpos = (string) $aMapPos->chrpos;
                 $ctg = (string) $aMapPos->ctg;
                 $ctgpos = (string) $aMapPos->ctgpos;
                 $coord = (string) $aMapPos->coord;
                 $lod = (string) $aMapPos->lod;
                 $bin = (string) $aMapPos->bin;
                 $binpos = (string) $aMapPos->binpos;
                 $het = (string) $aMapPos->het;
                 $lab = (string) $aMapPos->lab;
                 $unit = (string) $aMapPos->unit;
                 $r = rand();
                 $u_res = $this->getRes() . md5($r . $map);
                 $u_label = "locus for " . $map . " " . $marker . " " . $chr;
                 parent::AddRDF(parent::describeIndividual($u_res, $u_label, $this->getVoc() . "mappos") . parent::triplify($uid_res, $this->getVoc() . 'has-mappos', $u_res));
                 if (isset($unit) && strlen($unit)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'unit', $unit));
                 }
                 if (isset($lab) && strlen($lab)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'lab', $lab));
                 }
                 if (isset($het) && strlen($het)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'het', $het));
                 }
                 if (isset($binpos) && strlen($binpos)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'binpos', $binpos));
                 }
                 if (isset($bin) && strlen($bin)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'bin', $bin));
                 }
                 if (isset($lod) && strlen($lod)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'lod', $lod));
                 }
                 if (isset($coord) && strlen($coord)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'coord', $coord));
                 }
                 if (isset($ctgpos) && strlen($ctgpos)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'ctgpos', $ctgpos));
                 }
                 if (isset($ctg) && strlen($ctg)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'ctg', $ctg));
                 }
                 if (isset($chrpos) && strlen($chrpos)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'chrpos', $chrpos));
                 }
                 if (isset($chr) && strlen($chr)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'chr', $chr));
                 }
                 if (isset($marker) && strlen($marker)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'marker', $marker));
                 }
             }
             foreach ($anOrg->{'epcr'} as $aEpcr) {
                 $seqType = (string) $aEpcr->seqtype;
                 $acc = (string) $aEpcr->acc;
                 $gi = (string) $aEpcr->gi;
                 $pos1 = (string) $aEpcr->pos1;
                 $pos2 = (string) $aEpcr->pos2;
                 $epcr_size = (string) $aEpcr->epcrsize;
                 $r = rand();
                 $u_res = $this->getRes() . md5($r . $gi . $pos1);
                 $u_label = "epcr for " . $pos1 . " " . $pos2;
                 parent::AddRDF(parent::describeIndividual($u_res, $u_label, $this->getVoc() . "epcr") . parent::triplify($uid_res, $this->getVoc() . 'has-epcr', $u_res));
                 if (isset($seqtype) && strlen($seqtype)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'seqtype', $seqtype));
                 }
                 if (isset($acc) && strlen($acc)) {
                     parent::AddRDF(parent::triplify($u_res, $this->getVoc() . 'x-genbank', 'genbank:' . $acc));
                 }
                 if (isset($gi) && strlen($gi)) {
                     parent::AddRDF(parent::triplify($u_res, $this->getVoc() . 'x-gi', 'gi:' . $gi));
                 }
                 if (isset($pos1) && strlen($pos1)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'pos1', $pos1));
                 }
                 if (isset($pos2) && strlen($pos2)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'pos2', $pos2));
                 }
                 if (isset($epcr_size) && strlen($epcr_size)) {
                     parent::AddRDF(parent::triplifyString($u_res, $this->getVoc() . 'epcr_size', $epcr_size));
                 }
             }
         }
         $this->WriteRDFBufferToWriteFile();
     }
 }
Exemplo n.º 27
0
 function CTD_chem_gene_ixn_types()
 {
     $first = true;
     while ($l = $this->GetReadFile()->Read()) {
         if ($l[0] == '#') {
             continue;
         }
         $a = explode("\t", $l);
         // check number of columns
         if ($first) {
             if (($c = count(explode("\t", $l))) != 4) {
                 trigger_error("CTD_chem_gene_ixn_types function expects 4 fields, found {$c}!" . PHP_EOL, E_USER_WARNING);
                 return FALSE;
             }
             $first = false;
         }
         $id = $this->getVoc() . $a[1];
         $parent = trim($a[3]);
         if (isset($parent) && !empty($parent)) {
             $this->AddRDF(parent::describeClass($id, $a[0], $this->getVoc() . $parent, null, $a[2]));
         } else {
             $this->AddRDF(parent::describeClass($id, $a[0], null, null, $a[2]));
         }
         parent::WriteRDFBufferToWriteFile();
     }
     return TRUE;
 }
Exemplo n.º 28
0
 function Run()
 {
     // get the work
     if ($this->GetParameterValue('files') == 'all') {
         $sources = explode("|", parent::getParameterList('files'));
         array_shift($sources);
     } else {
         // comma separated list
         $sources = explode(",", parent::getParameterValue('files'));
     }
     $download_files = array("h**o-sapiens" => "Pathway%20Commons%202%20homo%20sapiens.BIOPAX.owl.gz", "hprd" => "Pathway%20Commons%202%20HPRD.BIOPAX.owl.gz", "humancyc" => "Pathway%20Commons%202%20HumanCyc.BIOPAX.owl.gz", "nci-nature" => "Pathway%20Commons%202%20NCI_Nature.BIOPAX.owl.gz", "panther-pathway" => "Pathway%20Commons%202%20PANTHER%20Pathway.BIOPAX.owl.gz", "phosphositeplus" => "Pathway%20Commons%202%20PhosphoSitePlus.BIOPAX.owl.gz", "reactome" => "Pathway%20Commons%202%20Reactome.BIOPAX.owl.gz");
     $graph_uri = parent::getGraphURI();
     if (parent::getParameterValue('dataset_graph') == true) {
         parent::setGraphURI(parent::getDatasetURI());
     }
     $dataset_description = '';
     // iterate over the requested data
     foreach ($sources as $source) {
         echo "processing {$source}... ";
         $ldir = parent::getParameterValue('indir');
         $odir = parent::getParameterValue('outdir');
         $rdir = parent::getParameterValue('download_url');
         // set the remote and input files
         $file = $source . ".owl";
         $zfile = $source . ".owl.gz";
         $rfile = $rdir . $download_files[$source];
         $lfile = $ldir . $zfile;
         // download if if the file doesn't exist locally or we are told to
         if (!file_exists($lfile) || $this->GetParameterValue('download') == 'true') {
             // download
             echo "downloading... ";
             file_put_contents($lfile, file_get_contents($rfile));
         }
         // extract the file out of the ziparchive
         // and load into a buffer
         echo 'extracting... ';
         if (($fpin = gzopen($lfile, "r")) === FALSE) {
             trigger_error("Unable to open {$lfile}", E_USER_ERROR);
             exit;
         }
         $data = '';
         while (!gzeof($fpin)) {
             $buffer = gzgets($fpin, 4096);
             $data .= $buffer;
         }
         gzclose($fpin);
         // set the output file
         $suffix = parent::getParameterValue('output_format');
         $outfile = $source . '.' . $suffix;
         $gz = false;
         if (strstr(parent::getParameterValue('output_format'), "gz")) {
             $gz = true;
         }
         parent::setWriteFile($odir . $outfile, $gz);
         // send for parsing
         $p = new BioPAX2Bio2RDF($this);
         $p->SetBuffer($data)->SetBioPAXVersion(3)->SetBaseNamespace("http://purl.org/pc2/3/")->SetBio2RDFNamespace("http://bio2rdf.org/pathwaycommons:")->SetDatasetURI(parent::getDatasetURI());
         $rdf = $p->Parse();
         parent::addRDF($rdf);
         // write to output
         parent::writeRDFBufferToWriteFile();
         parent::getWriteFile()->Close();
         echo "done!" . PHP_EOL;
         //generate dataset description
         echo "Generating dataset description for {$zfile}... ";
         $source_file = (new DataResource($this))->setURI($rfile)->setTitle("Pathway Commons")->setRetrievedDate(date("Y-m-d\\TG:i:s\\Z", filemtime($lfile)))->setFormat("rdf/xml")->setPublisher("http://www.pathwaycommons.org/")->setHomepage("http://www.pathwaycommons.org/")->setRights("use")->setRights("restricted-by-source-license")->setLicense("http://www.pathwaycommons.org/pc2/home.html#data_sources")->setDataset("http://identifiers.org/pathwaycommons/");
         $dataset_description .= $source_file->toRDF();
         echo "done!" . PHP_EOL;
     }
     echo "Generating dataset description for Bio2RDF Pathways Commons dataset... ";
     $prefix = parent::getPrefix();
     $bVersion = parent::getParameterValue('bio2rdf_release');
     $date = date("Y-m-d\\TG:i:s\\Z");
     $output_file = (new DataResource($this))->setURI("http://download.bio2rdf.org/release/{$bVersion}/{$prefix}/")->setTitle("Bio2RDF v{$bVersion} RDF version of {$prefix} (generated at {$date})")->setSource($source_file->getURI())->setCreator("https://github.com/bio2rdf/bio2rdf-scripts/blob/master/pathwaycommons/pathwaycommons.php")->setCreateDate($date)->setHomepage("http://download.bio2rdf.org/release/{$bVersion}/{$prefix}/{$prefix}.html")->setPublisher("http://bio2rdf.org")->setRights("use-share-modify")->setRights("by-attribution")->setRights("restricted-by-source-license")->setLicense("http://creativecommons.org/licenses/by/3.0/")->setDataset(parent::getDatasetURI());
     if ($gz) {
         $output_file->setFormat("application/gzip");
     }
     if (strstr(parent::getParameterValue('output_format'), "nt")) {
         $output_file->setFormat("application/n-triples");
     } else {
         $output_file->setFormat("application/n-quads");
     }
     $dataset_description .= $output_file->toRDF();
     //write dataset description to file
     parent::setGraphURI($graph_uri);
     parent::setWriteFile($odir . parent::getBio2RDFReleaseFile());
     parent::getWriteFile()->write($dataset_description);
     parent::getWriteFile()->close();
     echo "done!" . PHP_EOL;
 }
Exemplo n.º 29
0
 function Parse($xml)
 {
     // state the dataset info
     foreach ($xml->release->dbinfo as $o) {
         $db = $o->attributes()->dbname . " v" . $o->attributes()->version . " (" . $o->attributes()->entry_count . " entries) [" . $o->attributes()->file_date . "]";
         parent::addRDF(parent::triplifyString(parent::getDatasetURI(), parent::getVoc() . "contains", $db));
         if ((string) $o->attributes()->dbname === "INTERPRO") {
             parent::setDatasetVersion($o->attributes()->version);
         }
     }
     // get a potential id list
     if (parent::getParameterValue("id_list") != '') {
         $id_list = explode(",", parent::getParameterValue("id_list"));
     }
     // now interate over the entries
     foreach ($xml->interpro as $o) {
         parent::writeRDFBufferToWriteFile();
         $interpro_id = $o->attributes()->id;
         if (isset($id_list) && !in_array($interpro_id, $id_list)) {
             continue;
         }
         echo "Processing {$interpro_id}" . PHP_EOL;
         $name = $o->name;
         $short_name = $o->attributes()->short_name;
         $type = $o->attributes()->type;
         $s = parent::getNamespace() . $interpro_id;
         //echo "Adding... $s rdfs:label $name ($short_name) $type [$s]".PHP_EOL;
         parent::addRDF(parent::describeIndividual($s, "{$name} ({$short_name}) {$type}", parent::getVoc() . $type));
         // get the pubs
         unset($pubs);
         foreach ($o->pub_list->publication as $p) {
             $pid = (string) $p->attributes()->id;
             if (isset($p->db_xref)) {
                 if ($p->db_xref->attributes()->db == "PUBMED") {
                     $pmid = (string) $p->db_xref->attributes()->dbkey;
                     $pubs['pid'][] = '<cite idref="' . $pid . '"/>';
                     $pubs['pmid'][] = '<a href="http://www.ncbi.nlm.nih.gov/pubmed/' . $pmid . '">pubmed:' . $pmid . '</a>';
                     parent::addRDF(parent::triplify($s, parent::getVoc() . "x-pubmed", "pubmed:{$pmid}"));
                 }
             }
         }
         $abstract = (string) $o->abstract->p->asXML();
         if (isset($pubs)) {
             $abstract = str_replace($pubs['pid'], $pubs['pmid'], $abstract);
         }
         parent::addRDF(parent::triplifyString($s, "dc:description", $abstract));
         if (isset($o->example_list)) {
             foreach ($o->example_list->example as $example) {
                 $db = (string) $example->db_xref->attributes()->db;
                 $id = (string) $example->db_xref->attributes()->dbkey;
                 parent::addRDF(parent::triplify($s, parent::getVoc() . "example-entry", "{$db}:{$id}"));
             }
         }
         if (isset($o->parent_list->rel_ref)) {
             foreach ($o->parent_list->rel_ref as $parent) {
                 $id = (string) $parent->attributes()->ipr_ref;
                 parent::addRDF(parent::triplify($s, parent::getVoc() . "parent", "interpro:{$id}"));
             }
         }
         if (isset($o->child->rel_ref)) {
             foreach ($o->child->rel_ref as $child) {
                 $id = (string) $child->attributes()->ipr_ref;
                 parent::addRDF(parent::triplify($s, parent::getVoc() . "child", "interpro:{$id}"));
             }
         }
         if (isset($o->contains->rel_ref)) {
             foreach ($o->contains->rel_ref as $contains) {
                 $id = (string) $contains->attributes()->ipr_ref;
                 parent::addRDF(parent::triplify($s, parent::getVoc() . "contains", "interpro:{$id}"));
             }
         }
         if (isset($o->found_in->rel_ref)) {
             foreach ($o->found_in->rel_ref as $f) {
                 $id = (string) $f->attributes()->ipr_ref;
                 parent::addRDF(parent::triplify($s, parent::getVoc() . "found-in", "interpro:{$id}"));
             }
         }
         if (isset($o->sec_list->sec_ac)) {
             foreach ($o->sec_ac as $s) {
                 $id = (string) $s->attributes()->acc;
                 parent::addRDF(parent::triplify($s, parent::getVoc() . "secondary-accession", "interpro:{$id}"));
             }
         }
         // xrefs
         if (isset($o->member_list->dbxref)) {
             foreach ($o->member_list->db_xref as $dbxref) {
                 $db = (string) $dbxref->attributes()->db;
                 $id = (string) $dbxref->attributes()->dbkey;
                 parent::addRDF(parent::triplify($s, parent::getVoc() . "x-" . strtolower($db), "{$db}:{$id}"));
             }
         }
         if (isset($o->external_doc_list)) {
             foreach ($o->external_doc_list->db_xref as $dbxref) {
                 $db = (string) $dbxref->attributes()->db;
                 $id = (string) $dbxref->attributes()->dbkey;
                 parent::addRDF(parent::triplify($s, parent::getVoc() . "x-" . strtolower($db), "{$db}:{$id}"));
             }
         }
         if (isset($o->structure_db_links->db_xref)) {
             foreach ($o->structure_db_links->db_xref as $dbxref) {
                 $db = (string) $dbxref->attributes()->db;
                 $id = (string) $dbxref->attributes()->dbkey;
                 parent::addRDF(parent::triplify($s, parent::getVoc() . "x-" . strtolower($db), "{$db}:{$id}"));
             }
         }
         // taxon distribution
         foreach ($o->taxonomy_distribution->taxon_data as $t) {
             $organism = (string) $t->attributes()->name;
             $number = (string) $t->attributes()->proteins_count;
             parent::addRDF(parent::triplifyString($s, parent::getVoc() . "taxon-distribution", "{$organism} ({$number})"));
         }
     }
 }
Exemplo n.º 30
0
 function mapping()
 {
     $this->AddRDF(parent::triplify($this->getVoc() . "has-proper-part", "owl:equivalentProperty", "sio:SIO_000053") . parent::triplify($this->getVoc() . "encodes", "owl:equivalentProperty", "sio:SIO_010078") . parent::triplify($this->getVoc() . "is-about", "owl:equivalentProperty", "sio:SIO_000332") . parent::triplify($this->getVoc() . "is-proper-part-of", "owl:equivalentProperty", "sio:SIO_000093") . parent::triplify($this->getVoc() . "article", "owl:equivalentProperty", "sio:SIO_000212") . parent::triplify($this->getVoc() . "has-participant", "owl:equivalentProperty", "sio:SIO_000132") . parent::triplify($this->getVoc() . "is-described-by", "owl:equivalentProperty", "sio:SIO_000557") . parent::triplify($this->getVoc() . "Protein", "owl:equivalentClass", "chebi:36080") . parent::triplify($this->getVoc() . "RNA", "owl:equivalentClass", "chebi:33697") . parent::triplify($this->getVoc() . "Chromosome", "owl:equivalentClass", "so:0000340"));
 }