Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Holland Computing Center
chipathlon
Commits
edbc4f8d
Commit
edbc4f8d
authored
May 26, 2017
by
aknecht2
Browse files
Updated file caching to use both accession & file_type.
parent
4acb6045
Changes
1
Hide whitespace changes
Inline
Side-by-side
chipathlon/db.py
View file @
edbc4f8d
...
...
@@ -6,6 +6,7 @@ import traceback
import
os
import
itertools
import
time
import
collections
import
chipathlon.conf
from
pprint
import
pprint
import
hashlib
...
...
@@ -35,7 +36,7 @@ class MongoDB(object):
self
.
password
=
password
self
.
client
=
MongoClient
(
host
)
self
.
db
=
self
.
client
.
chipseq
self
.
cache
=
{}
self
.
cache
=
collections
.
defaultdict
(
dict
)
try
:
self
.
db
.
authenticate
(
username
,
password
,
mechanism
=
"SCRAM-SHA-1"
)
except
:
...
...
@@ -45,12 +46,12 @@ class MongoDB(object):
self
.
gfs
=
gridfs
.
GridFS
(
self
.
db
)
return
def
add_cache
(
self
,
function
,
key
,
data
):
def
add_cache
(
self
,
accession
,
file_type
,
data
):
"""
:param
funct
ion: The
function name
:type
funct
ion: str
:param
key: The key to add the cache entry under
.
:type
key: Any hashable
:param
access
ion: The
accession of the file to store.
:type
access
ion: str
:param
file_type: The type of file to store
.
:type
file_type: str
:param data: The data to add to the cache.
:type data: Object
...
...
@@ -60,23 +61,20 @@ class MongoDB(object):
peak calling tools. In these cases we don't want to request info
from the database multiple times for the same data.
"""
if
function
not
in
self
.
cache
:
self
.
cache
[
function
]
=
{}
self
.
cache
[
function
][
key
]
=
data
self
.
cache
[
accession
][
file_type
]
=
data
return
def
get_cache
(
self
,
function
,
key
):
def
get_cache
(
self
,
accession
,
file_type
):
"""
:param
funct
ion: The
function name
:type
funct
ion: str
:param
key: The key to get from the cach
e.
:type
key: Any hashable
:param
access
ion: The
accession of the file to retrieve.
:type
access
ion: str
:param
file_type: The type of file to retriev
e.
:type
file_type: str
Gets a data item from the internal cache.
"""
if
function
in
self
.
cache
:
if
key
in
self
.
cache
[
function
]:
return
self
.
cache
[
function
][
key
]
if
accession
in
self
.
cache
:
return
self
.
cache
[
accession
].
get
(
file_type
)
return
None
def
delete_result
(
self
,
result
,
genome
):
...
...
@@ -331,7 +329,7 @@ class MongoDB(object):
valid
=
True
msg
=
""
data
=
{}
check_cache
=
self
.
get_cache
(
"get_sample"
,
accession
)
check_cache
=
self
.
get_cache
(
accession
,
file_type
)
if
check_cache
is
not
None
:
msg
=
"Retrieved data from cache."
data
=
check_cache
...
...
@@ -342,7 +340,7 @@ class MongoDB(object):
})
if
cursor
.
count
()
==
1
:
data
=
cursor
.
next
()
self
.
add_cache
(
"get_sample"
,
accession
,
data
)
self
.
add_cache
(
accession
,
file_type
,
data
)
else
:
valid
=
False
msg
=
"Found %s files with accession: %s, file_type: %s. Should only be 1."
%
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment