add smid dump script.
[SMMID.git] / script / import_images.pl
blobd2a8db67abc318d2321fb2bb32bdf0fe91caeb0a
2 use strict;
4 use Getopt::Std;
5 use Data::Dumper;
6 use File::Basename;
7 use SMMID::Image;
8 use SMIDDB;
10 our ($opt_H, $opt_D, $opt_p);
11 getopts('H:D:p:');
13 my $image_source_dir = shift;
15 my $schema = SMIDDB->connect("dbi:Pg:dbname=$opt_D;host=$opt_H;user=postgres;password=$opt_p");
17 my @images = glob("$image_source_dir/*");
19 print STDERR Dumper(\@images);
21 foreach my $file (@images) {
22 my $image = SMMID::Image->new( { schema => $schema, image_dir => '/home/production/smmid_images/' });
24 my $name = basename($file);
25 $image->name($file);
26 $image->description("This image represents the structure of the smid $name");
27 $image->copyright("This image may be subject to copryight. Please contact the submitter for copyright information.");
28 $image->dbuser_id(1);
29 $image->process_image($file);
32 my $compound_name = $name;
33 $compound_name =~ s/\.png//g;
35 print STDERR "Compound name = $compound_name\n";
37 my $row = $schema->resultset("SMIDDB::Result::Compound")->find( { smid_id => $compound_name });
39 if (! $row) {
40 print STDERR "Compound $compound_name not found... Skipping.\n";
41 next();
44 my $link_row = $schema->resultset("SMIDDB::Result::CompoundImage")->create(
46 compound_id => $row->compound_id(),
47 image_id => $image->image_id(),
48 });