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
4ea8345f
Commit
4ea8345f
authored
9 years ago
by
aknecht2
Browse files
Options
Downloads
Patches
Plain Diff
Added examples. Created base db class with authentication>
parent
13235331
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
chipathlon/db.py
+22
-1
22 additions, 1 deletion
chipathlon/db.py
examples/gridfs_example.py
+32
-0
32 additions, 0 deletions
examples/gridfs_example.py
examples/join_example.py
+33
-0
33 additions, 0 deletions
examples/join_example.py
with
87 additions
and
1 deletion
chipathlon/db.py
+
22
−
1
View file @
4ea8345f
from
pymongo
import
MongoClient
import
gridfs
import
sys
import
traceback
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
def
setup
This diff is collapsed.
Click to expand it.
examples/gridfs_example.py
0 → 100644
+
32
−
0
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
()
This diff is collapsed.
Click to expand it.
examples/join_example.py
0 → 100644
+
33
−
0
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
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