Skip to content

Commit

Permalink
Bugfix: Rewrote as parser function instead of tag function. Now works…
Browse files Browse the repository at this point in the history
… with SMW facts
  • Loading branch information
samuell committed Mar 25, 2014
1 parent 779b6ab commit b681cab
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 18 deletions.
7 changes: 7 additions & 0 deletions GeneIdConvert.i18n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

$magicWords = array();

$magicWords['en'] = array(
'geneidconv' => array( 0, 'geneidconv' ),
);
62 changes: 48 additions & 14 deletions GeneIdConvert.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
/**
* Simple MediaWiki extension that converts from Ensembl Gene ID to
* desired target gene ID type, by using the CrossRef endpoint of the
Expand All @@ -21,7 +21,7 @@
*
* Example usage of the extension within a MediaWiki article:
*
* <geneidconv to="EntrezGene">ENSG00000157764</gene>
* {{ #geneidconv: ENSG00000157764 | EntrezGene }}
*
* A few of the avaible options for the "to" parameter, is (as of
* writing this):
Expand All @@ -37,30 +37,65 @@
*
*/

$wgHooks['ParserFirstCallInit'][] = 'wfGeneIdConvertParserInit';
// Take credit for your work.
$wgExtensionCredits['parserhook'][] = array(

// The full path and filename of the file. This allows MediaWiki
// to display the Subversion revision number on Special:Version.
'path' => __FILE__,

// The name of the extension, which will appear on Special:Version.
'name' => 'Gene ID Convert',

// A description of the extension, which will appear on Special:Version.
'description' => 'Simple MediaWiki extension that converts from Ensembl Gene ID to desired target gene ID type',

// Alternatively, you can specify a message key for the description.
// 'descriptionmsg' => 'exampleextension-desc',

// The version of the extension, which will appear on Special:Version.
// This can be a number or a string.
'version' => 1,

// Your name, which will appear on Special:Version.
'author' => 'Samuel Lampa',

// The URL to a wiki page/web page with information about the extension,
// which will appear on Special:Version.
'url' => 'https://www.mediawiki.org/wiki/Manual:Parser_functions',

);

// Specify the function that will initialize the parser function.
$wgHooks['ParserFirstCallInit'][] = 'GeneIdConvertSetupParserFunction';

// Allow translation of the parser function name
$wgExtensionMessagesFiles['GeneIdConvert'] = __DIR__ . '/GeneIdConvert.i18n.php';

// Hook our callback function into the parser
function wfGeneIdConvertParserInit( Parser $parser ) {
function GeneIdConvertSetupParserFunction( &$parser ) {
// When the parser sees the <geneidconv> tag, it executes
$parser->setHook( 'geneidconv', 'wfGeneIdConvRender' );
$parser->setFunctionHook( 'geneidconv', 'GeneIdConvertRenderParserFunction' );
// Always return true from this function. The return value does not denote
// success or otherwise have meaning - it just must always be true.
return true;
}

// Execute
function wfGeneIdConvRender( $srcGeneId, array $args, Parser $parser, PPFrame $frame ) {
// function geneIDConvert( $srcGeneId, array $args, Parser $parser, PPFrame $frame ) {
function GeneIdConvertRenderParserFunction( $parser, $srcGeneId = '', $toFormat = '' ) {

if ( $srcGeneId === '' ) {
return 'ERROR:Field_1_gene_id_missing';
}
if ( $toFormat === '' ) {
return 'ERROR:Field_2_target_format_missing';
}
// Disable cache, at least for debugging purposes
$parser->disableCache();

// Parse any wiki text in the content of the tag:
$srcGeneId = $parser->recursiveTagParse( $srcGeneId, $frame );

// Set some variables
$ensemblRestBaseUrl = "http://beta.rest.ensembl.org/xrefs/id"; // Without trailing slash
$targetId = "";
$toFormat = $args['to'];
$targetId = '';

// Construct the Query URL
$queryUrl = $ensemblRestBaseUrl . '/' . $srcGeneId . '?content-type=application/json';
Expand All @@ -87,8 +122,7 @@ function wfGeneIdConvRender( $srcGeneId, array $args, Parser $parser, PPFrame $f
} else {
$targetId = 'N/A';
}
// echo "TargetId: [$targetId]";
return (string)$targetId;
return $targetId;
}

function wfGetRemoteData( $url ) {
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ desired target gene ID type, by using the CrossRef endpoint of the
new Ensembl REST API.

Author: Samuel Lampa - samuel.lampa@gmail.com
Date: 2013-05-31
Created Date: 2013-05-31

More info on the REST API Here:

Expand All @@ -24,11 +24,14 @@ require_once("$IP/extensions/GeneIdConvert/GeneIdConvert.php");
- Example usage of the extension within a MediaWiki article:

````
<geneidconv to="EntrezGene">ENSG00000157764</gene>
{{ #geneidconv: ENSG00000157764 | EntrezGene }}
````

A few of the avaible options for the "to" parameter, is (as of
writing this):
... where the first field is the source ID (in Ensembl ID format)
and the second field is the target id type.

A few of the avaible options for the "to" parameter, is (as of
writing this) are the following:

- OTTG
- ArrayExpress
Expand Down

0 comments on commit b681cab

Please sign in to comment.