Skip to content

Commit 490fc6d

Browse files
Merge pull request #286 from micheldumontier/ct_onefile
Ct onefile fix
2 parents 68f7111 + 3818beb commit 490fc6d

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

clinicaltrials/clinicaltrials.php

+34-33
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,20 @@ function parse_dir(){
166166
$indir = parent::getParameterValue('indir');
167167
if($handle = opendir($indir)) {
168168
echo "Processing directory $indir\n";
169+
170+
$outfile = "clinicaltrials.".parent::getParameterValue('output_format');
171+
$gz = (strstr(parent::getParameterValue('output_format'),".gz") === FALSE)?false:true;
172+
parent::setWriteFile(parent::getParameterValue("outdir").$outfile,$gz);
173+
169174
while(($file = readdir($handle)) !== false){
170175
if (in_array($file,$ignore) || is_dir($file) ) continue;
171176
$trial_id = basename($file,'.xml');
172177
if(parent::getParameterValue('id_list') == '' || in_array($trial_id, $ids)) {
173178
echo "Processing $file".PHP_EOL;
174179
$this->process_file($file);
175-
176-
$outfile = basename($file,".xml").'.'.parent::getParameterValue('output_format');
177-
180+
178181
// make the dataset description
179-
$ouri = parent::getGraphURI(parent::getDatasetURI());
182+
$ouri = parent::getGraphURI();
180183
parent::setGraphURI(parent::getDatasetURI());
181184

182185
$rfile = "http://clinicaltrials.gov/ct2/show/".$trial_id."?resultsxml=true";
@@ -194,31 +197,34 @@ function parse_dir(){
194197
->setLicense("http://clinicaltrials.gov/ct2/about-site/terms-conditions")
195198
->setDataset("http://identifiers.org/clinicaltrials/");
196199

197-
$output_file = (new DataResource($this))
198-
->setURI("http://download.bio2df.org/release/$bVersion/$prefix/$outfile")
199-
->setTitle("Bio2RDF v$bVersion RDF version of $prefix v$source_version")
200-
->setSource($source_file->getURI())
201-
->setCreator("https://github.com/bio2rdf/bio2rdf-scripts/blob/master/clinicaltrials/clinicaltrials.php")
202-
->setCreateDate($date)
203-
->setHomepage("http://download.bio2rdf.org/release/$bVersion/$prefix/$prefix.html")
204-
->setPublisher("http://bio2rdf.org")
205-
->setRights("use-share-modify")
206-
->setRights("by-attribution")
207-
->setRights("restricted-by-source-license")
208-
->setLicense("http://creativecommons.org/licenses/by/3.0/")
209-
->setDataset(parent::getDatasetURI());
210-
211-
$gz = (strstr(parent::getParameterValue('output_format'),".gz") === FALSE)?false:true;
212-
if($gz) $output_file->setFormat("application/gzip");
213-
if(strstr(parent::getParameterValue('output_format'),"nt")) $output_file->setFormat("application/n-triples");
214-
else $output_file->setFormat("application/n-quads");
215-
216-
fwrite($fp, $source_file->toRDF().$output_file->toRDF());
217-
parent::setGraphURI(parent::setDatasetURI($ouri));
200+
parent::writeToReleaseFile($source_file->toRDF());
201+
parent::setGraphURI($ouri);
218202
}
219203
}
220-
echo "Finished\n.";
204+
echo "Finished.".PHP_EOL;
221205
closedir($handle);
206+
207+
$output_file = (new DataResource($this))
208+
->setURI("http://download.bio2df.org/release/$bVersion/$prefix/$outfile")
209+
->setTitle("Bio2RDF v$bVersion RDF version of $prefix v$source_version")
210+
->setSource($source_file->getURI())
211+
->setCreator("https://github.com/bio2rdf/bio2rdf-scripts/blob/master/clinicaltrials/clinicaltrials.php")
212+
->setCreateDate($date)
213+
->setHomepage("http://download.bio2rdf.org/release/$bVersion/$prefix/$prefix.html")
214+
->setPublisher("http://bio2rdf.org")
215+
->setRights("use-share-modify")
216+
->setRights("by-attribution")
217+
->setRights("restricted-by-source-license")
218+
->setLicense("http://creativecommons.org/licenses/by/3.0/")
219+
->setDataset(parent::getDatasetURI());
220+
221+
$gz = (strstr(parent::getParameterValue('output_format'),".gz") === FALSE)?false:true;
222+
if($gz) $output_file->setFormat("application/gzip");
223+
if(strstr(parent::getParameterValue('output_format'),"nt")) $output_file->setFormat("application/n-triples");
224+
else $output_file->setFormat("application/n-quads");
225+
226+
parent::writeToReleaseFile($output_file->toRDF());
227+
parent::closeReleaseFile();
222228

223229
// write the dataset description file
224230
fclose($fp);
@@ -230,12 +236,7 @@ function parse_dir(){
230236
**/
231237
function process_file($infile) {
232238
$indir = parent::getParameterValue('indir');
233-
$outfile = parent::getParameterValue("outdir")
234-
.basename($infile,".xml")
235-
.'.'.parent::getParameterValue('output_format');
236-
$gz = (strstr(parent::getParameterValue('output_format'),".gz") === FALSE)?false:true;
237-
238-
$this->setWriteFile($outfile,$gz);
239+
239240
$xml = new CXML($indir,basename($infile));
240241
$this->setCheckPoint('file');
241242
while($xml->Parse("clinical_study") == TRUE) {
@@ -924,10 +925,10 @@ function process_file($infile) {
924925
echo "There was an error parsing the is_fda_regulated element: $e\n";
925926
}
926927

928+
parent::writeRDFBufferToWriteFile();
927929
}
928930
$this->setCheckPoint('record');
929931
$this->setCheckPoint('dataset');
930-
$this->getWriteFile()->close();
931932
}
932933

933934
function getString($xpath,$element = null)

0 commit comments

Comments
 (0)