Skip to content

Developing a Bio2RDF parser

David Ponce edited this page Mar 22, 2019 · 4 revisions

BoilerPlate

The code below is the boiler plate for writing a script under the new Bio2RDF api.

<?php
class NameOfSript extends Bio2RDFizer
{
  function __construct($argv) {
    parent::__construct($argv,"nameofscript");
    // parameters are added like so
    parent::addParameter('param',true,null,'all','');  // parameter name, required, not really sure, default value
    parent:: initialize();
   }

  // set up the script. set the in directory and out directory etc
  function Run(){
   // whatever you do to run the code
   $this->parse();
   return true;
  }
   // do what needs to be done to parse the data
  function parse(){
  }
}
$a = new BioRDFApp($argv);
?>

Once you get the boiler plate copied its time to start the setup. This means getting and setting in and out directories and files to read and write too.

Getting a parameter:

$param = parent::getParameterValue('parameter');

Setting a read file:

$file = parent::setReadFile('filename');

Setting the file to write the triples to:

$outfile = parent::setWriteFile("path to file",true|false); here the boolean is to set if the flag will be compressed or not

Common Patterns

Below are some common patterns for doing the basic tasks of setting up a script, downloading files, parsing a file type, and annotating records.

Generating the Release file

$desc = $this->getBio2RDFDatasetDescription(
       $this->getNamespace(),
       "https://github.com/bio2rdf/bio2rdf-scripts/blob/master/affymetrix/affymetrix.php", 
       $bio2rdf_download_files,
       "http://affymetrix.com/",
       array("use-share-modify","no-commercial"),
       null, // license
       parent::getParameterValue('download_url'),
       parent::getDatasetVersion()
     );

$this->setWriteFile($odir.$this->getBio2RDFReleaseFile($this->getNamespace()));
     $this->getWriteFile()->write($desc);
     $this->getWriteFile()->close();

Next, checkout the RDFization Guide