Esempio n. 1
0
 function Run()
 {
     // directory shortcuts
     $ldir = parent::getParameterValue('indir');
     $odir = parent::getParameterValue('outdir');
     // get the listings page
     $rfile = trim(parent::getParameterValue('download_url'));
     $file = "interpro.xml.gz";
     $lfile = $ldir . $file;
     if (!file_exists($lfile) || parent::getParameterValue("download") == "true") {
         echo "Downloading {$lfile}" . PHP_EOL;
         $ret = file_get_contents($rfile);
         if ($ret === FALSE) {
             trigger_error("unable to download {$rfile}");
             exit;
         }
         file_put_contents($lfile, $ret);
     }
     echo "Loading XML file...";
     $cxml = new CXML($lfile);
     $cxml->Parse();
     $xml = $cxml->GetXMLRoot();
     echo "Done" . PHP_EOL;
     // set the write file
     $gz = strstr(parent::getParameterValue('output_format'), ".gz") === FALSE ? false : true;
     $outfile = "interpro." . parent::getParameterValue('output_format');
     parent::setWriteFile($odir . $outfile, $gz);
     echo "Parsing interpro xml file" . PHP_EOL;
     $this->parse($xml);
     parent::writeRDFBufferToWriteFile();
     parent::getWriteFile()->close();
     echo "Done!" . PHP_EOL;
     // let's make an nq file
     parent::setGraphURI(parent::getDatasetURI());
     // dataset description
     $source_version = parent::getDatasetVersion();
     $source_file = (new DataResource($this))->setURI($rfile)->setTitle("InterPro v{$source_version}")->setRetrievedDate(date("Y-m-d\\TG:i:s\\Z", filemtime($lfile)))->setFormat("application/xml")->setFormat("application/g-zip")->setPublisher("http://www.ebi.ac.uk/")->setHomepage("http://www.ebi.ac.uk/interpro/")->setRights("InterPro - Integrated Resource Of Protein Domains And Functional Sites. Copyright (C) 2001 The InterPro Consortium")->setLicense("http://www.ebi.ac.uk/interpro/faqs.html")->setDataset("http://identifiers.org/interpro/");
     $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}/{$outfile}")->setTitle("Bio2RDF v{$bVersion} RDF version of {$prefix} v{$source_version}")->setSource($source_file->getURI())->setCreator("https://github.com/bio2rdf/bio2rdf-scripts/blob/master/interpro/interpro.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();
     parent::setWriteFile($odir . parent::getBio2RDFReleaseFile());
     parent::getWriteFile()->write($dataset_description);
     parent::getWriteFile()->close();
     return true;
 }
Esempio n. 2
0
 function Run()
 {
     // directory shortcuts
     $ldir = $this->GetParameterValue('indir');
     $odir = $this->GetParameterValue('outdir');
     // get the listings page
     $rfile = trim($this->GetParameterValue('download_url'));
     $file = "interpro.xml.gz";
     $lfile = $ldir . $file;
     if (!file_exists($lfile) || $this->GetParameterValue("download") == "true") {
         echo "Downloading {$lfile}" . PHP_EOL;
         $ret = file_get_contents($rfile);
         if ($ret === FALSE) {
             trigger_error("unable to download {$rfile}");
             exit;
         }
         file_put_contents($lfile, $ret);
     }
     $cxml = new CXML($ldir, $file);
     $cxml->Parse();
     $xml = $cxml->GetXMLRoot();
     // set the write file
     $outfile = 'interpro.nt';
     $gz = false;
     if ($this->GetParameterValue('graph_uri')) {
         $outfile = 'interpro.nq';
     }
     if ($this->GetParameterValue('gzip')) {
         $outfile .= '.gz';
         $gz = true;
     }
     $this->SetWriteFile($odir . $outfile, $gz);
     echo "Parsing interpro xml file" . PHP_EOL;
     $this->Parse($xml);
     $this->WriteRDFBufferToWriteFile();
     $this->GetWriteFile()->Close();
     echo "Done!" . PHP_EOL;
     // generate the release file
     $this->DeleteBio2RDFReleaseFiles($odir);
     $desc = $this->GetBio2RDFDatasetDescription($this->GetNamespace(), "https://github.com/bio2rdf/bio2rdf-scripts/blob/master/interpro/intepro.php", $this->GetBio2RDFDownloadURL($this->GetNamespace()) . $outfile, "http://www.ebi.ac.uk/interpro/", array("use-share-modify"), null, $this->GetParameterValue('download_url'), $this->version);
     $this->SetWriteFile($odir . $this->GetBio2RDFReleaseFile($this->GetNamespace()));
     $this->GetWriteFile()->Write($desc);
     $this->GetWriteFile()->Close();
     return true;
 }
Esempio n. 3
0
 /**
  * process a results xml file from the download directory
  **/
 function process_file($infile)
 {
     $indir = parent::getParameterValue('indir');
     $xml = new CXML($infile);
     $this->setCheckPoint('file');
     while ($xml->Parse("clinical_study") == TRUE) {
         $this->setCheckPoint('record');
         $this->root = $root = $xml->GetXMLRoot();
         $this->nct_id = $nct_id = $this->getString("//id_info/nct_id");
         $this->study_id = $study_id = parent::getNamespace() . "{$nct_id}";
         ### declare
         $label = $this->getString("//brief_title");
         if (!$label) {
             $label = $this->getString("//official_title");
         }
         if (!$label) {
             $label = "Clinical trial #" . $nct_id;
         }
         parent::addRDF(parent::describeIndividual($study_id, $label, parent::getVoc() . "Clinical-Study") . parent::describeClass(parent::getVoc() . "Clinical-Study", "Clinical Study"));
         ##########################################################################################
         #required header
         ##########################################################################################
         parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "download-date", $this->getString('//required_header/download_date')) . parent::triplify($study_id, parent::getVoc() . "url", $this->getString('//required_header/url')));
         ##########################################################################################
         #identifiers
         ##########################################################################################
         parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "nct-id", $this->getString('//id_info/nct_id'), "xsd:string") . parent::triplifyString($study_id, parent::getVoc() . "org-study-id", $this->getString('//id_info/org_study_id'), "xsd:string"));
         $sids = $root->xpath('//id_info/secondary_id');
         if (isset($sids)) {
             foreach ($sids as $id) {
                 parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "secondary-id", (string) $id, "xsd:string"));
             }
         }
         $nctaliases = $root->xpath('//id_info/nct-alias');
         if (isset($nctaliases)) {
             foreach ($nctaliases as $id) {
                 parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "nct-alias", (string) $id, "xsd:string"));
             }
         }
         ##########################################################################################
         #titles
         ##########################################################################################
         parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "brief-title", $this->getString("//brief_title")) . parent::triplifyString($study_id, parent::getVoc() . "official-title", $this->getString("//official_title")));
         ###################################################################################
         #brief summary
         ###################################################################################
         $brief_summary = str_replace(array("\r", "\n", "\t"), array("
", "
", "	"), $this->getString('//brief_summary/textblock'));
         parent::addRDF(parent::triplifyString($study_id, $this->getVoc() . "brief-summary", $brief_summary));
         ####################################################################################
         # detailed description
         ####################################################################################
         $d = str_replace(array("\r", "\n", "\t"), array("
", "
", "	"), $this->getString('//detailed_description/textblock'));
         parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "detailed-description", $d));
         #########################################################################################
         #acronym
         #########################################################################################
         parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "acronym", $this->getString("//acronym")));
         ########################################################################################
         #sponsors
         ########################################################################################
         try {
             $sponsors = array("lead_sponsor", "collaborator");
             foreach ($sponsors as $sponsor) {
                 $a = @array_shift($root->xpath('//sponsors/' . $sponsor));
                 if ($a == null) {
                     break;
                 }
                 $agency = $this->getString("//agency", $a);
                 $agency_id = parent::getRes() . md5($agency);
                 $agency_class = $this->getString("//agency_class", $a);
                 $agency_class_id = parent::getRes() . md5($agency_class);
                 parent::addRDF(parent::describeIndividual($agency_id, $agency, parent::getVoc() . "Organization") . parent::describeClass(parent::getVoc() . "Organization", "Organization") . parent::triplify($study_id, parent::getVoc() . str_replace("_", "-", $sponsor), $agency_id) . parent::describeIndividual($agency_class_id, $agency_class, parent::getVoc() . "Organization") . parent::describeClass(parent::getVoc() . "Organization", "Organization") . parent::triplify($agency_id, parent::getVoc() . "organization", $agency_class_id));
             }
         } catch (Exception $e) {
             echo "There was an error in the lead sponsor element: {$e}\n";
         }
         #################################################################################
         # source
         #################################################################################
         $source = $this->getString('//source');
         if ($source) {
             $source_id = parent::getRes() . md5($source);
             parent::addRDF(parent::describeIndividual($source_id, $source, parent::getVoc() . "Organization") . parent::triplify($study_id, parent::getVoc() . "source", $source_id));
         }
         ######################################################################################
         # oversight
         ######################################################################################
         try {
             $oversight = @array_shift($root->xpath('//oversight_info'));
             $oversight_id = parent::getRes() . md5($oversight->asXML());
             $authority = $this->getString('//authority', $oversight);
             $authority_id = parent::getRes() . md5($authority);
             parent::addRDF(parent::describeIndividual($oversight_id, $authority, parent::getVoc() . "Organization") . parent::triplify($study_id, $this->getVoc() . "oversight", $oversight_id) . parent::triplify($study_id, $this->getVoc() . "authority", $authority_id) . parent::triplifyString($oversight_id, parent::getVoc() . "has-dmc", $this->getString('//has_dmc', $oversight)));
         } catch (Exception $e) {
             echo "There was an error in the oversight info element: {$e}\n";
         }
         #################################################################################
         # overall status
         #################################################################################
         $overall_status = $this->getString('//overall_status');
         if ($overall_status) {
             $status_id = parent::getRes() . md5($overall_status);
             parent::addRDF(parent::describeIndividual($status_id, $overall_status, parent::getVoc() . "Status") . parent::describeClass(parent::getVoc() . "Status", "Status") . parent::triplify($study_id, parent::getVoc() . "overall-status", $status_id));
         }
         #########################################################################################
         #why stopped
         #########################################################################################
         parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "why-stopped", $this->getString("//why_stopped")));
         ##################################################################################
         # dates
         ##################################################################################
         $dates = array("start_date", "end_date", "completion_date", "primary_completion_date", "verification_date", "lastchanged_date", "firstreceived_date", "firstreceived_results_date");
         foreach ($dates as $date) {
             $d = $this->getString('//' . $date);
             if ($d) {
                 $datetime = $this->getDatetimeFromDate($d);
                 if (isset($datetime)) {
                     parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . str_replace("_", "-", $date), $datetime));
                 } else {
                     trigger_error("unable to parse date: {$d}", E_USER_ERROR);
                 }
             }
         }
         ####################################################################################
         # phase
         ####################################################################################
         $phase = $this->getString('//phase');
         if ($phase && $phase != "N/A") {
             $phase_id = $this->getRes() . md5($phase);
             parent::addRDF(parent::describeIndividual($phase_id, $phase, parent::getVoc() . "Phase", $phase) . parent::describeClass(parent::getVoc() . "Phase", $phase) . parent::triplify($study_id, parent::getVoc() . "phase", $phase_id));
         }
         ###################################################################################
         # study type
         ####################################################################################
         $study_type = $this->getString('//study_type');
         if ($study_type) {
             $study_type_id = $this->getRes() . md5($study_type);
             parent::addRDF(parent::describeClass($study_type_id, $study_type, parent::getVoc() . "Study-Type") . parent::describeClass(parent::getVoc() . "Study-Type", "Study Type") . parent::triplify($study_id, parent::getVoc() . "study-type", $study_type_id));
         }
         ###############################################################################
         # study design
         ###############################################################################
         $study_design = $this->getString('//study_design');
         if ($study_design) {
             $study_design_id = parent::getRes() . md5($study_id . $study_design);
             parent::addRDF(parent::describeIndividual($study_design_id, "{$study_id} study design", parent::getVoc() . "Study-Design") . parent::describeClass(parent::getVoc() . "Study-Design", "Study Design") . parent::triplify($study_id, parent::getVoc() . "study-design", $study_design_id));
             // Intervention Model: Parallel Assignment, Masking: Double-Blind, Primary Purpose: Treatment
             foreach (explode(", ", $study_design) as $i => $b) {
                 $c = explode(":  ", $b);
                 if (isset($c[1])) {
                     $sdp = $study_design_id . "-" . ($i + 1);
                     $key = parent::getRes() . md5($c[0]);
                     $value = parent::getRes() . md5($c[1]);
                     parent::addRDF(parent::describeIndividual($sdp, $b, parent::getVoc() . "Study-Design-Parameter") . parent::describeClass(parent::getVoc() . "Study-Design-Parameter", "Study Design Parameter") . parent::triplify($sdp, parent::getVoc() . "key", $key) . parent::describeClass($key, $c[0]) . parent::triplify($sdp, parent::getVoc() . "value", $value) . parent::describeClass($value, $c[1]) . parent::triplify($study_design_id, parent::getVoc() . "study-design-parameter", $sdp));
                 }
             }
         }
         ####################################################################################
         # target duration
         ####################################################################################
         parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "target-duration", $this->getString('//target_duration')));
         ################################################################################
         # outcomes
         ###############################################################################
         $outcomes = array("primary_outcome", "secondary_outcome", "other_outcome");
         foreach ($outcomes as $outcome) {
             $o = $root->xpath('//' . $outcome);
             if ($o) {
                 $os = $o;
                 if (!is_array($o)) {
                     $os = array($o);
                 }
                 foreach ($os as $o) {
                     try {
                         $po_id = parent::getRes() . md5($nct_id . $o->asXML());
                         $po_type = parent::getVoc() . str_replace("_", "-", $outcome);
                         $measure = $this->getString('//measure', $o);
                         $time_frame = $this->getString('//time_frame', $o);
                         $safety_issue = $this->getString('//saftey_issue', $o);
                         $description = $this->getString('//description', $o);
                         parent::addRDF(parent::describeIndividual($po_id, $measure . " " . $time_frame, ucfirst($po_type)) . parent::describeClass(ucfirst($po_type), str_replace("_", " ", ucfirst($outcome))) . parent::triplifyString($po_id, "dc:description", $description) . parent::triplifyString($po_id, parent::getVoc() . "measure", $measure) . parent::triplifyString($po_id, parent::getVoc() . "time-frame", $time_frame) . parent::triplifyString($po_id, parent::getVoc() . "safety-issue", $safety_issue) . parent::triplify($study_id, parent::getVoc() . $po_type, $po_id));
                     } catch (Exception $e) {
                         echo "There was an error parsing the primary outcome element: {$e} \n";
                     }
                 }
             }
         }
         ##############################################################################
         #number of arms
         ##############################################################################
         try {
             parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "number-of-arms", $this->getString('//number_of_arms')));
         } catch (Exception $e) {
             echo "There was an exception parsing the number of arms element: {$e}\n";
         }
         ##############################################################################
         #number of groups
         ##############################################################################
         try {
             parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "number-of-arms", $this->getString('//number_of_groups')));
         } catch (Exception $e) {
             echo "There was an exception parsing the number of groups: {$e}\n";
         }
         ##############################################################################
         #enrollment
         ##############################################################################
         try {
             $e = $root->xpath('//enrollment');
             if ($e) {
                 $type = strtolower((string) $e[0]->attributes()->type);
                 $value = $this->getString('//enrollment');
                 parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . ($type ? $type . "-" : "") . "enrollment", $value));
             }
         } catch (Exception $e) {
             echo "There was an exception parsing the enrollment element: {$e}\n";
         }
         ###############################################################################
         #condition
         ###############################################################################
         try {
             $conditions = $root->xpath('//condition');
             foreach ($conditions as $condition) {
                 $mesh_label_id = parent::getRes() . md5($condition);
                 parent::addRDF(parent::triplify($study_id, parent::getVoc() . "condition", $mesh_label_id) . parent::describeClass($mesh_label_id, $condition, parent::getVoc() . "Condition") . parent::describeClass(parent::getVoc() . "Condition", "Condition"));
             }
         } catch (Exception $e) {
             echo "There was an exception parsing condition element: {$e}\n";
         }
         ################################################################################
         # arm_group
         ################################################################################
         try {
             $arm_groups = $root->xpath('//arm_group');
             foreach ($arm_groups as $arm_group) {
                 $arm_group_id = $this->getString('./arm_group_label', $arm_group);
                 $arm_group_id = md5($arm_group_id);
                 $arm_group_uri = parent::getRes() . $this->nct_id . "/arm-group/" . $arm_group_id;
                 $arm_group_label = $this->nct_id . " arm group " . $arm_group_id;
                 $arm_group_type = ucfirst(str_replace(" ", "_", $this->getString('./arm_group_type', $arm_group)));
                 if (!$arm_group_type) {
                     $arm_group_type = "Clinical-Arm";
                 }
                 $description = $this->getString('./description', $arm_group);
                 parent::addRDF(parent::describeIndividual($arm_group_uri, $arm_group_label, parent::getVoc() . $arm_group_type) . parent::describeClass(parent::getVoc() . $arm_group_type, ucfirst(str_replace("_", " ", $arm_group_type))) . parent::triplifyString($arm_group_uri, parent::getVoc() . "description", $description) . parent::describeIndividual($arm_group_uri, $arm_group, parent::getVoc() . "Arm-Group") . parent::describeClass(parent::getVoc() . "Arm-Group", "Arm Group") . parent::triplify($study_id, parent::getVoc() . "arm-group", $arm_group_uri));
             }
         } catch (Exception $e) {
             echo "There was an exception in arm groups: {$e}\n";
         }
         ##############################################################################
         #intervention
         ##############################################################################
         try {
             $interventions = $root->xpath('//intervention');
             foreach ($interventions as $intervention) {
                 $intervention_id = parent::getRes() . md5($intervention->asXML());
                 $intervention_name = $this->getString('./intervention_name', $intervention);
                 $intervention_type = $this->getString('./intervention_type', $intervention);
                 $intervention_type_uri = parent::getVoc() . ucfirst(str_replace(" ", "_", $intervention_type));
                 $intervention_desc = $this->getString('./description', $intervention);
                 $intervention_on = $this->getString('./other_name', $intervention);
                 parent::addRDF(parent::describeIndividual($intervention_id, $intervention_name, $intervention_type_uri) . parent::describeClass($intervention_type_uri, $intervention_type) . parent::triplifyString($intervention_id, parent::getVoc() . "intervention-name", $intervention_name) . parent::triplifyString($intervention_id, parent::getVoc() . "intervention-desc", $intervention_desc) . parent::triplifyString($intervention_id, parent::getVoc() . "other-name", $intervention_on) . parent::triplify($study_id, parent::getvoc() . "intervention", $intervention_id));
                 $agl = $intervention->xpath("./arm_group_label");
                 foreach ($agl as $a) {
                     $arm_group_id = md5($a);
                     $ag = parent::getRes() . $this->nct_id . "/arm-group/" . $arm_group_id;
                     parent::addRDF(parent::describeIndividual($ag, $a, parent::getVoc() . "Arm-Group") . parent::describeClass(parent::getVoc() . "Arm-Group", "Arm Group") . parent::triplify($intervention_id, parent::getVoc() . "arm-group", $ag));
                 }
             }
         } catch (Exception $e) {
             echo "There was an error in interventions {$e}\n";
         }
         ###############################################################################
         #eligibility
         ################################################################################
         try {
             $eligibility = @array_shift($root->xpath('//eligibility'));
             if ($eligibility !== null) {
                 $eligibility_label = "eligibility for " . $study_id;
                 $eligibility_id = parent::getRes() . md5($eligibility->asXML());
                 parent::addRDF(parent::describeIndividual($eligibility_id, $eligibility_label, parent::getVoc() . "Eligibility") . parent::describeClass(parent::getVoc() . "Eligibility", "Eligibility") . parent::triplify($study_id, parent::getVoc() . "eligibility", $eligibility_id));
                 if ($criteria = @array_shift($eligibility->xpath('./criteria'))) {
                     $text = @array_shift($criteria->xpath('./textblock'));
                     parent::addRDF(parent::triplifyString($eligibility_id, parent::getVoc() . "text", $text));
                     $c = preg_split("/(Inclusion Criteria\\:|Exclusion Criteria\\:)/", $text);
                     //inclusion
                     if (isset($c[1])) {
                         $d = explode(" - ", $c[1]);
                         // the lists are separated by a hyphen
                         foreach ($d as $inclusion) {
                             $inc = trim($inclusion);
                             if ($inc != '') {
                                 $inc_id = parent::getRes() . md5($inc);
                                 parent::addRDF(parent::describeIndividual($inc_id, $inc, parent::getVoc() . "Inclusion-Criteria") . parent::describeClass(parent::getVoc() . "Inclusion-Criteria", "Inclusion Criteria") . parent::triplify($eligibility_id, parent::getVoc() . "inclusion-criteria", $inc_id));
                             }
                         }
                     }
                     //exclusion
                     if (isset($c[2])) {
                         $d = explode(" - ", $c[1]);
                         foreach ($d as $exclusion) {
                             $exc = trim($exclusion);
                             if ($exc != '') {
                                 $exc_id = parent::getRes() . md5($exc);
                                 parent::addRDF(parent::describeIndividual($exc_id, $exc, parent::getVoc() . "Exclusion-Criteria") . parent::describeClass(parent::getVoc() . "Exclusion-Criteria", "Exclusion Criteria") . parent::triplify($eligibility_id, parent::getVoc() . "exclusion-criteria", $exc_id));
                             }
                         }
                     }
                 }
                 parent::addRDF(parent::triplifyString($eligibility_id, parent::getVoc() . "gender", $this->getString('./gender', $eligibility)));
                 parent::addRDF(parent::triplifyString($eligibility_id, parent::getVoc() . "healthy-volunteers", $this->getString('./healthy_volunteers', $eligibility)));
                 $attributes = array('minimum_age', 'maximum_age');
                 foreach ($attributes as $a) {
                     $s = $this->getString('./' . $a, $eligibility);
                     if ($s != 'N/A') {
                         $age = trim(str_replace("Years", "", $s));
                         parent::addRDF(parent::triplifyString($eligibility_id, parent::getVoc() . str_replace("_", "-", $a), $age));
                     }
                 }
                 $attributes = array("study_pop" => "study-population", "sampling_method" => "sampling-method");
                 foreach ($attributes as $a => $r) {
                     $e = @array_shift($eligibility->xpath('./' . $a));
                     if ($s = $this->getString('./' . $a, $eligibility)) {
                         parent::addRDF(parent::triplifyString($eligibility_id, parent::getVoc() . $r, $this->getString('./textblock', $e)));
                     }
                 }
             }
         } catch (Exception $e) {
             echo "There was an error in eligibility: {$e}\n";
         }
         ######################################################################################
         #biospec
         #####################################################################################
         parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "biospec-retention", $this->getString('//biospec_retention')));
         try {
             $b = @array_shift($root->xpath('//biospec_descr'));
             if ($b) {
                 parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "biospec_descr", $this->getString('./textblock', $b)));
             }
         } catch (Exception $e) {
             echo "There was an error in biospec_descr: {$e}\n";
         }
         ###################################################################
         # contacts
         ###################################################################
         $contacts = array("overall_official", "overall_contact", "overall_contact_backup");
         try {
             foreach ($contacts as $c) {
                 $d = @array_shift($root->xpath('//' . $c));
                 if ($d) {
                     parent::addRDF(parent::triplify($study_id, parent::getVoc() . str_replace("_", "-", $c), $this->makeContact($d)));
                 }
             }
         } catch (Exception $e) {
             echo "There was an error parsing overall contact: {$e}" . "\n";
         }
         ##############################################################
         # location of facility doing the testing
         ##############################################################
         try {
             $location = @array_shift($root->xpath('//location'));
             if ($location) {
                 $location_uri = parent::getRes() . md5($location->asXML());
                 $name = $this->getString('//facility/name', $location);
                 $address = @array_shift($location->xpath('//facility/address'));
                 $contact = @array_shift($location->xpath('//contact'));
                 $backups = @array_shift($location->xpath('//contact_backup'));
                 $investigators = @array_shift($location->xpath('//investigator'));
                 parent::addRDF(parent::describeIndividual($location_uri, $name, parent::getVoc() . "Location") . parent::describeClass(parent::getVoc() . "Location", "Location") . parent::triplifyString($location_uri, parent::getVoc() . "status", $this->getString('//status', $location)) . parent::triplify($study_id, parent::getVoc() . "location", $location_uri) . parent::triplify($location_uri, parent::getVoc() . "address", $this->makeAddress($address)) . ($contact != null ? parent::triplify($location_uri, parent::getVoc() . "contact", $this->makeContact($contact)) : ""));
                 if ($backups) {
                     foreach ($backups as $backup) {
                         parent::addRDF(parent::triplify($location_uri, parent::getVoc() . "contact-backup", $this->makeContact($backup)));
                     }
                 }
                 if ($investigators) {
                     foreach ($investigators as $investigator) {
                         parent::addRDF(parent::triplify($location_uri, parent::getVoc() . "investigator", $this->makeContact($investigator)));
                     }
                 }
             }
         } catch (Exception $e) {
             echo "There was an error parsing location: {$e}" . "\n";
         }
         ######################################################################
         #countries
         ######################################################################
         try {
             $a = array("location_countries", "removed_countries");
             foreach ($a as $country) {
                 $lc = @array_shift($root->xpath('//' . $country));
                 if ($lc) {
                     $label = $this->getString('//country', $lc);
                     $cid = parent::getRes() . md5($label);
                     parent::addRDF(parent::describeIndividual($cid, $label, parent::getVoc() . "Country") . parent::describeClass(parent::getVoc() . "Country", "Country") . parent::triplify($study_id, parent::getVoc() . "country", $cid));
                 }
             }
         } catch (Exception $e) {
             echo "There was an error parsing country: {$e}" . "\n";
         }
         ######################################################################
         #reference
         ######################################################################
         try {
             $a = array("reference", "result_reference");
             foreach ($a as $ref_type) {
                 $references = $root->xpath('//' . $ref_type);
                 foreach ($references as $reference) {
                     $p = $this->getString('./PMID', $reference);
                     if ($p) {
                         $pmid = "pubmed:{$p}";
                         parent::addRDF(parent::describeIndividual($pmid, $p, parent::getVoc() . "Reference") . parent::describeClass(parent::getVoc() . "Reference", "Reference") . parent::triplifyString($pmid, parent::getVoc() . "citation", $this->getString('./citation', $reference)) . parent::triplify($study_id, parent::getVoc() . str_replace("_", "-", $ref_type), $pmid));
                     }
                 }
             }
         } catch (Exception $e) {
             echo "There was an error parsing references element: {$e}\n";
         }
         #######################################################################
         #link
         #######################################################################
         try {
             $links = $root->xpath('//link');
             foreach ($links as $i => $link) {
                 $url = $this->getString('./url', $link);
                 $url = preg_replace("/>.*\$/", "", $url);
                 $lid = parent::getRes() . md5($url);
                 parent::addRDF(parent::describeIndividual($lid, $this->getString('./description', $link), parent::getVoc() . "Link") . parent::describeClass(parent::getVoc() . "Link", "Link") . parent::triplify($lid, parent::getVoc() . "url", $url) . parent::triplify($study_id, parent::getVoc() . "link", $lid));
             }
         } catch (Exception $e) {
             echo "There was an error parsing link element: {$e}\n";
         }
         ############################################################################
         #responsible party
         ############################################################################
         try {
             $rp = @array_shift($root->xpath('//responsible_party'));
             if ($rp) {
                 $rp_id = parent::getRes() . md5($rp->asXML());
                 $label = $this->getString('./name_title', $rp);
                 if (!$label) {
                     $label = $this->getString('./organization', $rp);
                 } else {
                     $label .= ", " . $this->getString('./organization', $rp);
                 }
                 if (!$label) {
                     $label = $this->getString('./party_type', $rp);
                 }
                 $org_id = parent::getRes() . md5($this->getString('./organization', $rp));
                 parent::addRDF(parent::describeIndividual($rp_id, $label, parent::getVoc() . "Responsible-Party") . parent::describeClass(parent::getVoc() . "Responsible-Party", "Responsible Party") . parent::triplify($study_id, parent::getVoc() . "responsible-party", $rp_id) . parent::triplify($rp_id, parent::getVoc() . "organization", $org_id) . parent::describeIndividual($org_id, $this->getString('./organization', $rp), parent::getVoc() . "Organization") . parent::describeClass(parent::getVoc() . "Organization", "Organization") . parent::triplifyString($rp_id, parent::getVoc() . "name-title", $this->getString('./name_title', $rp)) . parent::triplifyString($rp_id, parent::getVoc() . "party-type", $this->getString('./party_type', $rp)) . parent::triplifyString($rp_id, parent::getVoc() . "investigator-affiliation", $this->getString('./investigator_affiliation', $rp)) . parent::triplifyString($rp_id, parent::getVoc() . "investigator-full-name", $this->getString('./investigator_full_name', $rp)) . parent::triplifyString($rp_id, parent::getVoc() . "investigator-title", $this->getString('./investigator_title', $rp)));
             }
         } catch (Exception $e) {
             echo "There was an error parsing the responsible_party element: {$e}\n";
         }
         ##############################################################################
         # keywords
         ##############################################################################
         try {
             $keywords = $root->xpath('//keyword');
             foreach ($keywords as $keyword) {
                 parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "keyword", (string) $keyword));
             }
         } catch (Exception $e) {
             echo "There was an error parsing the keywords element: {$e}";
         }
         # mesh terms
         # note: mesh terms are assigned using an imperfect algorithm
         try {
             $mesh_terms = $root->xpath('//condition_browse/mesh_term');
             foreach ($mesh_terms as $mesh_term) {
                 $term = (string) $mesh_term;
                 $mesh_id = parent::getRes() . md5($term);
                 parent::addRDF(parent::triplify($study_id, parent::getVoc() . "condition-mesh", $mesh_id));
                 parent::addRDF(parent::triplifyString($mesh_id, "rdfs:label", $term));
             }
         } catch (Exception $e) {
             echo "There was an error in mesh_terms: {$e}\n";
         }
         ################################################################################
         # regulated by fda?  is section 801? has expanded access?
         ################################################################################
         try {
             parent::addRDF(parent::triplifyString($study_id, parent::getVoc() . "is-fda-regulated", $this->getString('is_fda_regulated')) . parent::triplifyString($study_id, parent::getVoc() . "is-section-801", $this->getString('is_section_801')) . parent::triplifyString($study_id, parent::getVoc() . "has-expanded-access", $this->getString('has_expanded_access')));
         } catch (Exception $e) {
             echo "There was an error parsing the is_fda_regulated element: {$e}\n";
         }
         ###############################################################################
         # mesh terms for the intervention browse
         ###############################################################################
         try {
             $a = array("condition_browse", "intervention_browse");
             foreach ($a as $browse_type) {
                 $terms = $root->xpath("//{$browse_type}/mesh_term");
                 foreach ($terms as $term) {
                     $term_label = (string) $term;
                     $term_id = parent::getRes() . md5($term);
                     parent::addRDF(parent::describeIndividual($term_id, $term_label, parent::getVoc() . "Term") . parent::describeClass(parent::getVoc() . "Term", "Term") . parent::triplify($study_id, parent::getVoc() . str_replace("_", "-", $browse_type), $term_id));
                 }
             }
         } catch (Exception $e) {
             echo "There was an error parsing {$browse_type}/mesh_term element: {$e}\n";
         }
         ################################################################################
         # clinical results
         ################################################################################
         try {
             $cr = @array_shift($root->xpath('//clinical_results'));
             if ($cr) {
                 $cr_id = parent::getRes() . md5($study_id . $cr->asXML());
                 parent::addRDF(parent::describeIndividual($cr_id, "clinical results for {$study_id}", parent::getVoc() . "Clinical-Result") . parent::describeClass(parent::getVoc() . "Clinical-Result", "Clinical Result") . parent::triplifyString($cr_id, parent::getVoc() . "description", $this->getString('./desc', $cr)) . parent::triplifyString($cr_id, parent::getVoc() . "restrictive-agreement", $this->getString('./restrictive_agreement', $cr)) . parent::triplifyString($cr_id, parent::getVoc() . "limitations-and-caveats", $this->getString('./limitations_and_caveats', $cr)) . parent::triplify($study_id, parent::getVoc() . "clinical-result", $cr_id));
             }
         } catch (Exception $e) {
             echo "There was an error parsing clinical results: {$e}\n";
         }
         ################################################################################
         # Participant Flow
         ################################################################################
         try {
             $pc = 1;
             $mc = 1;
             $wc = 1;
             $pf = @array_shift($root->xpath('//clinical_results/participant_flow'));
             if ($pf) {
                 $pf_id = parent::getRes() . md5($pf->asXML());
                 parent::addRDF(parent::describeIndividual($pf_id, "participant flow for {$study_id}", parent::getVoc() . "Participant-Flow") . parent::describeClass(parent::getVoc() . "Participant-Flow", "Participant-Flow") . parent::triplify($study_id, parent::getVoc() . "participant-flow", $pf_id) . parent::triplifyString($pf_id, parent::getVoc() . "recruitment-details", $this->getString('./recruitment_details', $pf)) . parent::triplifyString($pf_id, parent::getVoc() . "pre-assignment-details", $this->getString('./pre_assignment_details', $pf)));
                 $groups = @array_shift($pf->xpath('./group_list'));
                 foreach ($groups as $group) {
                     parent::addRDF(parent::triplify($pf_id, parent::getVoc() . "group", $this->makeGroup($group)));
                 }
                 //period_list
                 $periods = @array_shift($pf->xpath('./period_list'));
                 foreach ($periods as $period) {
                     $period_id = parent::getRes() . $nct_id . "/period/" . $pc++;
                     $period_title = $this->getString('./title', $period);
                     parent::addRDF(parent::describeIndividual($period_id, $period_title . " for {$nct_id}", parent::getVoc() . "Period") . parent::describeClass(parent::getVoc() . "Period", "Period") . parent::triplify($pf_id, parent::getVoc() . "period", $period_id));
                     // milestones
                     $milestones = @array_shift($period->xpath('./milestone_list'));
                     if ($milestones) {
                         foreach ($milestones as $milestone) {
                             $milestone_id = parent::getRes() . $nct_id . "/milestone/" . $mc++;
                             $label = $this->getString('./title', $milestone);
                             parent::addRDF(parent::describeIndividual($milestone_id, $label, parent::getVoc() . "Milestone") . parent::describeClass(parent::getVoc() . "Milestone", "Milestone") . parent::triplify($period_id, parent::getVoc() . "milestone", $milestone_id));
                             // participants
                             $p = 1;
                             $ps_list = @array_shift($milestone->xpath('./participants_list'));
                             foreach ($ps_list as $ps) {
                                 $ps_id = $milestone_id . "/p/" . $p++;
                                 $group_id = parent::getRes() . $this->nct_id . "/group/" . $ps->attributes()->group_id;
                                 $count = (string) $ps->attributes()->count;
                                 parent::addRDF(parent::describeIndividual($ps_id, "participant counts in " . $ps->attributes()->group_id . " for milestone {$mc} of {$nct_id}", parent::getVoc() . "Participant-Count") . parent::describeClass(parent::getVoc() . "Participant-Count", "Participant Count") . parent::triplify($ps_id, parent::getVoc() . "group", $group_id) . parent::triplifyString($ps_id, parent::getVoc() . "count", $count) . parent::triplify($milestone_id, parent::getVoc() . "participant-counts", $ps_id));
                             }
                         }
                     }
                     // milestones
                     $withdraws = @array_shift($period->xpath('./drop_withdraw_reason_list'));
                     if ($withdraws) {
                         foreach ($withdraws as $withdraw) {
                             $wid = parent::getRes() . $this->nct_id . "/withdraw/" . $wc++;
                             $label = $this->getString('./title', $withdraw);
                             parent::addRDF(parent::describeIndividual($wid, $label, parent::getVoc() . "Withdraw-Reason") . parent::describeClass(parent::getVoc() . "Withdraw-Reason", "Withdraw Reason"));
                             // participants
                             $ps_list = @array_shift($withdraw->xpath('./participants_list'));
                             foreach ($ps_list as $ps) {
                                 $group_id = parent::getRes() . $nct_id . "/group/" . $ps->attributes()->group_id;
                                 $count = (string) $ps->attributes()->count;
                                 parent::addRDF(parent::triplify($wid, parent::getVoc() . "group", $group_id) . parent::triplifyString($wid, parent::getVoc() . "count", $count));
                             }
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             echo "There was an error parsing participant flow element: {$e}\n";
         }
         ################################################################################
         # baseline
         ################################################################################
         try {
             $baseline = @array_shift($root->xpath('//baseline'));
             if ($baseline) {
                 $b_id = $this->nct_id . "/baseline";
                 $b_uri = parent::getRes() . $b_id;
                 // group list
                 $groups = @array_shift($baseline->xpath('./group_list'));
                 foreach ($groups as $group) {
                     parent::addRDF(parent::describeIndividual($b_uri, "baseline for {$nct_id}", parent::getVoc() . "Baseline") . parent::describeClass(parent::getVoc() . "Baseline", "Baseline") . parent::triplify($b_uri, parent::getVoc() . "group", $this->makeGroup($group)) . parent::triplify($study_id, parent::getVoc() . "baseline", $b_uri));
                 }
                 // measure list
                 $measures = @array_shift($baseline->xpath('./measure_list'));
                 foreach ($measures as $measure) {
                     parent::addRDF(parent::triplify($b_uri, parent::getVoc() . "measure", $this->makeMeasure($measure)));
                 }
             }
         } catch (Exception $e) {
             echo "Error in parsing baseline" . PHP_EOL;
         }
         ################################################################################
         # outcomes
         ################################################################################
         try {
             $outcomes = @array_shift($root->xpath('//outcome_list'));
             if ($outcomes) {
                 foreach ($outcomes as $i => $outcome) {
                     $outcome_id = $this->nct_id . "/outcome/" . ($i + 1);
                     $outcome_uri = parent::getRes() . $outcome_id;
                     $outcome_label = $this->getString("./title", $outcome);
                     if (!$outcome_label) {
                         $outcome_label = "outcome for " . $this->nct_id;
                     }
                     parent::addRDF(parent::describeIndividual($outcome_uri, $outcome_label, parent::getVoc() . "Outcome", $this->getString("./description", $outcome)) . parent::describeClass(parent::getVoc() . "Outcome", "Outcome") . parent::triplify($study_id, parent::getVoc() . "outcome", $outcome_uri) . parent::triplifyString($outcome_uri, parent::getVoc() . "type", $this->getString("./type", $outcome)) . parent::triplifyString($outcome_uri, parent::getVoc() . "time-frame", $this->getString("./time_frame", $outcome)) . parent::triplifyString($outcome_uri, parent::getVoc() . "safety-issue", $this->getString("./safety_issue", $outcome)) . parent::triplifyString($outcome_uri, parent::getVoc() . "posting-date", $this->getString("./posting-date", $outcome)) . parent::triplifyString($outcome_uri, parent::getVoc() . "population", $this->getString("./population", $outcome)));
                     $groups = @array_shift($outcome->xpath('./group_list'));
                     if ($groups) {
                         foreach ($groups as $group) {
                             parent::addRDF(parent::triplify($outcome_uri, parent::getVoc() . "group", $this->makeGroup($group)));
                         }
                     }
                     // measure list
                     $measures = @array_shift($outcome->xpath('./measure_list'));
                     if ($measures) {
                         foreach ($measures as $measure) {
                             parent::addRDF(parent::triplify($outcome_uri, parent::getVoc() . "measure", $this->makeMeasure($measure)));
                         }
                     }
                     // analysis list
                     $analyses = @array_shift($outcome->xpath('./analysis_list'));
                     if ($analyses) {
                         foreach ($analyses as $analysis) {
                             parent::addRDF(parent::triplify($outcome_uri, parent::getVoc() . "analysis", $this->makeAnalysis($analysis)));
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             echo "Error in parsing outcomes" . PHP_EOL;
         }
         ################################################################################
         # events
         ################################################################################
         try {
             $c_ev = $c_c = 1;
             $reported_events = @array_shift($root->xpath('//reported_events'));
             if ($reported_events) {
                 $rp_id = parent::getRes() . md5($reported_events->asXML());
                 $groups = @array_shift($reported_events->xpath('./group_list'));
                 parent::addRDF(parent::describeIndividual($rp_id, "Reported events for {$nct_id}", parent::getVoc() . "Reported-Events") . parent::describeClass(parent::getVoc() . "Reported-Events", "Reported Events") . parent::triplify($study_id, parent::getVoc() . "reported-events", $rp_id));
                 foreach ($groups as $group) {
                     parent::addRDF(parent::triplify($rp_id, parent::getVoc() . "group", $this->makeGroup($group)));
                 }
                 // events
                 $event_list = array("serious_events" => "Serious Event", "other_events" => "Other Event");
                 foreach ($event_list as $ev => $ev_label) {
                     $et = @array_shift($reported_events->xpath('./' . $ev));
                     if (!$et) {
                         continue;
                     }
                     $ev_uri = parent::getVoc() . str_replace(" ", "-", $ev_label);
                     $categories = @array_shift($et->xpath('./category_list'));
                     foreach ($categories as $category) {
                         $major_title = $this->getString('./title', $category);
                         $major_title_uri = parent::getRes() . md5($major_title);
                         $events = @array_shift($category->xpath('./event_list'));
                         foreach ($events as $event) {
                             $e_uri = parent::getRes() . $this->nct_id . "/{$ev}/" . $c_ev++;
                             $subtitle = (string) $this->getString('./sub_title', $event) . " for " . $this->nct_id;
                             $subtitle_uri = parent::getRes() . md5($subtitle);
                             parent::addRDF(parent::describeIndividual($e_uri, $subtitle, $ev_uri) . parent::describeClass($ev_uri, $ev_label) . parent::triplify($e_uri, parent::getVoc() . "sub-title", $subtitle_uri) . parent::describeIndividual($subtitle_uri, $subtitle, parent::getVoc() . "Event") . parent::describeClass(parent::getVoc() . "Event", "Event") . parent::triplify($e_uri, parent::getVoc() . "major-title", $major_title_uri) . parent::describeClass($major_title_uri, $major_title) . parent::triplify($rp_id, parent::getVoc() . str_replace("_", "-", $ev), $e_uri));
                             $counts = $event->xpath('./counts');
                             foreach ($counts as $c) {
                                 $group_id = $c->attributes()->group_id;
                                 $group_uri = parent::getRes() . $nct_id . "/group/" . $group_id;
                                 $c_uri = $e_uri . "/count/" . $c_c++;
                                 parent::addRDF(parent::describeIndividual($c_uri, $subtitle . " for " . $group_id . " in " . $this->nct_id, parent::getVoc() . "Event-Count") . parent::describeClass(parent::getVoc() . "Event-Count", "Event Count") . parent::triplify($c_uri, parent::getVoc() . "group", $group_uri) . parent::triplify($e_uri, parent::getVoc() . "count", $c_uri) . parent::triplifyString($c_uri, parent::getVoc() . "default-vocabulary", $this->getString('./default_vocab', $et)) . parent::triplifyString($c_uri, parent::getVoc() . "frequency-threshold", $this->getString('./frequency_threshold', $et)) . parent::triplifyString($c_uri, parent::getVoc() . "default-assessment", $this->getString('./default_assessment', $et)) . parent::triplifyString($c_uri, parent::getVoc() . "number-events", $c->attributes()->events) . parent::triplifyString($c_uri, parent::getVoc() . "subjects-affected", $c->attributes()->subjects_affected) . parent::triplifyString($c_uri, parent::getVoc() . "subjects-at-risk", $c->attributes()->subjects_at_risk));
                             }
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             echo "Error in parsing reported events" . PHP_EOL;
         }
         parent::writeRDFBufferToWriteFile();
     }
     $this->setCheckPoint('record');
     $this->setCheckPoint('dataset');
 }
Esempio n. 4
0
 /**
  *  parse an individual pubchem substance file
  **/
 function parse_substance_file($indir, $file)
 {
     $xml = new CXML($indir, $file);
     while ($xml->Parse("PC-Substance") == TRUE) {
         parent::setCheckpoint('record');
         $this->parse_substance_record($xml);
     }
 }
Esempio n. 5
0
 function Parse($ldir, $infile)
 {
     $i = 0;
     $xml = new CXML($ldir, $infile);
     while ($xml->Parse("partner") == TRUE) {
         $this->ParsePartnerEntry($xml);
         $this->WriteRDFBufferToWriteFile();
         //if($i++ == 10) break;
     }
     unset($xml);
     $xml = new CXML($ldir, $infile);
     while ($xml->Parse("drug") == TRUE) {
         $this->ParseDrugEntry($xml);
         $this->WriteRDFBufferToWriteFile();
         //if($i++ == 10) break;
     }
     unset($xml);
 }
 /**
  * process a results xml file from the download directory
  **/
 function process_result($infile, $curr_block)
 {
     $indir = $this->GetParameterValue('indir');
     $outfile = $this->GetParameterValue("outdir");
     $this->CreateDirectory($outfile);
     $outfile .= basename($infile, ".xml") . ".nt";
     $gz = false;
     if ($this->GetParameterValue('gzip')) {
         $outfile .= basename($infile, ".xml") . ".nq";
     }
     if ($this->GetParameterValue('gzip')) {
         $outfile .= '.gz';
         $gz = true;
     }
     $this->SetWriteFile($outfile, $gz);
     $xml = new CXML($indir, basename($infile));
     while ($xml->Parse("clinical_study") == TRUE) {
         $root = $xml->GetXMLRoot();
         #########################################################################################
         # study ids
         #########################################################################################
         $nct_id = @array_shift($root->xpath("//id_info/nct_id"));
         $org_study_id = @array_shift($root->xpath("//id_info/org_study_id"));
         $secondary_id = @array_shift($root->xpath("//id_info/secondary_id"));
         $study_id = "clinicaltrials:" . $nct_id;
         $this->AddRDF($this->QQuad($study_id, "rdf:type", "clinicaltrials_vocabulary:Clinical-Study"));
         $this->AddRDF($this->QQuadl($study_id, "dc:identifier", $nct_id));
         $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:org-study-identifier", $org_study_id));
         $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:secondary-identifier", $secondary_id));
         ##########################################################################################
         #brief trial
         ##########################################################################################
         $brief_title = @array_shift($root->xpath("//brief_title"));
         if ($brief_title != "") {
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:brief-title", $this->SafeLiteral($brief_title)));
             $this->AddRDF($this->QQuadl($study_id, "rdfs:label", $this->SafeLiteral($brief_title) . " [{$study_id}]"));
         }
         ##########################################################################################
         #official title
         ##########################################################################################
         $official_title = @array_shift($root->xpath("//official_title"));
         if ($official_title != "") {
             $this->AddRDF($this->QQuadl($study_id, "dc:title", $this->SafeLiteral($official_title)));
             if (!$brief_title) {
                 $this->AddRDF($this->QQuadl($study_id, "rdfs:label", $this->SafeLiteral($official_title) . " [{$study_id}]"));
             }
         }
         #########################################################################################
         #acronym
         #########################################################################################
         $acronym = @array_shift($root->xpath("//acronym"));
         if ($acronym != "") {
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:acronym", $this->SafeLiteral($acronym)));
         }
         ########################################################################################
         #lead_sponser
         ########################################################################################
         try {
             $lead_sponsor = @array_shift($root->xpath('//sponsors/lead_sponsor'));
             $agency = @array_shift($lead_sponsor->xpath("//agency"));
             $agency_class = @array_shift($lead_sponsor->xpath("//agency_class"));
             $lead_sponsor_id = "clinicaltrials_resource:" . md5($lead_sponsor->asXML());
             $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:lead-sponsor", $lead_sponsor_id));
             $this->AddRDF($this->QQuad($lead_sponsor_id, "rdf:type", "clinicaltrials_vocabulary:Lead-Sponsor"));
             $this->AddRDF($this->QQuadl($lead_sponsor_id, "dc:title", $this->SafeLiteral($agency)));
             $this->AddRDF($this->QQuadl($lead_sponsor_id, "rdfs:label", $this->SafeLiteral($agency) . " [{$lead_sponsor_id}]"));
             $this->AddRDF($this->QQuadl($lead_sponsor_id, "clinicaltrials_vocabulary:agency-class", $this->SafeLiteral($agency_class)));
         } catch (Exception $e) {
             echo "There was an error in the lead sponsor element: {$e}\n";
         }
         ######################################################################################
         #oversight info
         ######################################################################################
         try {
             $over_site = @array_shift($root->xpath('//oversight_info'));
             $authority = @array_shift($over_site->xpath('//authority'));
             $os_id = "clinicaltrials_resource:" . md5($over_site->asXML());
             $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:oversight-authority", $os_id));
             $this->AddRDF($this->QQuad($os_id, "rdf:type", "clinicaltrials_vocabulary:Oversight-Authority"));
             $this->AddRDF($this->QQuadl($os_id, "rdfs:label", $authority . " [{$os_id}]"));
             $this->AddRDF($this->QQuadl($os_id, "dc:title", $authority));
         } catch (Exception $e) {
             echo "There was an error in the oversight info element: {$e}\n";
         }
         ####################################################################################
         # has_dmc
         ####################################################################################
         $has_dmc = @array_shift($over_site->xpath('//has_dmc'));
         if ($has_dmc != "") {
             $this->AddRDF($this->QQuadl($os_id, "clinicaltrials_vocabulary:dmc", $has_dmc));
             // what's a dmc?
         }
         ###################################################################################
         #brief summary
         ###################################################################################
         $brief_summary = @array_shift($root->xpath('//brief_summary/textblock'));
         if ($brief_summary) {
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:brief-summary", $this->SafeLiteral($brief_summary)));
         }
         ####################################################################################
         # detailed description
         ####################################################################################
         $detailed_description = @array_shift($root->xpath('//detailed_description/textblock'));
         if ($detailed_description) {
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:detailed-description", $this->SafeLiteral($detailed_description)));
         }
         #################################################################################
         # overall status
         #################################################################################
         $overall_status = @array_shift($root->xpath('//overall_status'));
         if ($overall_status) {
             $status_id = "clinicaltrials_resource:" . md5($overall_status);
             $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:overall-status", $status_id));
             $this->AddRDF($this->QQuad($status_id, "rdf:type", "clinicaltrials_vocabulary:Status"));
             $this->AddRDF($this->QQuadL($status_id, "rdfs:label", $overall_status));
         }
         ##################################################################################
         # start date
         ##################################################################################
         $start_date = @array_shift($root->xpath('//start_date'));
         if ($start_date) {
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:start-date", $this->SafeLiteral($start_date)));
         }
         ###################################################################################
         # completion date
         ##################################################################################
         $completion_date = @array_shift($root->xpath('//completion_date'));
         if ($completion_date != "") {
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:completion-date", $this->SafeLiteral($completion_date)));
         }
         ####################################################################################
         # primary completion date
         ###################################################################################
         $primary_completion_date = @array_shift($root->xpath('//primary_completion_date'));
         if ($primary_completion_date != "") {
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:primary-completion-date", $this->SafeLiteral($primary_completion_date)));
         }
         ####################################################################################
         # study type
         ####################################################################################
         $study_type = @array_shift($root->xpath('//study_type'));
         if ($study_type != "") {
             $study_type_id = "clinicaltrials_resource:" . md5($study_type);
             $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:study-type", $study_type_id));
             $this->AddRDF($this->QQuad($study_type_id, "rdf:type", "clinicaltrials_vocabulary:Study-Type"));
             $this->AddRDF($this->QQuadL($study_type_id, "rdfs:label", $this->SafeLiteral($study_type) . " [{$study_type_id}]"));
         }
         ####################################################################################
         # phase
         ####################################################################################
         $phase = @array_shift($root->xpath('//phase'));
         if ($phase && $phase != "N/A") {
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:phase", $this->SafeLiteral($phase)));
         }
         ###############################################################################
         # study design
         ###############################################################################
         $study_design = @array_shift($root->xpath('//study_design'));
         if ($study_design) {
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:study-design", $this->SafeLiteral($study_design)));
         }
         ################################################################################
         #primary outcome
         ###############################################################################
         $primary_outcome = @array_shift($root->xpath('//primary_outcome'));
         if ($primary_outcome) {
             try {
                 $measure = @array_shift($root->xpath('//primary_outcome/measure'));
                 $time_frame = @array_shift($root->xpath('//primary_outcome/time_frame'));
                 $safety_issue = @array_shift($root->xpath('//primary_outcome/saftey_issue'));
                 $description = @array_shift($root->xpath('//primary_outcome/description'));
                 $po_id = "clinicaltrials_resource:" . md5($nct_id . $primary_outcome->asXML());
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:primary-outcome", $po_id));
                 $this->AddRDF($this->QQuad($po_id, "rdf:type", "clinicaltrials_vocabulary:Primary-Outcome"));
                 $this->AddRDF($this->QQuadl($po_id, "rdfs:label", $this->SafeLiteral($measure . " " . $time_frame) . " [{$po_id}]"));
                 $this->AddRDF($this->QQuadl($po_id, "clinicaltrials_vocabulary:measure", $this->SafeLiteral($measure)));
                 if ($description) {
                     $this->AddRDF($this->QQuadl($po_id, "dc:description", $this->SafeLiteral($description)));
                 }
                 if ($time_frame) {
                     $this->AddRDF($this->QQuadl($po_id, "clinicaltrials_vocabulary:time-frame", $this->SafeLiteral($time_frame)));
                 }
                 if ($safety_issue) {
                     $this->AddRDF($this->QQuadl($po_id, "clinicaltrials_vocabulary:safety-issue", $this->SafeLiteral($safety_issue)));
                 }
             } catch (Exception $e) {
                 echo "There was an error parsing the primary outcome element: {$e} \n";
             }
         }
         #################################################################################
         #secondary outcome
         #################################################################################
         try {
             $secondary_outcomes = $root->xpath('//secondary_outcome');
             foreach ($secondary_outcomes as $secondary_outcome) {
                 $measure = @array_shift($secondary_outcome->xpath('//measure'));
                 $time_frame = @array_shift($secondary_outcome->xpath('//time_frame'));
                 $safety_issue = @array_shift($secondary_outcome->xpath('//safety_issue'));
                 $so_id = "clinicaltrials_resource:" . md5($nct_id . $secondary_outcome->asXML());
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:secondary-outcome", $so_id));
                 $this->AddRDF($this->QQuad($so_id, "rdf:type", "clinicaltrials_vocabulary:Secondary-Outcome"));
                 $this->AddRDF($this->QQuadl($so_id, "rdfs:label", $this->SafeLiteral($measure . " " . $time_frame) . "[{$so_id}]"));
                 $this->AddRDF($this->QQuadl($so_id, "clinicaltrials_vocabulary:measure", $this->SafeLiteral($measure)));
                 if ($time_frame) {
                     $this->AddRDF($this->QQuadl($so_id, "clinicaltrials_vocabulary:time-frame", $this->SafeLiteral($time_frame)));
                 }
                 if ($safety_issue) {
                     $this->AddRDF($this->QQuadl($so_id, "clinicaltrials_vocabulary:safety-issue", $this->SafeLiteral($safety_issue)));
                 }
             }
         } catch (Exception $e) {
             "There was an exception parsing the secondary outcomes element: {$e}\n";
         }
         ##############################################################################
         #number of arms
         ##############################################################################
         try {
             $no_of_arms = @array_shift($root->xpath('//number_of_arms'));
             if ($no_of_arms != "") {
                 $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:number-of-arms", $no_of_arms));
             }
         } catch (Exception $e) {
             echo "There was an exception parsing the number of arms element: {$e}\n";
         }
         ##############################################################################
         #enrollment
         ##############################################################################
         try {
             $enrollment = @array_shift($root->xpath('//enrollment'));
             if ($enrollment) {
                 $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:enrollment", $this->SafeLiteral($enrollment)));
             }
         } catch (Exception $e) {
             echo "There was an exception parsing the enrollment element: {$e}\n";
         }
         ###############################################################################
         #condition
         ###############################################################################
         try {
             $conditions = $root->xpath('//condition');
             foreach ($conditions as $condition) {
                 $mesh_label_id = "clinicaltrials_resource:" . md5($this->SafeLiteral($condition));
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:condition", $mesh_label_id));
                 $this->AddRDF($this->QQuadl($mesh_label_id, "rdfs:label", $this->SafeLiteral($condition)));
             }
         } catch (Exception $e) {
             echo "There was an exception parsing condition element: {$e}\n";
         }
         ################################################################################
         # arm_group
         ################################################################################
         try {
             $arm_groups = $root->xpath('//arm_group');
             foreach ($arm_groups as $arm_group) {
                 $arm_group_label = @array_shift($arm_group->xpath('./arm_group_label'));
                 $arm_group_type = ucfirst(str_replace(" ", "_", @array_shift($arm_group->xpath('./arm_group_type'))));
                 $description = @array_shift($arm_group->xpath('./description'));
                 $arm_group_id = "clinicaltrials_resource:" . md5($arm_group->asXML());
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:arm-group", $arm_group_id));
                 $this->AddRDF($this->QQuadl($arm_group_id, "rdfs:label", $this->SafeLiteral($arm_group_label) . "[{$arm_group_id}]"));
                 $this->AddRDF($this->QQuad($arm_group_id, "rdf:type", "clinicaltrials_vocabulary:" . $arm_group_type));
                 $this->AddRDF($this->QQuadl($arm_group_id, "rdfs:comment", $this->SafeLiteral($description)));
             }
         } catch (Exception $e) {
             echo "There was an exception in arm groups: {$e}\n";
         }
         ##############################################################################
         #intervention
         ##############################################################################
         try {
             $interventions = $root->xpath('//intervention');
             foreach ($interventions as $intervention) {
                 $intervention_name = @array_shift($intervention->xpath('./intervention_name'));
                 $intervention_type = ucfirst(str_replace(" ", "_", @array_shift($intervention->xpath('./intervention_type'))));
                 $intervention_id = "clinicaltrials_resource:" . md5($intervention->asXML());
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:intervention", $intervention_id));
                 $this->AddRDF($this->QQuad($intervention_id, "rdf:type", "clinicaltrials_vocabulary:" . $intervention_type));
                 $this->AddRDF($this->QQuadl($intervention_id, "rdfs:label", $this->SafeLiteral($intervention_name)));
                 $description = @array_shift($intervention->xpath('./description'));
                 if ($description != "") {
                     $this->AddRDF($this->QQuadl($intervention_id, "rdfs:comment", $this->SafeLiteral($description)));
                 }
             }
         } catch (Exception $e) {
             echo "There was an error in interventions {$e}\n";
         }
         ###############################################################################
         #eligibility
         ################################################################################
         try {
             $eligibility = @array_shift($root->xpath('//eligibility'));
             if ($eligibility != null) {
                 $eligibility_id = "clinicaltrials_resource:" . md5($eligibility->asXML());
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:eligibility", $eligibility_id));
                 $this->AddRDF($this->QQuad($eligibility_id, "rdf:type", "clinicaltrials_vocabulary:Eligibility"));
                 if ($criteria = @array_shift($eligibility->xpath('./criteria'))) {
                     $text = str_replace("\n\n", "", @array_shift($criteria->xpath('./textblock')));
                     $c = preg_split("/(Inclusion Criteria\\:|Exclusion Criteria\\:)/", $text);
                     //inclusion
                     if (isset($c[1])) {
                         $d = explode(" - ", $c[1]);
                         // the lists are separated by a hyphen
                         foreach ($d as $inclusion) {
                             $inc = trim($inclusion);
                             if ($inc != '') {
                                 $inc_id = "clinicaltrials_resource:" . md5($inc);
                                 $this->AddRDF($this->QQuad($eligibility_id, "clinicaltrials_vocabulary:inclusion-criteria", $inc_id));
                                 $this->AddRDF($this->QQuad($inc_id, "rdf:type", "clinicaltrials_vocabulary:Inclusion-Criteria"));
                                 $this->AddRDF($this->QQuadL($inc_id, "rdfs:label", trim($this->SafeLiteral($inc))));
                             }
                         }
                     }
                     //exclusion
                     if (isset($c[2])) {
                         $d = explode(" - ", $c[1]);
                         foreach ($d as $exclusion) {
                             $exc = trim($exclusion);
                             if ($exc != '') {
                                 $exc_id = "clinicaltrials_resource:" . md5($exc);
                                 $this->AddRDF($this->QQuad($eligibility_id, "clinicaltrials_vocabulary:exclusion-criteria", $exc_id));
                                 $this->AddRDF($this->QQuad($exc_id, "rdf:type", "clinicaltrials_vocabulary:Exclusion-Criteria"));
                                 $this->AddRDF($this->QQuadL($exc_id, "rdfs:label", trim($this->SafeLiteral($exc))));
                             }
                         }
                     }
                 }
                 if ($gender = @array_shift($eligibility->xpath('./gender'))) {
                     $this->AddRDF($this->QQuadl($eligibility_id, "clinicaltrials_vocabulary:gender", $gender));
                 }
                 if ($minimum_age = @array_shift($eligibility->xpath('./minimum_age'))) {
                     if ($minimum_age != 'N/A') {
                         $this->AddRDF($this->QQuadL($eligibility_id, "clinicaltrials_vocabulary:minimum-age", trim(str_replace("Years", "", $minimum_age))));
                     }
                 }
                 if ($maximum_age = @array_shift($eligibility->xpath('./maximum_age'))) {
                     if ($maximum_age != 'N/A') {
                         $this->AddRDF($this->QQuadL($eligibility_id, "clinicaltrials_vocabulary:maximum-age", trim(str_replace("Years", "", $maximum_age))));
                     }
                 }
                 if ($healthy_volunteers = @array_shift($eligibility->xpath('./healthy_volunteers'))) {
                     $this->AddRDF($this->QQuadl($eligibility_id, "clinicaltrials_vocabulary:healthy-volunteers", $healthy_volunteers));
                 }
                 if ($study_pop = @array_shift($eligibility->xpath('./study_pop'))) {
                     $this->AddRDF($this->QQuadl($eligibility_id, "clinicaltrials_vocabulary:study-population", $study_pop->xpath('./textblock')));
                 }
                 if ($sampling_method = @array_shift($eligibility->xpath('./sampling_method'))) {
                     $this->AddRDF($this->QQuadl($eligibility_id, "clinicaltrials_vocabulary:sampling-method", $sampling_method->xpath('./textblock')));
                 }
             }
         } catch (Exception $e) {
             echo "There was an error in eligibility: {$e}\n";
         }
         ######################################################################################
         #overall official - the person in charge
         #####################################################################################
         try {
             $overall_official = @array_shift($root->xpath('//overall_official'));
             if ($overall_official) {
                 $overall_official = "clinicaltrials_resource:" . md5($overall_official->asXML());
                 $last_name = @array_shift($root->xpath('//overall_official/last_name'));
                 $role = @array_shift($root->xpath('//overall_official/role'));
                 $affiliation = @array_shift($root->xpath('//overall_official/affiliation'));
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:overall-official", $overall_official));
                 $this->AddRDF($this->QQuad($overall_official, "rdf:type", "clinicaltrials_vocabulary:Overall-Official"));
                 $this->AddRDF($this->QQuadl($overall_official, "clinicaltrials_vocabulary:lastname", $last_name));
                 $this->AddRDF($this->QQuadl($overall_official, "clinicaltrials_vocabulary:role", $role));
                 $this->AddRDF($this->QQuadl($overall_official, "clinicaltrials_vocabulary:affiliation", $this->SafeLiteral($affiliation)));
             }
         } catch (Exception $e) {
             echo "There was an error parsing the overal_official: {$e}\n";
         }
         ##############################################################
         # location of facility doing the testing
         ##############################################################
         try {
             $location = @array_shift($root->xpath('//location'));
             if ($location) {
                 $location_id = "clinicaltrials_resource:" . md5($location->asXML());
                 $title = @array_shift($location->xpath('//name'));
                 $facility = $location->xpath('./facility');
                 $address = @array_shift($location->xpath('//address'));
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:location", $location_id));
                 $this->AddRDF($this->QQuadl($location_id, "dc:title", $title));
                 $this->AddRDF($this->QQuadl($location_id, "rdfs:label", $title . " [{$location_id}]"));
                 $this->AddRDF($this->QQuad($location_id, "rdfs:type", "clinicaltrials_vocabulary:Location"));
                 if ($address && ($city = @array_shift($address->xpath('./city'))) != null) {
                     $this->AddRDF($this->QQuadl($location_id, "clinicaltrials_vocabulary:city", $city));
                 }
                 if ($address && ($state = @array_shift($address->xpath('./state'))) != null) {
                     $this->AddRDF($this->QQuadl($location_id, "clinicaltrials_vocabulary:state", $state));
                 }
                 if ($address && ($zip = @array_shift($address->xpath('./zip'))) != null) {
                     $this->AddRDF($this->QQuadl($location_id, "clinicaltrials_vocabulary:zipcode", $zip));
                 }
                 if ($address && ($country = @array_shift($address->xpath('./country'))) != null) {
                     $this->AddRDF($this->QQuadl($location_id, "clinicaltrials_vocabulary:country", $country));
                 }
             }
         } catch (Exception $e) {
             echo "There was an error parsing location: {$e}" . "\n";
         }
         ###################################################################
         # group
         ###################################################################
         try {
             $groups = $root->xpath('//group');
             foreach ($groups as $group) {
                 $group_id = "clinicaltrials_resource:" . md5($group->asXML());
                 $title = @array_shift($group->xpath('./title'));
                 $description = @array_shift($group->xpath('./description'));
                 $id = $group->attributes()->group_id;
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:group", $group_id));
                 $this->AddRDF($this->QQuad($group_id, "rdf:type", "clinicaltrials_vocabulary:Group"));
                 $this->AddRDF($this->QQuadl($group_id, "dc:title", $title));
                 $this->AddRDF($this->QQuadl($group_id, "rdfs:comment", $this->SafeLiteral($description)));
                 $this->AddRDF($this->QQuadl($group_id, "dc:identifier", $id));
             }
         } catch (Exception $e) {
             echo "There was an exception parsing groups xml element: {$e}\n";
         }
         ######################################################################
         #results reference
         ######################################################################
         try {
             $references = $root->xpath('//reference');
             foreach ($references as $reference) {
                 $p = @array_shift($reference->xpath('./PMID'));
                 if ($p) {
                     $pmid = "pubmed:{$p}";
                     $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:reference", $pmid));
                     $this->AddRDF($this->QQuadl($pmid, "rdfs:comment", $this->SafeLiteral(@array_shift($reference->xpath('./citation')))));
                 }
             }
         } catch (Exception $e) {
             echo "There was an error parsing references element: {$e}\n";
         }
         #######################################################################
         #results reference
         #######################################################################
         try {
             $results_references = $root->xpath('//results_reference');
             foreach ($results_references as $result_reference) {
                 $p = @array_shift($result_reference->xpath('./PMID'));
                 if ($p) {
                     $pmid = "pubmed:" . $p;
                     $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:results-reference", $pmid));
                     $this->AddRDF($this->QQuadl($pmid, "rdfs:comment", $this->SafeLiteral(@array_shift($result_reference->xpath('./citation')))));
                 }
             }
         } catch (Exception $e) {
             echo "There was an error parsing results_references element: {$e}\n";
         }
         ##########################################################################
         #verification date
         #########################################################################
         try {
             $verification_date = @array_shift($root->xpath('//verification_date'));
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:verification-date", $verification_date));
             $lastchanged_date = @array_shift($root->xpath('//lastchanged_date'));
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:last-changed-date", $lastchanged_date));
             $firstreceived_date = @array_shift($root->xpath('//firstreceived_date'));
             $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:first-received-date", $firstreceived_date));
         } catch (Exception $e) {
             echo "There was an error parsing the verification_date element: {$e}\n";
         }
         ############################################################################
         #responsible party
         ############################################################################
         try {
             $responsible_party = @array_shift($root->xpath('//responsible_party'));
             if ($responsible_party) {
                 $name_title = $root->xpath('//responsible_party/name_title');
                 $organization = $root->xpath('//responsible_party/organization');
                 $rp_id = "clinicaltrials_resource:" . md5($responsible_party->asXML());
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:responsible-party", $rp_id));
                 $this->AddRDF($this->QQuad($rp_id, "rdf:type", "clinicaltrials_vocabulary:Responsible-Party"));
                 $this->AddRDF($this->QQuadl($rp_id, "rdfs:label", "{$name_title}, {$organization} [{$rp_id}]"));
                 $this->AddRDF($this->QQuadl($rp_id, "clinicaltrials_vocabulary:name-title", $name_title));
                 $this->AddRDF($this->QQuadl($rp_id, "clinicaltrials_vocabulary:organization", $organization));
             }
         } catch (Exception $e) {
             echo "There was an error parsing the responsible_party element: {$e}\n";
         }
         ##############################################################################
         # key words
         ##############################################################################
         try {
             $keywords = $root->xpath('//keyword');
             foreach ($keywords as $keyword) {
                 $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:keyword", $keyword));
             }
         } catch (Exception $e) {
             echo "There was an error parsing the keywords element: {$e}";
         }
         # mesh terms
         # note: mesh terms are assigned using an imperfect algorithm
         try {
             $mesh_terms = $root->xpath('//condition_browse/mesh_term');
             foreach ($mesh_terms as $mesh_term) {
                 $mesh_id = "clinicaltrials_resource:" . md5($mesh_term);
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:condition-mesh", $mesh_id));
                 $this->AddRDF($this->QQuadl($mesh_id, "rdfs:label", $mesh_term));
             }
         } catch (Exception $e) {
             echo "There was an error in mesh_terms: {$e}\n";
         }
         ###############################################################################
         # mesh terms for hte invervention browse
         ###############################################################################
         try {
             $mesh_terms = $root->xpath('//intervention_browse/mesh_term');
             foreach ($mesh_terms as $mesh_label) {
                 $mesh_label_id = "clinicaltrials_resource:" . md5($mesh_label);
                 $this->AddRDF($this->QQuad($study_id, "clinicaltrials_vocabulary:intervention_mesh", $mesh_label_id));
                 $this->AddRDF($this->QQuadl($mesh_label_id, "rdfs:label", $this->SafeLiteral($mesh_label)));
             }
         } catch (Exception $e) {
             echo "There was an error parsing intervention_browse/mesh_term element: {$e}\n";
         }
         ################################################################################
         # regulated by fda?
         # boolean value yes or no
         ################################################################################
         try {
             $regulated = @array_shift($root->xpath('is_fda_regulated'));
             if ($regulated != "") {
                 $this->AddRDF($this->QQuadl($study_id, "clinicaltrials_vocabulary:is-fda-regulated", $regulated));
             }
         } catch (Excepetion $e) {
             echo "There was an error parsing the is_fda_regulated element: {$e}\n";
         }
         $this->WriteRDFBufferToWriteFile();
     }
     $this->getWriteFile()->close();
 }
Esempio n. 7
0
 /**
  *  parse an individual pubchem substance file
  **/
 function parse_substance_file($indir, $file)
 {
     $xml = new CXML($indir, $file);
     while ($xml->Parse("PC-Substance") == TRUE) {
         $this->parse_substance_record($xml);
         $this->WriteRDFBufferToWriteFile();
     }
 }
Esempio n. 8
0
 function parse_drugbank($ldir, $infile)
 {
     $xml = new CXML($ldir . $infile);
     while ($xml->parse("drug") == TRUE) {
         if (isset($this->id_list) and count($this->id_list) == 0) {
             break;
         }
         $this->parseDrugEntry($xml);
     }
     unset($xml);
 }
Esempio n. 9
0
 function genes($file)
 {
     $xml = new CXML($file);
     while ($xml->parse("DisorderList") == TRUE) {
         $x = $xml->GetXMLRoot();
         foreach ($x->Disorder as $d) {
             $orphanet_id = parent::getNamespace() . (string) $d->OrphaNumber;
             $disorder_name = (string) $d->Name;
             foreach ($d->DisorderGeneAssociationList->DisorderGeneAssociation as $dga) {
                 // gene
                 $gene = $dga->Gene;
                 $gene_id = parent::getNamespace() . (string) $gene->OrphaNumber;
                 $gene_internal_id = (string) $gene->attributes()->id;
                 $gene_label = (string) $gene->Name;
                 $gene_symbol = (string) $gene->Symbol;
                 parent::addRDF(parent::describeIndividual($gene_id, $gene_label, parent::getVoc() . "Gene") . parent::describeClass(parent::getVoc() . "Gene", "orphanet gene") . parent::triplifyString($gene_id, parent::getVoc() . "symbol", $gene_symbol));
                 foreach ($gene->SynonymList as $s) {
                     $synonym = (string) $s->Synonym;
                     parent::addRDF(parent::triplifyString($gene_id, parent::getVoc() . "synonym", $synonym));
                 }
                 foreach ($gene->ExternalReferenceList as $erl) {
                     $er = $erl->ExternalReference;
                     $db = (string) $er->Source;
                     $db = parent::getRegistry()->getPreferredPrefix($db);
                     $id = (string) $er->Reference;
                     $xref = "{$db}:{$id}";
                     parent::addRDF(parent::triplify($gene_id, parent::getVoc() . "x-{$db}", $xref));
                 }
                 $dga_id = parent::getRes() . (string) $d->OrphaNumber . "_" . md5($dga->asXML());
                 $ga = $dga->DisorderGeneAssociationType;
                 $ga_id = parent::getNamespace() . (string) $ga->attributes()->id;
                 $ga_label = (string) $ga->Name;
                 $s = $dga->DisorderGeneAssociationStatus;
                 $s_id = parent::getNamespace() . (string) $s->attributes()->id;
                 $s_label = (string) $s->Name;
                 parent::addRDF(parent::describeIndividual($dga_id, "{$ga_label} {$gene_label} in {$disorder_name} ({$s_label})", $ga_id) . parent::describeClass($ga_id, $ga_label, parent::getVoc() . "Disorder-Gene-Association") . parent::triplify($dga_id, parent::getVoc() . "status", $s_id) . parent::describeClass($s_id, $s_label, parent::getVoc() . "Disorder-Gene-Association-Status") . parent::triplify($dga_id, parent::getVoc() . "disorder", $orphanet_id) . parent::describeIndividual($orphanet_id, $disorder_name, parent::getVoc() . "Disorder") . parent::triplify($dga_id, parent::getVoc() . "gene", $gene_id));
             }
             parent::writeRDFBufferToWriteFile();
         }
     }
     unset($xml);
 }
Esempio n. 10
0
 function parse($file)
 {
     $xml = new CXML($file);
     $xml->parse();
     $entry = $xml->getXMLRoot();
     if (!isset($entry) or !$entry) {
         return false;
     }
     foreach ($entry->children() as $o) {
         $rsid = "rs" . $o->attributes()->rsId;
         $id = parent::getNamespace() . $rsid;
         $type = parent::getVoc() . ucfirst(str_replace(" ", "-", (string) $o->attributes()->snpClass));
         $snpclass = parent::getVoc() . (string) $o->attributes()->snpClass;
         $moltype = parent::getVoc() . (string) $o->attributes()->molType;
         // attributes
         parent::addRDF(parent::describeIndividual($id, $rsid, $type) . parent::describeClass($type, ucfirst("" . $o->attributes()->snpClass)) . parent::triplify($id, parent::getVoc() . "mol-type", $moltype) . parent::describeClass($moltype, (string) $o->attributes()->molType, parent::getVoc() . "Moltype") . parent::describeClass(parent::getVoc() . "Moltype", "Moltype") . parent::triplify($id, parent::getVoc() . "taxid", "taxonomy:" . (string) $o->attributes()->taxId));
         $genotype = (string) $o->attributes()->genoType;
         if ($genotype) {
             parent::addRDF(parent::triplifyString($id, parent::getVoc() . "genotype", parent::getVoc() . $genotype, "xsd:bool"));
         }
         // frequency
         // create/update
         /*			if(!isset($o->Update)) $a = $o->Create;
         			else $a = $o->Update;
         			parent::addRDF(parent::triplifyString($id,parent::getVoc()."build",(string) $a->attributes()->build));
         */
         //validation
         $a = $o->Validation;
         parent::addRDF(parent::triplifyString($id, parent::getVoc() . "validation-by-cluster", (string) $a->attributes()->byCluster) . parent::triplifyString($id, parent::getVoc() . "validation-by-frequency", (string) $a->attributes()->byFrequency) . parent::triplifyString($id, parent::getVoc() . "validation-by-2hit2allele", (string) $a->attributes()->by2Hit2Allele) . parent::triplifyString($id, parent::getVoc() . "validation-by-1000G", (string) $a->attributes()->by1000G));
         //hgvs names
         foreach ($o->hgvs as $name) {
             parent::addRDF(parent::triplifyString($id, parent::getVoc() . "hgvs-name", (string) $name));
         }
         // assembly
         $assembly = $o->Assembly;
         if ($assembly and $assembly->attributes()->reference == "true") {
             parent::addRDF(parent::triplifyString($id, parent::getVoc() . "dbsnp-build", (string) $assembly->attributes()->dbSnpBuild) . parent::triplifyString($id, parent::getVoc() . "genome-build", (string) $assembly->attributes()->genomeBuild));
             $component = $assembly->Component;
             if ($component) {
                 parent::addRDF(parent::triplify($id, parent::getVoc() . "contig-accession", "genbank:" . (string) $component->attributes()->accession) . parent::triplify($id, parent::getVoc() . "contig-gi", "gi:" . (string) $component->attributes()->gi) . parent::triplifyString($id, parent::getVoc() . "chromosome", (string) $component->attributes()->chromosome));
                 $maploc = $component->MapLoc;
                 if ($maploc) {
                     foreach ($maploc->children() as $fxnset) {
                         $fxnset_id = parent::getRes() . md5($fxnset->asXML());
                         parent::addRDF(parent::triplify($id, parent::getVoc() . "maps-to", $fxnset_id) . parent::triplify($fxnset_id, "rdf:type", parent::getVoc() . "Fxnset") . parent::describeClass(parent::getVoc() . "Fxnset", "Fxnset"));
                         if (isset($fxnset->attributes()->geneId)) {
                             parent::addRDF(parent::triplify($fxnset_id, parent::getVoc() . "gene", "ncbigene:" . (string) $fxnset->attributes()->geneId));
                         }
                         if (isset($fxnset->attributes()->symbol)) {
                             parent::addRDF(parent::triplifyString($fxnset_id, parent::getVoc() . "gene-symbol", (string) $fxnset->attributes()->symbol));
                         }
                         if (isset($fxnset->attributes()->mrnaAcc)) {
                             parent::addRDF(parent::triplify($fxnset_id, parent::getVoc() . "mrna", "refseq:" . (string) $fxnset->attributes()->mrnaAcc));
                         }
                         if (isset($fxnset->attributes()->protAcc)) {
                             parent::addRDF(parent::triplify($fxnset_id, parent::getVoc() . "protein", "refseq:" . (string) $fxnset->attributes()->protAcc));
                         }
                         if (isset($fxnset->attributes()->fxnClass)) {
                             parent::addRDF(parent::triplifyString($fxnset_id, parent::getVoc() . "fxn-class", (string) $fxnset->attributes()->fxnClass));
                         }
                         if (isset($fxnset->attributes()->allele)) {
                             parent::addRDF(parent::triplifyString($fxnset_id, parent::getVoc() . "allele", (string) $fxnset->attributes()->allele));
                         }
                         if (isset($fxnset->attributes()->residue)) {
                             parent::addRDF(parent::triplifyString($fxnset_id, parent::getVoc() . "residue", (string) $fxnset->attributes()->residue));
                         }
                         if (isset($fxnset->attributes()->readingFrame)) {
                             parent::addRDF(parent::triplifyString($fxnset_id, parent::getVoc() . "reading-frame", (string) $fxnset->attributes()->readingFrame));
                         }
                         if (isset($fxnset->attributes()->aaPosition)) {
                             parent::addRDF(parent::triplifyString($fxnset_id, parent::getVoc() . "position", (string) $fxnset->attributes()->aaPosition));
                         }
                     }
                 }
             }
         }
     }
     unset($xml);
 }