source: trunk/bio/scripts/intermine_items_example.pl @ 23479

Revision 23479, 1.7 KB checked in by alex, 16 months ago (diff)

Updated scripts to function with InterMine::Item::Document

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3# every perl script should start with these two lines.
4use strict;
5use warnings;
6
7use InterMine::Item::Document;
8use InterMine::Model;
9
10if (@ARGV < 3) {
11  die "usage: $0 data_source taxon_id model_file [files...]\n";
12}
13
14my ($data_source, $taxon_id, $model_file, @files) = @ARGV;
15
16my $model = new InterMine::Model(file => $model_file);
17my $doc = new InterMine::Item::Document(model => $model);
18
19my $org_item = make_item(
20    Organism => (
21        taxonId => $taxon_id,
22    )
23);
24my $data_source_item = make_item(
25    DataSource => (
26        name => $data_source,
27    ),
28);
29
30my $data_set_item = make_item(
31    DataSet => (
32        name => "$data_source data set taxon id: $taxon_id",
33    ),
34);
35
36# make a protein and add two publications to its publications collection
37my $protein1_item = make_item(
38    Protein => (
39        primaryAccession => 'Q8I5D2',
40    ),
41);
42
43my $protein2_item = make_item(
44    Protein => (
45        primaryAccession => 'Q8I4X0',
46    ),
47);
48
49my $gene1_item = make_item(
50    Gene => (
51        primaryIdentifier => 'gene 1',
52    ),
53);
54my $gene2_item = make_item(
55    Gene => (
56        primaryIdentifier => 'gene 2',
57    ),
58);
59
60$protein1_item->set(genes => [$gene1_item, $gene2_item]);
61$protein2_item->set(genes => [$gene1_item, $gene2_item]);
62
63my @pubmed_ids = (12368864, 16248207);
64my @pubs = map {make_item(Publication => (pubMedId => $_))} @pubmed_ids;
65
66# set a collection - no reverse reference
67$protein1_item->set(publications => \@pubs);
68
69$doc->close(); # writes the xml
70exit(0);
71
72######### helper subroutines:
73
74sub make_item {
75    my @args = @_;
76    my $item = $doc->add_item(@args);
77    if ($item->valid_field('organism')) {
78        $item->set(organism => $org_item);
79    }
80    return $item;
81}
Note: See TracBrowser for help on using the repository browser.