diff options
author | zsloan | 2022-08-01 16:00:25 +0000 |
---|---|---|
committer | zsloan | 2022-08-01 17:01:54 +0000 |
commit | 00baf5bab27fd034a53add29111e9aa0d9e45d6b (patch) | |
tree | 38bff0fb1bfe4b8f35c18ce26a56c59d0ac56195 /wqflask | |
parent | 82922e5a052abf22b9d458ddebaf8ee523bd6f55 (diff) | |
download | genenetwork2-00baf5bab27fd034a53add29111e9aa0d9e45d6b.tar.gz |
Add index column and phenotype group code to trait export
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/show_trait/export_trait_data.py | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/wqflask/wqflask/show_trait/export_trait_data.py b/wqflask/wqflask/show_trait/export_trait_data.py index 4b328a4a..ae83907e 100644 --- a/wqflask/wqflask/show_trait/export_trait_data.py +++ b/wqflask/wqflask/show_trait/export_trait_data.py @@ -11,11 +11,11 @@ def export_sample_table(targs): sample_data = json.loads(targs['export_data']) trait_name = targs['trait_display_name'] - meta_data = get_export_metadata(targs['trait_id'], targs['dataset']) + meta_data = get_export_metadata(targs) final_sample_data = meta_data - column_headers = ["Name", "Value"] + column_headers = ["Index", "Name", "Value"] attr_pos = 2 if any(sample["se"] for sample in sample_data['primary_samples']): column_headers.append("SE") @@ -30,8 +30,8 @@ def export_sample_table(targs): final_sample_data.append(column_headers) for sample_group in ['primary_samples', 'other_samples']: - for row in sample_data[sample_group]: - sorted_row = dict_to_sorted_list(row)[:attr_pos] + for i, row in enumerate(sample_data[sample_group]): + sorted_row = [i + 1] + dict_to_sorted_list(row)[:attr_pos] for attr in sample_data['attributes']: sorted_row.append(row[attr]) final_sample_data.append(sorted_row) @@ -39,7 +39,10 @@ def export_sample_table(targs): return trait_name, final_sample_data -def get_export_metadata(trait_id, dataset_name): +def get_export_metadata(trait_metadata): + + trait_id, display_name, dataset_name = trait_metadata['trait_id'], trait_metadata['trait_display_name'], trait_metadata['dataset'] + dataset = data_set.create_dataset(dataset_name) this_trait = create_trait(dataset=dataset, name=trait_id, @@ -48,28 +51,28 @@ def get_export_metadata(trait_id, dataset_name): metadata = [] if dataset.type == "Publish": - metadata.append(["Phenotype ID: " + trait_id]) - metadata.append(["Phenotype URL: " + "http://genenetwork.org/show_trait?trait_id=" + \ + metadata.append(["Phenotype ID:", display_name]) + metadata.append(["Phenotype URL: ", "http://genenetwork.org/show_trait?trait_id=" + \ trait_id + "&dataset=" + dataset_name]) - metadata.append(["Group: " + dataset.group.name]) + metadata.append(["Group: ", dataset.group.name]) metadata.append( - ["Phenotype: " + this_trait.description_display.replace(",", "\",\"")]) + ["Phenotype: ", this_trait.description_display.replace(",", "\",\"")]) metadata.append( - ["Authors: " + (this_trait.authors if this_trait.authors else "N/A")]) + ["Authors: ", (this_trait.authors if this_trait.authors else "N/A")]) metadata.append( - ["Title: " + (this_trait.title if this_trait.title else "N/A")]) + ["Title: ", (this_trait.title if this_trait.title else "N/A")]) metadata.append( - ["Journal: " + (this_trait.journal if this_trait.journal else "N/A")]) + ["Journal: ", (this_trait.journal if this_trait.journal else "N/A")]) metadata.append( - ["Dataset Link: http://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&InfoPageName=" + dataset.name]) + ["Dataset Link: ", "http://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&InfoPageName=" + dataset.name]) else: - metadata.append(["Record ID: " + trait_id]) - metadata.append(["Trait URL: " + "http://genenetwork.org/show_trait?trait_id=" + \ + metadata.append(["Record ID: ", trait_id]) + metadata.append(["Trait URL: ", "http://genenetwork.org/show_trait?trait_id=" + \ trait_id + "&dataset=" + dataset_name]) if this_trait.symbol: - metadata.append(["Symbol: " + this_trait.symbol]) - metadata.append(["Dataset: " + dataset.name]) - metadata.append(["Group: " + dataset.group.name]) + metadata.append(["Symbol: ", this_trait.symbol]) + metadata.append(["Dataset: ", dataset.name]) + metadata.append(["Group: ", dataset.group.name]) metadata.append([]) |