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
fce3d680
Commit
fce3d680
authored
8 years ago
by
Swen Vermeul
Browse files
Options
Downloads
Patches
Plain Diff
added sample_types
parent
14a86895
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
src/python/PyBis/pybis/pybis.py
+53
-62
53 additions, 62 deletions
src/python/PyBis/pybis/pybis.py
with
53 additions
and
62 deletions
src/python/PyBis/pybis/pybis.py
+
53
−
62
View file @
fce3d680
...
@@ -34,6 +34,7 @@ search_for_type = {
...
@@ -34,6 +34,7 @@ search_for_type = {
"
project
"
:
"
as.dto.project.search.ProjectSearchCriteria
"
,
"
project
"
:
"
as.dto.project.search.ProjectSearchCriteria
"
,
"
experiment
"
:
"
as.dto.experiment.search.ExperimentSearchCriteria
"
,
"
experiment
"
:
"
as.dto.experiment.search.ExperimentSearchCriteria
"
,
"
code
"
:
"
as.dto.common.search.CodeSearchCriteria
"
,
"
code
"
:
"
as.dto.common.search.CodeSearchCriteria
"
,
"
sample_type
"
:
"
as.dto.sample.search.SampleTypeSearchCriteria
"
,
}
}
...
@@ -48,6 +49,16 @@ def extract_identifier(ident):
...
@@ -48,6 +49,16 @@ def extract_identifier(ident):
return
str
(
ident
)
return
str
(
ident
)
return
ident
[
'
identifier
'
]
return
ident
[
'
identifier
'
]
def
extract_permid
(
permid
):
if
not
isinstance
(
permid
,
dict
):
return
str
(
permid
)
return
permid
[
'
permId
'
]
def
extract_nested_permid
(
permid
):
if
not
isinstance
(
permid
,
dict
):
return
str
(
permid
)
return
permid
[
'
permId
'
][
'
permId
'
]
def
extract_nested_identifier
(
ident
):
def
extract_nested_identifier
(
ident
):
if
not
isinstance
(
ident
,
dict
):
if
not
isinstance
(
ident
,
dict
):
return
str
(
ident
)
return
str
(
ident
)
...
@@ -58,6 +69,24 @@ def extract_person(person):
...
@@ -58,6 +69,24 @@ def extract_person(person):
return
str
(
person
)
return
str
(
person
)
return
"
%s %s <%s>
"
%
(
person
[
'
firstName
'
],
person
[
'
lastName
'
],
person
[
'
email
'
])
return
"
%s %s <%s>
"
%
(
person
[
'
firstName
'
],
person
[
'
lastName
'
],
person
[
'
email
'
])
def
_criteria_for_code
(
code
,
object_type
):
criteria
=
{
"
criteria
"
:
[
{
"
fieldName
"
:
"
code
"
,
"
fieldType
"
:
"
ATTRIBUTE
"
,
"
fieldValue
"
:
{
"
value
"
:
code
,
"
@type
"
:
"
as.dto.common.search.StringEqualToValue
"
},
"
@type
"
:
"
as.dto.common.search.CodeSearchCriteria
"
}
],
"
@type
"
:
search_for_type
[
object_type
],
"
operator
"
:
"
AND
"
}
return
criteria
class
Openbis
:
class
Openbis
:
"""
Interface for communicating with openBIS. A current version of openBIS is needed (at
"""
Interface for communicating with openBIS. A current version of openBIS is needed (at
least version 16.05).
least version 16.05).
...
@@ -267,6 +296,8 @@ class Openbis:
...
@@ -267,6 +296,8 @@ class Openbis:
def
get_space
(
self
,
spaceId
):
def
get_space
(
self
,
spaceId
):
"""
Returns a Space object for a given identifier (spaceId).
"""
Returns a Space object for a given identifier (spaceId).
"""
"""
spaceId
=
str
(
spaceId
).
upper
()
request
=
{
request
=
{
"
method
"
:
"
getSpaces
"
,
"
method
"
:
"
getSpaces
"
,
"
params
"
:
[
"
params
"
:
[
...
@@ -289,42 +320,27 @@ class Openbis:
...
@@ -289,42 +320,27 @@ class Openbis:
"
jsonrpc
"
:
"
2.0
"
"
jsonrpc
"
:
"
2.0
"
}
}
resp
=
self
.
_post_request
(
self
.
as_v3
,
request
)
resp
=
self
.
_post_request
(
self
.
as_v3
,
request
)
if
len
(
resp
)
==
0
:
raise
ValueError
(
"
No such space: %s
"
%
spaceId
)
return
Space
(
self
,
resp
[
spaceId
])
return
Space
(
self
,
resp
[
spaceId
])
def
_criteria_for_code
(
self
,
code
,
object_type
):
criteria
=
{
"
criteria
"
:
[
{
"
fieldName
"
:
"
code
"
,
"
fieldType
"
:
"
ATTRIBUTE
"
,
"
fieldValue
"
:
{
"
value
"
:
code
,
"
@type
"
:
"
as.dto.common.search.StringEqualToValue
"
},
"
@type
"
:
"
as.dto.common.search.CodeSearchCriteria
"
}
],
"
@type
"
:
search_for_type
[
object_type
],
"
operator
"
:
"
AND
"
}
return
criteria
def
get_samples
(
self
,
space
=
None
,
project
=
None
,
experiment
=
None
):
def
get_samples
(
self
,
space
=
None
,
project
=
None
,
experiment
=
None
,
sample_type
=
None
):
"""
Get a list of all samples for a given space/project/experiment (or any combination)
"""
Get a list of all samples for a given space/project/experiment (or any combination)
"""
"""
sub_criteria
=
[]
sub_criteria
=
[]
if
space
:
if
space
:
sub_criteria
.
append
(
self
.
_criteria_for_code
(
space
,
'
space
'
))
sub_criteria
.
append
(
_criteria_for_code
(
space
,
'
space
'
))
if
project
:
if
project
:
exp_crit
=
self
.
_criteria_for_code
(
experiment
,
'
experiment
'
)
exp_crit
=
_criteria_for_code
(
experiment
,
'
experiment
'
)
proj_crit
=
self
.
_criteria_for_code
(
project
,
'
project
'
)
proj_crit
=
_criteria_for_code
(
project
,
'
project
'
)
exp_crit
[
'
criteria
'
]
=
[]
exp_crit
[
'
criteria
'
]
=
[]
exp_crit
[
'
criteria
'
].
append
(
proj_crit
)
exp_crit
[
'
criteria
'
].
append
(
proj_crit
)
sub_criteria
.
append
(
exp_crit
)
sub_criteria
.
append
(
exp_crit
)
if
experiment
:
if
experiment
:
sub_criteria
.
append
(
self
.
_criteria_for_code
(
experiment
,
'
experiment
'
))
sub_criteria
.
append
(
_criteria_for_code
(
experiment
,
'
experiment
'
))
if
sample_type
:
sub_criteria
.
append
(
_criteria_for_code
(
sample_type
,
'
sample_type
'
))
criteria
=
{
criteria
=
{
"
criteria
"
:
sub_criteria
,
"
criteria
"
:
sub_criteria
,
...
@@ -348,7 +364,10 @@ class Openbis:
...
@@ -348,7 +364,10 @@ class Openbis:
"
experiment
"
:
{
"
experiment
"
:
{
"
@type
"
:
"
as.dto.experiment.fetchoptions.ExperimentFetchOptions
"
"
@type
"
:
"
as.dto.experiment.fetchoptions.ExperimentFetchOptions
"
},
},
"
@type
"
:
"
as.dto.sample.fetchoptions.SampleFetchOptions
"
"
type
"
:
{
"
@type
"
:
"
as.dto.sample.fetchoptions.SampleTypeFetchOptions
"
},
"
@type
"
:
"
as.dto.sample.fetchoptions.SampleFetchOptions
"
,
}
}
request
=
{
request
=
{
...
@@ -367,7 +386,7 @@ class Openbis:
...
@@ -367,7 +386,7 @@ class Openbis:
cache
=
{}
cache
=
{}
for
obj
in
objects
:
for
obj
in
objects
:
for
key
in
obj
.
keys
():
for
key
in
obj
.
keys
():
if
key
in
(
'
registrator
'
,
'
modifier
'
,
'
project
'
,
'
experiment
'
,
'
space
'
):
if
key
in
(
'
registrator
'
,
'
modifier
'
,
'
project
'
,
'
experiment
'
,
'
space
'
,
'
type
'
):
if
isinstance
(
obj
[
key
],
dict
):
if
isinstance
(
obj
[
key
],
dict
):
cache
[
obj
[
key
][
'
@id
'
]
]
=
obj
[
key
]
cache
[
obj
[
key
][
'
@id
'
]
]
=
obj
[
key
]
else
:
else
:
...
@@ -384,8 +403,9 @@ class Openbis:
...
@@ -384,8 +403,9 @@ class Openbis:
samples
[
'
modifier
'
]
=
samples
[
'
modifier
'
].
map
(
extract_person
)
samples
[
'
modifier
'
]
=
samples
[
'
modifier
'
].
map
(
extract_person
)
samples
[
'
identifier
'
]
=
samples
[
'
identifier
'
].
map
(
extract_identifier
)
samples
[
'
identifier
'
]
=
samples
[
'
identifier
'
].
map
(
extract_identifier
)
samples
[
'
experiment
'
]
=
samples
[
'
experiment
'
].
map
(
extract_nested_identifier
)
samples
[
'
experiment
'
]
=
samples
[
'
experiment
'
].
map
(
extract_nested_identifier
)
samples
[
'
type
'
]
=
samples
[
'
type
'
].
map
(
extract_nested_permid
)
return
samples
[[
'
code
'
,
'
identifier
'
,
'
experiment
'
,
'
registrator
'
,
'
registrationDate
'
,
'
modifier
'
,
'
modificationDate
'
]]
return
samples
[[
'
code
'
,
'
identifier
'
,
'
experiment
'
,
'
type
'
,
'
registrator
'
,
'
registrationDate
'
,
'
modifier
'
,
'
modificationDate
'
]]
else
:
else
:
raise
ValueError
(
"
No samples found!
"
)
raise
ValueError
(
"
No samples found!
"
)
...
@@ -395,9 +415,9 @@ class Openbis:
...
@@ -395,9 +415,9 @@ class Openbis:
sub_criteria
=
[]
sub_criteria
=
[]
if
space
:
if
space
:
sub_criteria
.
append
(
self
.
_criteria_for_code
(
space
,
'
space
'
))
sub_criteria
.
append
(
_criteria_for_code
(
space
,
'
space
'
))
if
project
:
if
project
:
sub_criteria
.
append
(
self
.
_criteria_for_code
(
project
,
'
project
'
))
sub_criteria
.
append
(
_criteria_for_code
(
project
,
'
project
'
))
criteria
=
{
criteria
=
{
"
criteria
"
:
sub_criteria
,
"
criteria
"
:
sub_criteria
,
...
@@ -464,7 +484,7 @@ class Openbis:
...
@@ -464,7 +484,7 @@ class Openbis:
sub_criteria
=
[]
sub_criteria
=
[]
if
space
:
if
space
:
sub_criteria
.
append
(
self
.
_criteria_for_code
(
space
,
'
space
'
))
sub_criteria
.
append
(
_criteria_for_code
(
space
,
'
space
'
))
criteria
=
{
criteria
=
{
"
criteria
"
:
sub_criteria
,
"
criteria
"
:
sub_criteria
,
...
@@ -1231,37 +1251,8 @@ class Space(dict):
...
@@ -1231,37 +1251,8 @@ class Space(dict):
self
.
openbis
=
openbis_obj
self
.
openbis
=
openbis_obj
self
.
code
=
self
.
code
self
.
code
=
self
.
code
def
get_samples
(
self
):
def
get_samples
(
self
,
*
args
,
**
kwargs
):
"""
Lists all samples in a given space. A pandas DataFrame object is returned.
"""
Lists all samples in a given space. A pandas DataFrame object is returned.
"""
"""
fields
=
[
'
spaceCode
'
,
'
permId
'
,
'
identifier
'
,
'
experimentIdentifierOrNull
'
]
request
=
{
return
self
.
openbis
.
get_samples
(
space
=
self
.
code
,
*
args
,
**
kwargs
)
"
method
"
:
"
searchForSamples
"
,
"
params
"
:
[
self
.
openbis
.
token
,
{
"
matchClauses
"
:
[
{
"
@type
"
:
"
AttributeMatchClause
"
,
"
fieldType
"
:
"
ATTRIBUTE
"
,
"
attribute
"
:
"
SPACE
"
,
"
desiredValue
"
:
self
.
code
,
}
],
"
subCriterias
"
:
[],
"
operator
"
:
"
MATCH_ALL_CLAUSES
"
},
[
"
PROPERTIES
"
,
"
PARENTS
"
]
],
"
id
"
:
"
1
"
,
"
jsonrpc
"
:
"
2.0
"
}
resp
=
self
.
openbis
.
_post_request
(
self
.
openbis
.
as_v1
,
request
)
if
resp
is
not
None
and
len
(
resp
)
>
0
:
datasets
=
DataFrame
(
resp
)[
fields
]
return
datasets
else
:
return
None
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