Last active
June 29, 2017 09:52
-
-
Save joshmoore/de806492566889dd36e35f37d4d41fde to your computer and use it in GitHub Desktop.
IDR Matlab Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% init (Move this file into the OMERO.matlab toolbox) | |
clear all;close all; | |
% import classes | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
import java.util.List; | |
import omero.sys.ParametersI; | |
import omero.api.RawFileStorePrxHelper; | |
import omero.api.RawFileStorePrx; | |
% create connection | |
client = loadOmero(); %edit ice.config to update login credentials in the matlab toolbox | |
session = client.createSession(); | |
omeroKeepAlive(client) | |
% plate id to download | |
plateId = 4403; | |
% target path for saving the images | |
targetPath = '/Users/bramalingam/Downloads/OMERO.matlab-5.3.3-ice36-b63/testDownload'; | |
% load all wells in a plate | |
wellList = session.getQueryService().findAllByQuery(... | |
['select well from Well as well '... | |
'left outer join fetch well.plate as pt '... | |
'left outer join fetch well.wellSamples as ws '... | |
'left outer join fetch ws.plateAcquisition as pa '... | |
'left outer join fetch ws.image as img '... | |
'left outer join fetch img.pixels as pix '... | |
'left outer join fetch pix.pixelsType as pt '... | |
'where well.plate.id = ', num2str(plateId)], []); | |
% get fileset associated with the well | |
values = ArrayList(); | |
for j = 0 | |
well = wellList.get(j); | |
wellsSampleList = well.copyWellSamples(); | |
for i = 0:wellsSampleList.size()-1 | |
ws = wellsSampleList.get(i); | |
image = ws.getImage(); | |
param = ParametersI(); | |
l = ArrayList(); | |
l.add(image.getId); | |
param.add("imageIds", omero.rtypes.rlist(l)); | |
filesets = session.getQueryService().findAllByQuery(... | |
['select fs from Fileset as fs '... | |
'join fetch fs.images as image '... | |
'left outer join fetch fs.usedFiles as usedFile '... | |
'join fetch usedFile.originalFile as f '... | |
'join fetch f.hasher '... | |
'where image.id in (:imageIds)'], param); | |
% values.addAll(filesets); | |
fi = filesets.iterator(); | |
cntr = 0; | |
while (fi.hasNext) | |
set = fi.next(); | |
entries = set.copyUsedFiles(); | |
fj = entries.iterator(); | |
while (fj.hasNext()) | |
fs = fj.next(); | |
origfile = fs.getOriginalFile(); | |
values.add(origfile); | |
disp([i j origfile.getId().getValue()]) | |
cntr = cntr + 1; | |
end | |
end | |
end | |
end | |
% download original files | |
i = values.iterator(); | |
name = omero.constants.RAWFILESTORE.value; | |
files = ArrayList(); | |
INC = 262144; | |
offset = 0; | |
while i.hasNext() | |
of = i.next; | |
store = session.createRawFileStore(); | |
disp(of.getId().getValue()); | |
store.setFileId(of.getId().getValue()); | |
f = File(targetPath, of.getName().getValue); | |
files.add(f) | |
stream = FileOutputStream(f); | |
size = of.getSize().getValue(); | |
try | |
for offset = 0:(offset+INC < size) | |
stream.write(store.read(offset, INC)); | |
offset = offset + INC; | |
end | |
catch | |
stream = FileOutputStream(f); | |
stream.write(store.read(offset, int16(size - offset))); | |
end | |
stream.close(); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment