Skip to content

Commit

Permalink
Remove 'if'
Browse files Browse the repository at this point in the history
  • Loading branch information
finngl committed May 7, 2024
1 parent 9e74d9a commit 2d93a70
Showing 1 changed file with 20 additions and 31 deletions.
51 changes: 20 additions & 31 deletions new_project_from_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
"A minimal data table will be generated automatically.")
parser = argparse.ArgumentParser(description=help_desc)
parser.add_argument(
"--trees",
"trees",
help=(
"Mongo ID(s) for document(s) in tree_calculations collection. "
"If more than one ID, separate with commas without spaces. "
"If argument is omitted, a random tree tree_calculations collection will be chosen."
)
)
parser.add_argument(
Expand All @@ -40,35 +39,25 @@
db = connection.get_database('bio_api_test')
trees_str: str = args.trees
tree_calcs = list()
if trees_str is None:
tc = db['tree_calculations'].find_one()
dmx_job_id = tc['dmx_job'] #TODO unify
dmx_job = db['dist_calculations'].find_one({'_id': ObjectId(dmx_job_id)})
assert 'result' in dmx_job
assert type(dmx_job['result']) is dict
assert['seq_to_mongo'] in dmx_job['result']
print(dmx_job)
tree_calcs.append(tc)
else:
tree_ids = [ ObjectId(id) for id in trees_str.split(',') ]
print("Tree ids:")
print(tree_ids)
tree_cursor = db['tree_calculations'].find({'_id': {'$in': tree_ids}})
tc = next(tree_cursor)
tree_calcs.append(tc)
dmx_job_id = tc['dmx_job'] #TODO unify
dmx_job = db['dist_calculations'].find_one({'_id': ObjectId(dmx_job_id)})
assert 'result' in dmx_job
assert type(dmx_job['result']) is dict
assert 'seq_to_mongo' in dmx_job['result']
while True:
try:
tc = next(tree_cursor)
# Make sure that all trees are calculated from the same dmx job
assert tc['dmx_job'] == dmx_job_id
tree_calcs.append(tc)
except StopIteration:
break
tree_ids = [ ObjectId(id) for id in trees_str.split(',') ]
print("Tree ids:")
print(tree_ids)
tree_cursor = db['tree_calculations'].find({'_id': {'$in': tree_ids}})
tc = next(tree_cursor)
tree_calcs.append(tc)
dmx_job_id = tc['dmx_job'] #TODO unify
dmx_job = db['dist_calculations'].find_one({'_id': ObjectId(dmx_job_id)})
assert 'result' in dmx_job
assert type(dmx_job['result']) is dict
assert 'seq_to_mongo' in dmx_job['result']
while True:
try:
tc = next(tree_cursor)
# Make sure that all trees are calculated from the same dmx job
assert tc['dmx_job'] == dmx_job_id
tree_calcs.append(tc)
except StopIteration:
break

seq_to_mongo:dict = dmx_job['result']['seq_to_mongo']
print("Seq to mongo:")
Expand Down

0 comments on commit 2d93a70

Please sign in to comment.