- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Annotate instrument information on image. #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
f2d07d0
              1d3725f
              4e75248
              a6c7766
              fda00f6
              5091e7f
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -20,6 +20,11 @@ | |
| import java.util.concurrent.ExecutionException; | ||
| import java.util.stream.Collectors; | ||
| import javax.imageio.ImageIO; | ||
| import life.qbic.datamodel.dtos.imaging.Instrument; | ||
| import life.qbic.datamodel.dtos.imaging.Location; | ||
| import life.qbic.datamodel.dtos.imaging.parameters.ImagingHardware; | ||
| import life.qbic.datamodel.people.Address; | ||
| import ome.model.annotations.MapAnnotation; | ||
| import omero.ServerError; | ||
| import omero.api.ExporterPrx; | ||
| import omero.api.RawFileStorePrx; | ||
| 
          
            
          
           | 
    @@ -966,6 +971,86 @@ public ByteArrayInputStream getThumbnail(long datasetId, long imageId) { | |
| 
     | 
||
| } | ||
| 
     | 
||
| /** | ||
| * Associates instrument metadata with an existing image in the OMERO server. | ||
| * @param instrument containing information to be associated with the image | ||
| * @param imageId ID of the image that will be annotated | ||
| */ | ||
| public void associateInstrumentWithImage(Instrument instrument, Long imageId) { | ||
| if (!isConnected()) { | ||
| this.connect(); | ||
| } | ||
| // 1. Check if an image with the id is in OMERO. Throw a runtime exception if not | ||
| ImageData imageData; | ||
| try { | ||
| BrowseFacility browseFacility = gateway.getFacility(BrowseFacility.class); | ||
| imageData = browseFacility.getImage(securityContext, imageId); | ||
| } catch (DSOutOfServiceException dsOutOfServiceException) { | ||
| throw new RuntimeException("Error while accessing omero service: broken connection, expired session or not logged in", dsOutOfServiceException); | ||
                
      
                  KochTobi marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| } catch (ExecutionException executionException) { | ||
| throw new RuntimeException("Task aborted unexpectedly.", executionException); | ||
                
      
                  KochTobi marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| } catch (DSAccessException dsAccessException) { | ||
| throw new RuntimeException("Could not pull data from the omero server.", dsAccessException); | ||
| } | ||
| 
     | 
||
| if (imageData == null) { | ||
| throw new IllegalArgumentException("No image available with image id " + imageId); | ||
| } | ||
| // 2. Use the instrument metadata and store them accordingly next to the image in OMERO. | ||
| List<NamedValue> mapAnnotationContent = new ArrayList<>(); | ||
| ImagingHardware instrumentHardware = instrument.getHardware(); | ||
| Location instrumentLocation = instrument.getLocation(); | ||
| Address instrumentLocationAddress = instrumentLocation.getAddress(); | ||
| try { | ||
| mapAnnotationContent.add(new NamedValue("hardware.detector.type", instrumentHardware.getDetector().getType())); | ||
| } catch (NullPointerException ignored) {} | ||
| try { | ||
| mapAnnotationContent.add(new NamedValue("hardware.objective", instrumentHardware.getObjective())); | ||
| } catch (NullPointerException ignored) {} | ||
| try { | ||
| mapAnnotationContent.add(new NamedValue("manufacturer", instrument.getManufacturer())); | ||
| } catch (NullPointerException ignored) {} | ||
| try { | ||
| mapAnnotationContent.add(new NamedValue("location.address.affiliation", instrumentLocationAddress.getAffiliation())); | ||
| } catch (NullPointerException ignored) {} | ||
| try { | ||
| mapAnnotationContent.add(new NamedValue("location.address.country", instrumentLocationAddress.getCountry())); | ||
| } catch (NullPointerException ignored) {} | ||
| try { | ||
| mapAnnotationContent.add(new NamedValue("location.address.street", instrumentLocationAddress.getStreet())); | ||
| } catch (NullPointerException ignored) {} | ||
| try { | ||
| mapAnnotationContent.add(new NamedValue("location.address.zipCode", instrumentLocationAddress.getZipCode().toString())); | ||
| } catch (NullPointerException ignored) {} | ||
| try { | ||
| mapAnnotationContent.add(new NamedValue("location.roomId", instrumentLocation.getRoomId())); | ||
| } catch (NullPointerException ignored) {} | ||
| 
         
      Comment on lines
    
      +1004
     to 
      +1027
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: the underlying problem is, that the instrument properties can be null. So lets make sure they are never null, but empty Strings, Lists or empty objects. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to be addressed in the instrument constructor then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created an issue in the data-model-lib qbicsoftware/data-model-lib#55  | 
||
| try { | ||
| mapAnnotationContent.add(new NamedValue("model", instrument.getModel())); | ||
| } catch (NullPointerException ignored) {} | ||
| try { | ||
| mapAnnotationContent.add(new NamedValue("serialNumber", instrument.getSerialNumber())); | ||
| } catch (NullPointerException ignored) {} | ||
| try { | ||
| mapAnnotationContent.add(new NamedValue("type", instrument.getType())); | ||
| } catch (NullPointerException ignored) {} | ||
| 
     | 
||
| MapAnnotationData annotationData = new MapAnnotationData(); | ||
| annotationData.setContent(mapAnnotationContent); | ||
| annotationData.setDescription("Instrument"); | ||
| 
     | 
||
| try { | ||
| DataManagerFacility dataManagerFacility = gateway.getFacility(DataManagerFacility.class); | ||
| dataManagerFacility.attachAnnotation(securityContext, annotationData, imageData); | ||
| } catch (DSOutOfServiceException | ExecutionException | DSAccessException e) { | ||
| // Throw a runtime exception if anything goes wrong during this process | ||
| throw new RuntimeException("Could not annotate instrument metadata.", e); | ||
| } | ||
| // 3. Enjoy coding! | ||
| // YAY! | ||
                
      
                  KochTobi marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| } | ||
| 
     | 
||
| 
     | 
||
| /** | ||
| * The destructor has to make sure to disconnect from the OMERO server and close the session. | ||
| * @throws Throwable | ||
| 
          
            
          
           | 
    ||
Uh oh!
There was an error while loading. Please reload this page.