[ome-devel] Struggling with augmented XML output from OME

Graham Klyne graham.klyne at zoo.ox.ac.uk
Tue Sep 20 16:32:12 BST 2005


[Resend, my last attempt was bounced from OME-devel]

Josiah,

Per request, here's my question resubmitted to OME-devel.  Also with the
complete modified source file attached (which I did previously intend to
provide, but forgot).

...

Following recent messages, I've made my attempt to obtain augmented XML
output from OME, but so far I'm hitting a brick wall.

Here's what I did so far:

(1) edited /usr/lib/perl5/site_perl/5.8.5/OME/Web/DefaultMenuBuilkder.pm
to contain this:
[[
	# ** Images **
	{
		web_class => 'OME::Web::XMLFileExport',
		type => 'link',
		text => undef,
	},
	{
		web_class => 'OME::Web::XMLFileExportDTGED',
		type => 'link',
		text => undef,
	},
]]


(2) created
/usr/lib/perl5/site_perl/5.8.5/OME/Web/XMLFileExportDTGED.pm, based on
XMLFileExport.pm, but with changes noted below.  The modifed file is
attached.


(3) Created /OME/html/Templates/XMLFileExportDTGED.tmpl from
/OME/html/Templates/XMLFileExport.tmpl, thus:
[[
[root at helenome src]# diff /OME/html/Templates/XMLFileExportDTGED.tmpl
/OME/html/Templates/XMLFileExport.tmpl
7c7
< <h2>Export Images to OME XML with DTGED data</h2>
---
> <h2>Export Images to OME XML</h2>
]]

...

The new left-menu entry is displayed as expected, and it does indeed
invoke the new code.  But whatever changes I make to the new function
exportDTGEDToXMLFile, the result of exporting DTGED file data is exactly
the same as fromn performing a normal export ofnthe same file.

I have ensured that the new function is actually being called (by
inserting a die clause in the new routine, and observing the system
error displayed when attempting to export DTGED data).

I have also tried removing the line:
    push(@exportObjects,$image) ; # Add the image
so I can get the metadata without image data, but still no change in the
result data.

I can't find any place other than that I've replaced where function
exportToXMLFile is called.

So, as far as I can tell, I am doing all the appropriate things, but
whatever changes I make to the new export function, the output I get
sent back to my browser is unchanged.

Any pointers, please?

#g
--

Changes to XMLFileExportDTGED.pm w.r.t. XMLFileExport.pm:
[[
[root at helenome src]# diff
/usr/lib/perl5/site_perl/5.8.5/OME/Web/XMLFileExportDTGED.pm
/usr/lib/perl5/site_perl/5.8.5/OME/Web/XMLFileExport.pm
1c1
< # OME/Web/XMLFileExportDTGED.pm
---
> # OME/Web/XMLFileExport.pm
38c38
< package OME::Web::XMLFileExportDTGED ;
---
> package OME::Web::XMLFileExport ;
54c54
<       return "Open Microscopy Environment - Export OME XML + DTGED data" ;
---
>       return "Open Microscopy Environment - Export OME XML to browser" ;
58,59c58
<         ###CHANGED:
<       my $menu_text = "Export debug DTGED Image(s)";
---
>       my $menu_text = "Export Image(s)";
95,97c94,95
<                       ###CHANGED:
<                       my $exporter=
OME::Web::XMLFileExportDTGED->new($session);
<                       $exporter->exportDTGEDToXMLFile(\@images,$filename);
---
>                       my $exporter=
OME::Tasks::OMEXMLImportExport->new($session);
>                       $exporter->exportToXMLFile(\@images,$filename);
121,122c119
<         ###CHANGED:
<       my $tmpl = HTML::Template->new( filename =>
'XMLFileExportDTGED.tmpl', path => $tmpl_dir );
---
>       my $tmpl = HTML::Template->new( filename =>
'XMLFileExport.tmpl', path => $tmpl_dir );
130,131c127
<               ###CHANGED:
<               $cgi->startform( -action => $self->pageURL(
'OME::Web::XMLFileExportDTGED' ) ).
---
>               $cgi->startform( -action => $self->pageURL(
'OME::Web::XMLFileExport' ) ).
139,201d134
<
< #####################################################
< # 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 exportDTGEDToXMLFile {
<
<       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();
<         ###NEW:
<       my $annotation_module   =
$session->Configuration()->annotation_module();
<       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...
<               # 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();
<               ###NEW:
<               my @dtged_outputs   = $dtged_MEX->untypedOutputs();
<               ###CHANGED:
< ###           foreach my $output
(@outputs, at untyped_outputs, at dtged_outputs) {
<               foreach my $output (@untyped_outputs, at dtged_outputs) {
<                       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 ;
< }
<
]]

-- 
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


-------------- next part --------------
# 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 + DTGED data" ;
}

{
        ###CHANGED:
	my $menu_text = "Export debug DTGED 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) {
		        ###CHANGED:
			my $exporter= OME::Web::XMLFileExportDTGED->new($session);
			$exporter->exportDTGEDToXMLFile(\@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();
        ###CHANGED:
	my $tmpl = HTML::Template->new( filename => 'XMLFileExportDTGED.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 .= 
	        ###CHANGED:
		$cgi->startform( -action => $self->pageURL( 'OME::Web::XMLFileExportDTGED' ) ).
		$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 exportDTGEDToXMLFile {

	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();
        ###NEW:
	my $annotation_module   = $session->Configuration()->annotation_module();
	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...
		# 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();
	        ###NEW:
		my @dtged_outputs   = $dtged_MEX->untypedOutputs();
	        ###CHANGED:
###		foreach my $output (@outputs, at untyped_outputs, at dtged_outputs) {
		foreach my $output (@untyped_outputs, at dtged_outputs) {
			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;



More information about the ome-devel mailing list