Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
chipathlon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Holland Computing Center
chipathlon
Commits
36308a57
Commit
36308a57
authored
7 years ago
by
aknecht2
Browse files
Options
Downloads
Patches
Plain Diff
Added db caching to greatly improve workflow generation time.
parent
9d36904d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
chipathlon/db.py
+46
-13
46 additions, 13 deletions
chipathlon/db.py
with
46 additions
and
13 deletions
chipathlon/db.py
+
46
−
13
View file @
36308a57
...
...
@@ -30,6 +30,7 @@ class MongoDB(object):
self
.
password
=
password
self
.
client
=
MongoClient
(
host
)
self
.
db
=
self
.
client
.
chipseq
self
.
cache
=
{}
try
:
self
.
db
.
authenticate
(
username
,
password
,
mechanism
=
"
SCRAM-SHA-1
"
)
except
:
...
...
@@ -39,6 +40,32 @@ class MongoDB(object):
self
.
gfs
=
gridfs
.
GridFS
(
self
.
db
)
return
def
add_cache
(
self
,
function
,
key
,
data
):
"""
:param function: The function name
:type function: str
:param key: The key to add the cache entry under.
:type key: Any hashable
:param data: The data to add to the cache.
:type data: Object
"""
if
function
not
in
self
.
cache
:
self
.
cache
[
function
]
=
{}
self
.
cache
[
function
][
key
]
=
data
return
def
get_cache
(
self
,
function
,
key
):
"""
:param function: The function name
:type function: str
:param key: The key to get from the cache.
:type key: Any hashable
"""
if
function
in
self
.
cache
:
if
key
in
self
.
cache
[
function
]:
return
self
.
cache
[
function
][
key
]
return
None
def
delete_result
(
self
,
result
,
genome
):
"""
:param result: The result to delete
...
...
@@ -279,19 +306,25 @@ class MongoDB(object):
valid
=
True
msg
=
""
data
=
{}
cursor
=
self
.
db
.
samples
.
find
({
"
accession
"
:
accession
,
"
file_type
"
:
file_type
})
if
cursor
.
count
()
==
1
:
data
=
cursor
.
next
()
check_cache
=
self
.
get_cache
(
"
get_sample
"
,
accession
)
if
check_cache
is
not
None
:
msg
=
"
Retrieved data from cache.
"
data
=
check_cache
else
:
valid
=
False
msg
=
"
Found %s files with accession: %s, file_type: %s. Should only be 1.
"
%
(
cursor
.
count
(),
accession
,
file_type
)
cursor
=
self
.
db
.
samples
.
find
({
"
accession
"
:
accession
,
"
file_type
"
:
file_type
})
if
cursor
.
count
()
==
1
:
data
=
cursor
.
next
()
self
.
add_cache
(
"
get_sample
"
,
accession
,
data
)
else
:
valid
=
False
msg
=
"
Found %s files with accession: %s, file_type: %s. Should only be 1.
"
%
(
cursor
.
count
(),
accession
,
file_type
)
return
(
valid
,
msg
,
data
)
def
get_samples
(
self
,
experiment_accession
,
file_type
):
...
...
@@ -307,7 +340,7 @@ class MongoDB(object):
valid -- Whether or not the accession / file_type combo is a valid exp
msg -- Why it is or is not valid
data -- A dictionary containing a list of all control / sample documents.
The data dictionary has two keys,
"
control
"
and
"
signal
"
, each one containing
a list of all metadata related to the experiment samples. The sample metadata
is taken directly from Mongo.
...
...
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