Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
f8347135
Commit
f8347135
authored
14 years ago
by
tpylak
Browse files
Options
Downloads
Patches
Plain Diff
LMS-2147 example program for Sanofi to fetch images with the API
SVN: 20511
parent
86b05df4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/LoadImagesScreeningClientApiTest.java
+150
-0
150 additions, 0 deletions
...ening/client/api/v1/LoadImagesScreeningClientApiTest.java
with
150 additions
and
0 deletions
screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/LoadImagesScreeningClientApiTest.java
0 → 100644
+
150
−
0
View file @
f8347135
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
ch.systemsx.cisd.openbis.plugin.screening.client.api.v1
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Properties
;
import
org.apache.log4j.PropertyConfigurator
;
import
ch.systemsx.cisd.openbis.plugin.screening.client.api.v1.ScreeningOpenbisServiceFacade.IImageOutputStreamProvider
;
import
ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageDatasetReference
;
import
ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.PlateIdentifier
;
import
ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.PlateImageReference
;
import
ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.WellPosition
;
/**
* A test class which shows how to use API to load images.
*
* @author Tomasz Pylak
*/
public
class
LoadImagesScreeningClientApiTest
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
if
(
args
.
length
!=
3
)
{
System
.
err
.
println
(
"Usage: <user> <password> <openbis-server-url>"
);
System
.
err
.
println
(
"Example parameters: test-user my-password http://localhost:8888"
);
System
.
exit
(
1
);
return
;
}
configureLogging
();
String
userId
=
args
[
0
];
String
userPassword
=
args
[
1
];
String
serverUrl
=
args
[
2
];
print
(
String
.
format
(
"Connecting to the server '%s' as a user '%s."
,
serverUrl
,
userId
));
IScreeningOpenbisServiceFacade
facade
=
ScreeningOpenbisServiceFacadeFactory
.
tryCreate
(
userId
,
userPassword
,
serverUrl
);
if
(
facade
==
null
)
{
System
.
err
.
println
(
"Authentication failed: check the user name and password."
);
System
.
exit
(
1
);
return
;
}
// Another way: PlateIdentifier.createFromAugmentedCode("/SPACE_CODE/MY_PLATE_CODE")
// PlateIdentifier plate = new PlateIdentifier("MY_PLATE_CODE", "SPACE_CODE", null);
PlateIdentifier
plate
=
new
PlateIdentifier
(
"PLATE-2-A"
,
"TEST"
,
null
);
List
<
ImageDatasetReference
>
imageDatasets
=
facade
.
listRawImageDatasets
(
Arrays
.
asList
(
plate
));
if
(
imageDatasets
.
size
()
==
0
)
{
System
.
err
.
println
(
"No image datasets connected to plate "
+
plate
);
System
.
exit
(
1
);
}
// take the first image dataset
ImageDatasetReference
imageDataset
=
imageDatasets
.
get
(
0
);
// You could get to know more about the image dataset metadata with:
// facade.listImageMetadata(imageDataset);
// Here we will make some assumptions.
// Note: first tile has number 0
int
tile
=
0
;
String
channel
=
"DAPI"
;
// Note: first well 1 has coordinates (1,1)
int
row
=
1
;
int
column
=
3
;
WellPosition
well
=
new
WellPosition
(
row
,
column
);
PlateImageReference
imageRef
=
new
PlateImageReference
(
tile
,
channel
,
well
,
imageDataset
);
loadImage
(
facade
,
imageRef
);
facade
.
logout
();
}
private
static
File
createImageFile
(
PlateImageReference
imageRef
)
{
File
dir
=
new
File
(
imageRef
.
getDatasetCode
());
dir
.
mkdir
();
return
new
File
(
dir
,
createImageFileName
(
imageRef
));
}
/**
* @throws IOException when reading images from the server or writing them to the files fails
*/
private
static
void
loadImage
(
IScreeningOpenbisServiceFacade
facade
,
PlateImageReference
imageReference
)
throws
IOException
{
File
imageOutputFile
=
createImageFile
(
imageReference
);
final
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
imageOutputFile
));
try
{
facade
.
loadImages
(
Arrays
.
asList
(
imageReference
),
new
IImageOutputStreamProvider
()
{
public
OutputStream
getOutputStream
(
PlateImageReference
imageRef
)
throws
IOException
{
return
out
;
}
});
}
finally
{
out
.
close
();
}
}
private
static
void
print
(
String
msg
)
{
System
.
out
.
println
(
new
Date
()
+
"\t"
+
msg
);
}
private
static
String
createImageFileName
(
PlateImageReference
image
)
{
WellPosition
well
=
image
.
getWellPosition
();
return
"img_row"
+
well
.
getWellRow
()
+
"_col"
+
well
.
getWellColumn
()
+
"_"
+
image
.
getChannel
()
+
"_tile"
+
image
.
getTile
()
+
".png"
;
}
private
static
void
configureLogging
()
{
Properties
props
=
new
Properties
();
props
.
put
(
"log4j.appender.STDOUT"
,
"org.apache.log4j.ConsoleAppender"
);
props
.
put
(
"log4j.appender.STDOUT.layout"
,
"org.apache.log4j.PatternLayout"
);
props
.
put
(
"log4j.appender.STDOUT.layout.ConversionPattern"
,
"%d %-5p [%t] %c - %m%n"
);
props
.
put
(
"log4j.rootLogger"
,
"INFO, STDOUT"
);
PropertyConfigurator
.
configure
(
props
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment