[ome-users] Custom annotations absent in exported metadata
Josiah Johnston
siah at nih.gov
Fri Sep 16 23:35:45 BST 2005
On Sep 15, 2005, at 10:57 AM, Graham Klyne wrote:
> Ilya,
>
> After a long break and many distractions, I'm back to figuring out how
> to export new Semantic Type annotations on the OME/XML file...
>
> Ilya Goldberg wrote:
>> The best place to start is definitely the current XML Export module:
>> src/perl2/OME/Web/XMLFileExport.pm
>> The entire web UI is done using sub-classes of OME::Web (in
>> src/perl2/OME/Web.pm and the src/perl2/OME/Web/ directory tree)
>> I would follow the same inheritance pattern and simply make a new
>> class similar to XMLFileExport - there's really no point to
>> subclassing this since its just an HTML interface for
>> src/perl2/OME/Tasks/OMEXMLImportExport.pm. This
>> OME::Tasks::OMEXMLImportExport class performs the logic of gathering
>> the objects to export. The export itself is performed by
>> OME::Tasks::OMEExport, which is the generalized exporter.
>> Since OMEXMLImportExport.pm just gathers objects and calls
>> OME::Tasks::OMEExport, the thing to do is copy the
>> OMEXMLImportExport->exportToXMLFile() method to your new class and
>> modify it to look for additional objects using a OME::Factory call
>> documented here:
>> http://openmicroscopy.org/APIdocs/OME/Factory.html
>
> Thanks.
>
> I've made a start on this, but I'm familiar with neither Perl coding
> nor
> the internal architecture details of OME. Here's my first attempt at
> an
> extended export function: does it look reasonable as far as it goes?
> Am I overlooking any key logic?
It looks fairly reasonable. You did a good job adapting existing code.
>
> (The next here has got some rather ugly line-wrapping; I also attach a
> copy of the source file I'm tinkering with.)
>
> <SNIP>
>
> As coded, I'm thinking this will add the untyped outputs of all
> annotation module executions to the XML output. Is this close?
Right on!
> If so,
> how can I refine it to select just the "DTGEDImageAnnotation" values?
> (This a detail I can't discern from
> http://openmicroscopy.org/APIdocs/OME/Factory.html.)
How are you making DTGEDImageAnnotation's? Using "Create a custom
annotation link of [-- Select a Semantic Type --]" in image detail?
Using a custom category group annotation template?
The good answer is to make DTGEDImageAnnotation use a different module.
Then instead of searching with the "Image Annotation" module (which
pulls up all kinds of stuff), you would search with the "DTGED Image
Annotation" module. You can find a module from its name with
my $module = $factory->findObject( "OME::Module", name => "DTGED Image
Annotation" );
The paranoid error check is
die "There are more than one modules named 'DTGED Image Annotation'"
if( $factory->countObject( "OME::Module", name => "Your module name"
) > 1 );
> Am I correct that the expression
> (@outputs, at untyped_outputs, at dtged_outputs) "flattens" the content of
> three lists into a single list?
You got it.
>
> If the new export function is about right, I guess I also need to
> modify the new module's getPageBody function to reference
> OME::Web::XMLFileExportDTGED->new($session) instead of
> OME::Tasks::OMEXMLImportExport->new($session).
Nope. The exporter managerial class (OMEXMLImportExport) is the same
for everything that wants to export.
>
> What does the "1;" at the end of the Perl module file do?
It lets modules return "true". I normally think of it as obscure syntax
that gets copied and pasted in when I write a new package. The
punchline is a package will compile without it, but anything that tries
to use the package will crash and burn.
>
> #g
>
> --
> Graham Klyne
> Image Bioinformatics Research Group (http://www.bioimage.org/)
> Department of Zoology, University of Oxford
> South Parks Road, Oxford OX1 3PS, UK
> E-mail: <Graham.Klyne at zoo.ox.ac.uk>
> Direct phone: +44-(0)1865-281991
> Departmental fax: +44-(0)1865-310447
>
> # OME/Web/XMLFileExportDTGED.pm
>
> #----------------------------------------------------------------------
> ---------
> #
> # Copyright (C) 2003 Open Microscopy Environment
> # Massachusetts Institute of Technology,
> # National Institutes of Health,
> # University of Dundee
> #
> #
> #
> # This library is free software; you can redistribute it and/or
> # modify it under the terms of the GNU Lesser General Public
> # License as published by the Free Software Foundation; either
> # version 2.1 of the License, or (at your option) any later version.
> #
> # This library is distributed in the hope that it will be useful,
> # but WITHOUT ANY WARRANTY; without even the implied warranty of
> # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> # Lesser General Public License for more details.
> #
> # You should have received a copy of the GNU Lesser General Public
> # License along with this library; if not, write to the Free
> Software
> # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> 02111-1307 USA
> #
> #----------------------------------------------------------------------
> ---------
>
>
>
>
> #----------------------------------------------------------------------
> ---------
> #
> # Written by: Ilya G. Goldberg <igg at nih.gov> (based on Jean-Marie
> Burel <j.burel at dundee.ac.uk>)
> #
> #----------------------------------------------------------------------
> ---------
>
>
> package OME::Web::XMLFileExportDTGED ;
>
> use strict;
> use vars qw($VERSION);
> use OME;
> $VERSION = $OME::VERSION;
> use CGI;
> use OME::Web::DBObjTable;
> use OME::Tasks::OMEXMLImportExport;
> use OME::Tasks::ImageManager;
> use OME::Tasks::PixelsManager;
>
> use base qw(OME::Web);
>
>
> sub getPageTitle {
> return "Open Microscopy Environment - Export OME XML to browser" ;
> }
>
> {
> my $menu_text = "Export Image(s)";
>
> sub getMenuText { return $menu_text }
> }
>
> sub getPageBody {
> my $self = shift;
> my $cgi = $self->CGI();
> my $session = $self->Session();
> my $factory = $session->Factory();
>
> my $action = $cgi->param('action');
> my $image_ids = $cgi->param('images_to_export');
> my @images;
> my $body;
> my $approximate_file_size;
> foreach my $image_id ( split( m',', $image_ids ) ) {
> my $image = $factory->loadObject( 'OME::Image', $image_id )
> or die "Couldn't load image id='$image_id'";
> push @images, $image;
> foreach my $pixels ( $image->pixels() ) {
> my ($bytesPerPixel, $isSigned, $isFloat) =
> OME::Tasks::PixelsManager->getPixelTypeInfo( $pixels->PixelType()
> );
> # size = bytesPerPixel * NumPixels * typical compression of 2/3's
> $approximate_file_size += $bytesPerPixel * $pixels->SizeX *
> $pixels->SizeY *
> $pixels->SizeZ * $pixels->SizeC * $pixels->SizeT * 2 / 3;
> }
> }
> $approximate_file_size /= 1048576;
> $approximate_file_size = sprintf( '%.2f', $approximate_file_size);
>
> if ( $action eq 'Export'){
> my $filename = $session->getTemporaryFilename('XMLFileExport','ome')
> or die "OME::Web::XMLFileExport could not obtain temporary
> filename\n";
>
> if (@images) {
> ### my $exporter= OME::Tasks::OMEXMLImportExport->new($session);
> my $exporter= OME::Web::XMLFileExportDTGED->new($session);
> $exporter->exportToXMLFile(\@images,$filename);
>
> my $downloadFilename = $cgi->param( 'filename' );
> if( not defined $downloadFilename || $downloadFilename eq '' ) {
> if (scalar @images > 1) {
> $downloadFilename = $session->dataset()->name();
> } else {
> $downloadFilename = $images[0]->name();
> }
> }
> $downloadFilename =~ s/(\.ome)?$/\.ome/;
>
> $self->contentType('application/ome+xml');
> return ('FILE',{
> filename => $filename,
> temp => 1,
> downloadFilename => $downloadFilename}) ;
> } else {
> $body .= $cgi->p({class => 'ome_error'}, 'No image(s) selected.
> Please try again.');
> }
> }
>
> $self->contentType('text/html');
> my $tmpl_dir = $self->Session()->Configuration()->template_dir();
> my $tmpl = HTML::Template->new( filename => 'XMLFileExport.tmpl',
> path => $tmpl_dir );
> if( @images ) {
> $tmpl->param( selected_images => $self->Renderer()->renderArray(
> \@images, 'ref_mass', { type => 'OME::Image' } ) );
> $tmpl->param( file_size => $approximate_file_size.' MB' );
> $tmpl->param( size_warning => $approximate_file_size.' MB' )
> if( $approximate_file_size >= 500 );
> }
> $body .=
> $cgi->startform( -action => $self->pageURL(
> 'OME::Web::XMLFileExport' ) ).
> $tmpl->output().
> $cgi->hidden( -name => 'images_to_export' ).
> $cgi->endform();
>
> return ('HTML',$body);
> }
>
>
> #####################################################
> # For each given image, exports all attributes from the
> # image import MEX to the specified XML file.
> # export($images,$file)
> # $images a ref to an array containing the image objects
> # $file MUST be absolute (path+name)
>
> sub exportToXMLFile {
>
> my ($self, $images, $file) = @_ ;
> my $session = OME::Session->instance();
> my $factory = $session->Factory() ;
>
> # To-do check if can write in file
> my $exporter = OME::Tasks::OMEExport->new( session => $session ) ;
> my @exportObjects = () ;
> my $image_import_module =
> $session->Configuration()->image_import_module();
> my $annotation_module =
> $session->Configuration()->annotation_module(); ###new
> my @outputs = $image_import_module->outputs();
> foreach my $image (@$images) {
> push(@exportObjects,$image) ; # Add the image
>
> # Get the import mex for this image
> my $import_MEX = $factory->findObject ("OME::ModuleExecution",
> image_id => $image->id(),
> module => $image_import_module,
> );
>
> ### New code ###
>
> # Get the DTGED annotation mex for this image
> my $dtged_MEX = $factory->findObject ("OME::ModuleExecution",
> image_id => $image->id(),
> module => $annotation_module
> );
> ### I guess this selects all annotations for the image;
> ### how do I restrict additional results to those with Untyped
> Oputput
> ### of the form/semantic type defined as "DTGEDImageAnnotation" ?
>
> ###
>
> # Collect all the attributes produced by the import MEX
> my @untyped_outputs = $import_MEX->untypedOutputs();
> my @dtged_outputs = $dtged_MEX->untypedOutputs(); ### New
> foreach my $output (@outputs, at untyped_outputs, at dtged_outputs) { ###
> Changed
> my $ST = $output->semantic_type();
> next unless $ST; # Skip the untyped output itself
>
> # Get the output's attributes, and push them on the list
> my $attributes = OME::Tasks::ModuleExecutionManager->
> getAttributesForMEX($import_MEX,$ST);
> push(@exportObjects,@$attributes);
> }
>
> }
> $exporter->buildDOM(\@exportObjects, ResolveAllRefs => 1, ExportSTDs
> => 0) ;
> $exporter->exportFile($file);
> return ;
> }
>
> 1;
> _______________________________________________
> ome-users mailing list
> ome-users at lists.openmicroscopy.org.uk
> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-users
More information about the ome-users
mailing list