Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. % init (Move this file into the OMERO.matlab toolbox)
  2. clear all;close all;
  3.  
  4. % import classes
  5. import java.io.File;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.util.ArrayList;
  9. import java.util.Iterator;
  10. import java.util.List;
  11.  
  12. import omero.sys.ParametersI;
  13. import omero.api.RawFileStorePrxHelper;
  14. import omero.api.RawFileStorePrx;
  15.  
  16. % create connection
  17. client = loadOmero(); %edit ice.config to update login credentials in the matlab toolbox
  18. session = client.createSession();
  19. omeroKeepAlive(client)
  20.  
  21. % plate id to download
  22. plateId = 2285;
  23. % target path for saving the images
  24. targetPath = '/Users/bramalingam/Downloads/OMERO.matlab-5.3.3-ice36-b63/testDownload';
  25.  
  26. % load all wells in a plate
  27. wellList = session.getQueryService().findAllByQuery(...
  28. ['select well from Well as well '...
  29. 'left outer join fetch well.plate as pt '...
  30. 'left outer join fetch well.wellSamples as ws '...
  31. 'left outer join fetch ws.plateAcquisition as pa '...
  32. 'left outer join fetch ws.image as img '...
  33. 'left outer join fetch img.pixels as pix '...
  34. 'left outer join fetch pix.pixelsType as pt '...
  35. 'where well.plate.id = ', num2str(plateId)], []);
  36.  
  37. % get fileset associated with the well
  38. values = ArrayList();
  39. for j = 0
  40. well = wellList.get(j);
  41. wellsSampleList = well.copyWellSamples();
  42.  
  43. for i = 0:wellsSampleList.size()-1
  44. ws = wellsSampleList.get(i);
  45.  
  46. image = ws.getImage();
  47. param = ParametersI();
  48.  
  49. l = ArrayList();
  50. l.add(image.getId);
  51. param.add("imageIds", omero.rtypes.rlist(l));
  52.  
  53. filesets = session.getQueryService().findAllByQuery(...
  54. ['select fs from Fileset as fs '...
  55. 'join fetch fs.images as image '...
  56. 'left outer join fetch fs.usedFiles as usedFile '...
  57. 'join fetch usedFile.originalFile as f '...
  58. 'join fetch f.hasher '...
  59. 'where image.id in (:imageIds)'], param);
  60.  
  61. % values.addAll(filesets);
  62. fi = filesets.iterator();
  63. cntr = 0;
  64. while (fi.hasNext)
  65. set = fi.next();
  66. entries = set.copyUsedFiles();
  67. fj = entries.iterator();
  68. while (fj.hasNext())
  69. fs = fj.next();
  70. origfile = fs.getOriginalFile();
  71. values.add(origfile);
  72. disp([i j origfile.getId().getValue()])
  73. cntr = cntr + 1;
  74. end
  75. end
  76. end
  77. end
  78.  
  79. % download original files
  80. i = values.iterator();
  81. name = omero.constants.RAWFILESTORE.value;
  82. files = ArrayList();
  83. INC = 262144;
  84. offset = 0;
  85. while i.hasNext()
  86. of = i.next;
  87. store = session.createRawFileStore();
  88. disp(of.getId().getValue());
  89. store.setFileId(of.getId().getValue());
  90.  
  91. f = File(targetPath, of.getName().getValue);
  92. files.add(f)
  93.  
  94. stream = FileOutputStream(f);
  95. size = of.getSize().getValue();
  96. try
  97. for offset = 0:(offset+INC < size)
  98. stream.write(store.read(offset, INC));
  99. offset = offset + INC;
  100. end
  101. catch
  102. stream = FileOutputStream(f);
  103. stream.write(store.read(offset, int16(size - offset)));
  104. end
  105.  
  106. stream.close();
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement