diff options
Diffstat (limited to 'Code/parse_ena_xml.py')
-rw-r--r-- | Code/parse_ena_xml.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Code/parse_ena_xml.py b/Code/parse_ena_xml.py index 75777a1..4af3a77 100644 --- a/Code/parse_ena_xml.py +++ b/Code/parse_ena_xml.py @@ -30,7 +30,9 @@ import os, json, re, operator import xml.etree.ElementTree import sys import string -from configure import ENA_RECORDS_READ_RUN, ENA_RECORDS_READ_EXPERIMENT, ENA_RECORDS_SAMPLE, ENA_RECORDS_STUDY +import shutil +from backup_files import backup_file +from configure import ENA_RECORDS_READ_RUN, ENA_RECORDS_READ_EXPERIMENT, ENA_RECORDS_SAMPLE, ENA_RECORDS_STUDY, RNA_SEQ_INFO_DATABASE_JSON MAX_DESCRIPTION_LENGTH = 6000 # max number to characters to keep in json file @@ -326,6 +328,15 @@ if __name__ == '__main__': percent = 100*count_tissue/count_transcriptomic print(f'%% RNA-seq: {count_transcriptomic}, of which {count_tissue} having tissue info ({percent} percent)') - fname = '../Data/information/rnaseq_info_database.json.temp' - with open(fname, 'w') as f: + temp_fname = RNA_SEQ_INFO_DATABASE_JSON + '.temp' + with open(temp_fname, 'w') as f: json.dump(json_dict, f, indent=4) + + # Use rnaseq_info_database.json.temp to replace the exisiting rnaseq_info_database.json + # But make a backup for rnaseq_info_database.json first + try: + bak_fname = backup_file(RNA_SEQ_INFO_DATABASE_JSON) + shutil.move(temp_fname, RNA_SEQ_INFO_DATABASE_JSON) + print(f'Made {bak_fname}') + except Exception as e: + print(f'Backup {RNA_SEQ_INFO_DATABASE_JSON} encountered problem') |