| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | # every perl script should start with these two lines. |
|---|
| 4 | use strict; |
|---|
| 5 | use warnings; |
|---|
| 6 | |
|---|
| 7 | use InterMine::Item::Document; |
|---|
| 8 | use InterMine::Model; |
|---|
| 9 | |
|---|
| 10 | if (@ARGV < 3) { |
|---|
| 11 | die "usage: $0 data_source taxon_id model_file [files...]\n"; |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | my ($data_source, $taxon_id, $model_file, @files) = @ARGV; |
|---|
| 15 | |
|---|
| 16 | my $model = new InterMine::Model(file => $model_file); |
|---|
| 17 | my $doc = new InterMine::Item::Document(model => $model); |
|---|
| 18 | |
|---|
| 19 | my $org_item = make_item( |
|---|
| 20 | Organism => ( |
|---|
| 21 | taxonId => $taxon_id, |
|---|
| 22 | ) |
|---|
| 23 | ); |
|---|
| 24 | my $data_source_item = make_item( |
|---|
| 25 | DataSource => ( |
|---|
| 26 | name => $data_source, |
|---|
| 27 | ), |
|---|
| 28 | ); |
|---|
| 29 | |
|---|
| 30 | my $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 |
|---|
| 37 | my $protein1_item = make_item( |
|---|
| 38 | Protein => ( |
|---|
| 39 | primaryAccession => 'Q8I5D2', |
|---|
| 40 | ), |
|---|
| 41 | ); |
|---|
| 42 | |
|---|
| 43 | my $protein2_item = make_item( |
|---|
| 44 | Protein => ( |
|---|
| 45 | primaryAccession => 'Q8I4X0', |
|---|
| 46 | ), |
|---|
| 47 | ); |
|---|
| 48 | |
|---|
| 49 | my $gene1_item = make_item( |
|---|
| 50 | Gene => ( |
|---|
| 51 | primaryIdentifier => 'gene 1', |
|---|
| 52 | ), |
|---|
| 53 | ); |
|---|
| 54 | my $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 | |
|---|
| 63 | my @pubmed_ids = (12368864, 16248207); |
|---|
| 64 | my @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 |
|---|
| 70 | exit(0); |
|---|
| 71 | |
|---|
| 72 | ######### helper subroutines: |
|---|
| 73 | |
|---|
| 74 | sub 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 | } |
|---|