Page 1 of 1

problem with adding "File Annotation" to "Plate"

PostPosted: Wed May 29, 2013 1:29 pm
by yuriy_alexandrov
Dear All,

After updating to Omero 4.8.8 I found strange behavior with Matlab code that worked OK previously.

The test code below (almost ready for exec) is an attempt to create new Plate, which is Child of some Parent Screen, and then add File Annotation to this new plate (annotation file is the same Matlab "test.m" file).

The annotation is added, but newly created Plate is disconnected from its Parent Screen, and becomes standalone Plate as one can see in Insight.

Crucial are 4 last lines - if they aren't executed, the new Plate is created correctly, but annotation is certainly not added.

Best regards,
Y.

Code: Select all
        screenid = 52;
        plateid = 603;

       newplate = omero.model.PlateI();
        newplate.setName(omero.rtypes.rstring('jfgnjklsdfbajfhujawehlasjjkdnasfkljasdnfasjk'));   
        newplate = updateService.saveAndReturnObject(newplate);
        link = omero.model.ScreenPlateLinkI;
        link.setChild(newplate);           
        link.setParent(omero.model.ScreenI(screenid,false));           
        updateService.saveObject(link);                                                     

        namespace = 'gkgkgiuyiuoiupj';
        description = ' ';           
        sha1 = char('pending');
        file_mime_type = char('application/octet-stream');
        root = pwd;
        full_file_name = [root filesep 'test.m'];
        %
        updateService = session.getUpdateService();
        %
        file = java.io.File(full_file_name);
        name = file.getName();
        absolutePath = file.getAbsolutePath();
        path = absolutePath.substring(0, absolutePath.length()-name.length());
        %
        originalFile = omero.model.OriginalFileI;
        originalFile.setName(omero.rtypes.rstring(name));
        originalFile.setPath(omero.rtypes.rstring(path));
        originalFile.setSize(omero.rtypes.rlong(file.length()));
        originalFile.setSha1(omero.rtypes.rstring(sha1));
        originalFile.setMimetype(omero.rtypes.rstring(file_mime_type));
        %       
        originalFile = updateService.saveAndReturnObject(originalFile);       
        % Initialize the service to load the raw data
        rawFileStore = session.createRawFileStore();
        rawFileStore.setFileId(originalFile.getId().getValue());       
        % open file and read it - code for small file.
        L = file.length();
        fid = fopen(full_file_name,'r');   
            byteArray = fread(fid,L,'uint8');
        fclose(fid);
                               
        rawFileStore.write(byteArray, 0, L);       
        originalFile = rawFileStore.save();               
        % Important to close the service
        rawFileStore.close();
        %
        % now we have an original File in DB and raw data uploaded.
        % We now need to link the Original file to the image using the File annotation object. That's the way to do it.
        fa = omero.model.FileAnnotationI;
        fa.setFile(originalFile);
        fa.setDescription(omero.rtypes.rstring(description)); % The description set above e.g. PointsModel
        fa.setNs(omero.rtypes.rstring(namespace)) % The name space you have set to identify the file annotation.
        % save the file annotation.
        fa = updateService.saveAndReturnObject(fa);
        %     
        link = omero.model.PlateAnnotationLinkI;                                       
        link.setChild(fa);
        link.setParent(newplate);
        % save the link back to the server.
        updateService.saveAndReturnObject(link);

Re: problem with adding "File Annotation" to "Plate"

PostPosted: Thu May 30, 2013 7:57 am
by jburel
Hi Yuriy

The problem is due to the fact the newPlate object is not loaded so
the link to the screen will be removed when you save the annotation.
In order to avoid the issue, you can do, for example, when you create the annotation


Code: Select all
        % save the file annotation.
        fa = updateService.saveAndReturnObject(fa);
        %     
        link = omero.model.PlateAnnotationLinkI;                                       
        link.setChild(fa);
        %link.setParent(newplate);
        link.setParent(omero.model.PlateI(newplate.getId().getValue(),false))
        % save the link back to the server.
        updateService.saveAndReturnObject(link);



Jmarie

Re: problem with adding "File Annotation" to "Plate"

PostPosted: Thu May 30, 2013 10:05 am
by yuriy_alexandrov
Many thanks Jmarie, that solved the problem.

All the best,
Y.