From cd9933e37ae76aea19f807ba62df8c949d21882a Mon Sep 17 00:00:00 2001 From: Mats Bovin Date: Fri, 5 Jan 2024 08:26:03 +0100 Subject: [PATCH] Copy original files first --- sbdi/process-backbone.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/sbdi/process-backbone.py b/sbdi/process-backbone.py index 3deb922..b2c38c1 100755 --- a/sbdi/process-backbone.py +++ b/sbdi/process-backbone.py @@ -1,11 +1,18 @@ #!/usr/bin/env python3 +import os import sys def process_taxon(src_dir): print('\nProcess taxon') - infile = open(f'{src_dir}/Taxon-lab.tsv', 'r') - outfile = open(f'{src_dir}/Taxon-new.tsv', 'w') + destination_path = f'{src_dir}/Taxon.tsv' + original_path = f'{destination_path}.original' + + if not os.path.isfile(original_path): + os.rename(destination_path, original_path) + + infile = open(original_path, 'r') + outfile = open(destination_path, 'w') row_count = 0 @@ -33,8 +40,14 @@ def process_taxon(src_dir): def process_vernacular_name(src_dir): print('\nProcess vernacular name') - infile = open(f'{src_dir}/VernacularName.tsv', 'r') - outfile = open(f'{src_dir}/VernacularName-new.tsv', 'w') + destination_path = f'{src_dir}/VernacularName.tsv' + original_path = f'{destination_path}.original' + + if not os.path.isfile(original_path): + os.rename(destination_path, original_path) + + infile = open(original_path, 'r') + outfile = open(destination_path, 'w') row_count = 0 keep_count = 0 @@ -57,6 +70,7 @@ def process_vernacular_name(src_dir): print(f'Done. Processed {row_count} rows. Kept {keep_count} rows.') def main(argv): + src_dir = argv[1] if len(argv) > 1 else '/data/bie-index/import/backbone' print(f'Using {src_dir} as source directory')