Skip to content

Commit

Permalink
fix(bug): fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
giangbui committed Mar 27, 2018
1 parent e282e1a commit 17b1984
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
7 changes: 3 additions & 4 deletions peregrine/resources/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def root_graphql_query():
payload = peregrine.utils.parse_request_json()
query = payload.get('query')
export_format = payload.get('format')
bag_path = payload.get('path')
variables, errors = peregrine.utils.get_variables(payload)
if errors:
return flask.jsonify({'data': None, 'errors': errors}), 400
Expand All @@ -98,9 +97,9 @@ def root_graphql_query():
if export_format == 'bdbag':
data, code = return_data
if code == 200:
if peregrine.utils.contain_node_with_category(data.json, 'data_file') == False:
return flask.jsonify({'errors': 'No data_file node'}), 400
res = peregrine.utils.json2tbl(json.loads(data.data), '', "_")
# if peregrine.utils.contain_node_with_category(data.data, 'data_file') == False:
# return flask.jsonify({'errors': 'No data_file node'}), 400
res = peregrine.utils.json2tbl(json.loads(data.data), '', "-")
tsv = peregrine.utils.dicts2tsv(res)
return flask.Response(tsv, mimetype='text/tab-separated-values'), code
else:
Expand Down
19 changes: 10 additions & 9 deletions peregrine/utils/json2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,31 @@ def dicts2tsv(dict_list):
output string
"""
tsv = ""

header_set = set()

for dict_row in dict_list:
header_set.update(dict_row.keys())

for h in sorted(header_set):
words = h.split('_')
for h in header_set:
words = h.split('-')
tsv = tsv + "{}\t".format(words[-1])
tsv = tsv[:-1] + "\n"

nrow = 0
for dict_row in dict_list:
row = []
for h in sorted(header_set):
for h in header_set:
if dict_row[h]:
tsv = tsv + "{}\t".format(dict_row[h])
else:
tsv = tsv + "None\t"
tsv = tsv[:-1] + "\n"
nrow = nrow + 1
if nrow >= 1000:
break
tsv = tsv[:-1] + "\n"
nrow = nrow + 1
if nrow >= 1000:
break
return tsv


def join(table_list, L, index, row):
'''
Join sub tables to generate a big table
Expand Down
10 changes: 4 additions & 6 deletions peregrine/utils/pybdbag.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ def create_bdbag(bag_path, bag_info, payload, max_row=10000):

with open(bag_path + '/data/manifest.tsv', 'w') as tsvfile:
writer = csv.writer(tsvfile, delimiter='\t')
#write header
# write header
row = []
for k in payload[0].keys():
k = k.replace('_data_','')
k = k.replace('_data_', '')
row.append(k)
header = copy.deepcopy(row)
writer.writerow(row)
nrow = 1
print('==============header==========')
print(header)
for row_dict in payload:
row=[]
row = []
print(row_dict)
for h in header:
if row_dict.get('_data_'+h):
Expand All @@ -40,7 +38,7 @@ def create_bdbag(bag_path, bag_info, payload, max_row=10000):
nrow = nrow + 1
if nrow >= max_row:
break

bag.save(manifests=True) # creates checksum manifests
# Compress bag.
zip_file_path = os.path.basename(os.path.normpath(str(bag)))
Expand Down

0 comments on commit 17b1984

Please sign in to comment.