Skip to content
GitLab
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
4ea8345f
Commit
4ea8345f
authored
Feb 25, 2016
by
aknecht2
Browse files
Added examples. Created base db class with authentication>
parent
13235331
Changes
3
Hide whitespace changes
Inline
Side-by-side
chipathlon/db.py
View file @
4ea8345f
from
pymongo
import
MongoClient
import
gridfs
import
sys
import
traceback
def
setup
class
MongoDB
(
object
):
def
__init__
(
self
,
host
,
username
,
password
):
self
.
client
=
MongoClient
(
args
.
host
)
self
.
db
=
client
.
chipseq
try
:
self
.
db
.
authenticate
(
args
.
username
,
args
.
password
,
mechanism
=
"SCRAM-SHA-1"
)
except
:
print
(
"Could not authenticate to db %s!"
%
(
host
,))
print
traceback
.
format_exc
()
sys
.
exit
(
1
)
self
.
gfs
=
gridfs
.
GridFS
(
self
.
db
)
return
def
load_bed
(
self
,
collection
,
result_id
,
bed_file
,
attributes
=
{}):
return
examples/gridfs_example.py
0 → 100644
View file @
4ea8345f
from
pymongo
import
MongoClient
import
argparse
from
pprint
import
pprint
import
gridfs
parser
=
argparse
.
ArgumentParser
(
description
=
"Perform a join between the experiment and sample collections."
)
parser
.
add_argument
(
"--password"
,
dest
=
"password"
,
required
=
True
,
help
=
"Database user password."
)
parser
.
add_argument
(
"--username"
,
dest
=
"username"
,
default
=
"aknecht"
,
required
=
True
,
help
=
"Database user."
)
parser
.
add_argument
(
"--host"
,
dest
=
"host"
,
default
=
"hcc-anvil-241-41.unl.edu"
,
required
=
True
,
help
=
"Database host."
)
args
=
parser
.
parse_args
()
# Everything in a db named chipseq
# Set up connection and authenticate
client
=
MongoClient
(
args
.
host
)
db
=
client
.
chipseq
db
.
authenticate
(
args
.
username
,
args
.
password
,
mechanism
=
"SCRAM-SHA-1"
)
gfs
=
gridfs
.
GridFS
(
db
)
# Put a file
with
open
(
"join_example.py"
,
"r"
)
as
rh
:
gfs
.
put
(
rh
,
filename
=
"foo"
,
attribute1
=
"asdf"
,
attribute2
=
"asdf"
)
# Find files
cursor
=
gfs
.
find
({
"filename"
:
"foo"
,
"attribute1"
:
"asdf"
})
for
document
in
cursor
:
print
document
.
read
()
examples/join_example.py
0 → 100644
View file @
4ea8345f
from
pymongo
import
MongoClient
import
argparse
from
pprint
import
pprint
parser
=
argparse
.
ArgumentParser
(
description
=
"Perform a join between the experiment and sample collections."
)
parser
.
add_argument
(
"--password"
,
dest
=
"password"
,
required
=
True
,
help
=
"Database user password."
)
parser
.
add_argument
(
"--username"
,
dest
=
"username"
,
default
=
"aknecht"
,
required
=
True
,
help
=
"Database user."
)
parser
.
add_argument
(
"--host"
,
dest
=
"host"
,
default
=
"hcc-anvil-241-41.unl.edu"
,
required
=
True
,
help
=
"Database host."
)
args
=
parser
.
parse_args
()
# Everything in a db named chipseq
# Set up connection and authenticate
client
=
MongoClient
(
args
.
host
)
db
=
client
.
chipseq
db
.
authenticate
(
args
.
username
,
args
.
password
,
mechanism
=
"SCRAM-SHA-1"
)
cursor
=
db
.
experiments
.
aggregate
([
{
"$lookup"
:
{
"from"
:
"samples"
,
"localField"
:
"_id"
,
"foreignField"
:
"experiment_id"
,
"as"
:
"samples"
}
}
## Potentially more aggregation steps here.
])
for
document
in
cursor
:
if
len
(
document
[
"samples"
])
>
0
:
pprint
(
document
)
break
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment