Perl Items API

In the intermine/perl directory we provide a Perl library for creating files in InterMine “Item XML” format. Files in this format can be loaded into an InterMine database by creating a “source”.


Most code using these modules will follow this pattern:

Make a model

my $model = InterMine::Model->new(file => $model_file);

Make a new InterMine item XML document:

my $document = InterMine::Item::Document->new(
  model  => $model,
  output => $out_file,

Make an item:

my $gene = $factory->make_item("Gene");

Set some attributes

$gene->set(identifier => "CG10811");

or references:

my $org = $factory->make_item("Organism");
$org->set(taxonId => 7227);
$gene->set(organism => $org);

or collections:

$gene->set(transcripts => [$transcript1, $transcript2]);

It is also possible to combine creation and attribute setting in one command:

my $gene = $factory->make_item(
  identifier  => 'CG10811',
  organism    => $org,
  transcripts => [$transcript1, $transcript2],

Repeat 4 as necessary then call $document->write to write the items to the output.

FlyMine example

Example using the FlyMine model:

use InterMine::Model;
use InterMine::Item::Document;

my $model_file = $ARGV[0] or die;

my $model   = InterMine::Model->new(file => $model_file);
my $document = InterMine::Item::Document->new(model => $model);

my $organism = $document->add_item(
    taxonId => 7227,

my $pub1 = $document->add_item(
    pubMedId => 11700288,
my $pub2 = $document->add_item(
    pubMedId => 16496002,

my $gene = $document->add_item(
    identifier   => "CG10811",
    organism     => $organism,
    publications => [$pub1, $pub2]

# write as InterMine Items XML


   <item id="0_4" class="" implements="Gene">
      <attribute name="identifier" value="CG10811" />
      <collection name="publications">
         <reference ref_id="0_2" />
         <reference ref_id="0_3" />
      <reference name="organism" ref_id="0_1" />
   <item id="0_1" class="" implements="Organism">
      <attribute name="taxonId" value="7227" />
   <item id="0_2" class="" implements="Publication">
      <attribute name="pubMedId" value="11700288" />
   <item id="0_3" class="" implements="Publication">
      <attribute name="pubMedId" value="16496002" />


In the InterMine scripts repository there is a longer example:

The script has three arguments:
  • a string describing a DataSet
  • a taxon id
  • the path to a genomic model file

If you install XML::Writer, the script should run as:

Example command line: .. code-block:: perl

./ “FlyMine” 5833 flymine/dbmodel/resources/main/genomic_model.xml