diff options
author | Alexander_Kabui | 2023-01-23 13:34:38 +0300 |
---|---|---|
committer | Alexander_Kabui | 2023-01-23 13:34:38 +0300 |
commit | 8dcdfea901631fa65b6f4793a152bf66188a98de (patch) | |
tree | b13d8bc148841098170401b74b3f8c7e5a3030e1 | |
parent | 683674266c4ea0744284c17e7516ebb952169c86 (diff) | |
download | genenetwork2-8dcdfea901631fa65b6f4793a152bf66188a98de.tar.gz |
generate csv file;parse dataset
-rw-r--r-- | wqflask/wqflask/correlation/correlation_file_generator.py | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/wqflask/wqflask/correlation/correlation_file_generator.py b/wqflask/wqflask/correlation/correlation_file_generator.py index 9f469a32..79161f6d 100644 --- a/wqflask/wqflask/correlation/correlation_file_generator.py +++ b/wqflask/wqflask/correlation/correlation_file_generator.py @@ -1,8 +1,9 @@ from urllib.parse import urlparse import pymysql as mdb -import os +import os import csv + def get_probesetfreezes(conn, inbredsetid=1): with conn.cursor() as cursor: cursor.execute( @@ -79,4 +80,46 @@ WHERE a.database_name = b.db_last_update_name """ - #todo file_storage lmdb file_parsing file_run
\ No newline at end of file + # todo file_storage lmdb file_parsing file_run + + + + +def parse_dataset(results): + ids = ["ID"] + data = {} + for (trait, strain,val) in results: + if strain not in ids: + ids.append(strain) + + if trait in data: + data[trait].append(val) + else: + data[trait] = [trait,val] + + return (data,ids) + +# above refactor the code + +def generate_csv_file(conn,db_name,txt_dir,file_name): + + # write to file + + # file name ,file expiry,type of storage + + # I want to use lmdb to store the files + # file name already done #import that + + # file expiry to be done lt + + try: + (data,col_ids) = parse_dataset(fetch_probeset_data(conn,db_name)) + with open( os.path.join(txt_dir,file_name),"w+" ,encoding='UTF8') as file_handler: + writer = csv.writer(file_handler) + writer.writerow(col_ids) # write header s + writer.writerows(val for val in data.values() ) + return "success" + + except Exception as e: + raise e + |