Skip to content

Instantly share code, notes, and snippets.

@dbolser-ebi
Created September 21, 2018 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbolser-ebi/1890e35cb6d1366544e1346666cfe6f5 to your computer and use it in GitHub Desktop.
Save dbolser-ebi/1890e35cb6d1366544e1346666cfe6f5 to your computer and use it in GitHub Desktop.
Plant Reactome BioMart Perl API script for Justin
# An example script demonstrating the use of BioMart API.
# This perl API representation is only available for configuration versions >= 0.5
use strict;
use BioMart::Initializer;
use BioMart::Query;
use BioMart::QueryRunner;
my $confFile = "../conf/martURLLocation.xml";
my $species = shift || "bnapus";
print STDERR "The other species is $species\n";
#
# NB: change action to 'clean' if you wish to start a fresh configuration
# and to 'cached' if you want to skip configuration step on subsequent runs from the same registry
#
my $action='clean';
#my $action='cached';
my $initializer = BioMart::Initializer->new('registryFile'=>$confFile, 'action'=>$action);
my $registry = $initializer->getRegistry;
my $query = BioMart::Query->new('registry'=>$registry,'virtualSchemaName'=>'default');
$query->setDataset("osativa_eg_gene");
$query->addAttribute("ensembl_gene_id");
$query->addAttribute("${species}_eg_homolog_ensembl_gene");
$query->addAttribute("${species}_eg_homolog_perc_id");
$query->addAttribute("${species}_eg_homolog_perc_id_r1");
$query->addAttribute("${species}_eg_homolog_orthology_confidence");
$query->formatter("TSV");
my $query_runner = BioMart::QueryRunner->new();
############################## GET COUNT ############################
# $query->count(1);
# $query_runner->execute($query);
# print $query_runner->getCount();
#####################################################################
############################## GET RESULTS ##########################
# to obtain unique rows only
# $query_runner->uniqueRowsOnly(1);
$query_runner->execute($query);
$query_runner->printHeader();
$query_runner->printResults();
$query_runner->printFooter();
#####################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment