Skip to content

Commit

Permalink
reworks backup strategy (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-ervin-jones authored Jan 23, 2023
1 parent 4fe3ae6 commit c33f9fd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 26 deletions.
10 changes: 3 additions & 7 deletions phylofisher/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def first_backup(dfo, date_time):
os.mkdir(f'{dfo}/backups/{date_time}')
shutil.copytree(f'{dfo}/orthologs', f'{dfo}/backups/{date_time}/orthologs')
shutil.copytree(f'{dfo}/paralogs', f'{dfo}/backups/{date_time}/paralogs')
shutil.copytree(f'{dfo}/proteomes', f'{dfo}/backups/{date_time}/proteomes')
shutil.copy(f'{dfo}/metadata.tsv', f'{dfo}/backups/{date_time}/metadata.tsv')
shutil.copy(f'{dfo}/tree_colors.tsv', f'{dfo}/backups/{date_time}/tree_colors.tsv')

Expand All @@ -210,13 +209,12 @@ def backup(dfo):
os.mkdir(f'{dfo}/backups/{now}')
os.mkdir(f'{dfo}/backups/{now}/orthologs')
os.mkdir(f'{dfo}/backups/{now}/paralogs')
os.mkdir(f'{dfo}/backups/{now}/proteomes')

for root, dirs, files in os.walk(f'{dfo}/backups'):
for file in files:
back_files[file] = (os.path.join(root, file))

for folder in ['orthologs', 'paralogs', 'proteomes']:
for folder in ['orthologs', 'paralogs']:
for root, dirs, files in os.walk(f'{dfo}/{folder}'):
for file in files:
db_files[file] = (os.path.join(root, file))
Expand All @@ -230,10 +228,8 @@ def backup(dfo):
else:
dest = '/'.join(v.split('/')[-2:])

if k in back_files.keys() and get_md5(db_files[k]) == get_md5(back_files[k]):
os.symlink(f'{dfo}/backups/{latest_backup}/{dest}', f'{dfo}/backups/{now}/{dest}')
else:
shutil.copy(v, f'{dfo}/backups/{now}/{dest}')

shutil.copy(v, f'{dfo}/backups/{now}/{dest}')

else:
first_backup(dfo, now)
3 changes: 0 additions & 3 deletions phylofisher/utilities/backup_restoration.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ def restore():
os.remove(f'{args.database}/tree_colors.tsv')
shutil.copy(f'{backup_dir}/tree_colors.tsv', f'{args.database}/tree_colors.tsv')

if os.path.isdir(f'{args.database}/proteomes'):
shutil.rmtree(f'{args.database}/proteomes')
shutil.copytree(f'{backup_dir}/proteomes', f'{args.database}/proteomes')


if __name__ == '__main__':
Expand Down
16 changes: 0 additions & 16 deletions phylofisher/utilities/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,6 @@ def delete_homologs(org_set):
fasta_cleaner(file, org_set)


def delete_proteomes(org_set, collapsed_taxa):
'''
Purges input proteomes
Does not purge collapsed taxa, because they do not have a input proteomes
:param org_set: organisms to remove
:type org_set: set
:param collapsed_taxa: collapsed taxa
:type collapsed_taxa: list
'''
for org in org_set:
if org not in collapsed_taxa:
os.remove(os.path.join(dfo, 'proteomes', f'{org}.faa.tar.gz'))


def purge(collapsed_taxa):
'''
Purges taxa from database
Expand All @@ -131,7 +116,6 @@ def purge(collapsed_taxa):
res.writerow(line)

delete_homologs(orgs_to_del)
delete_proteomes(orgs_to_del, collapsed_taxa)


if __name__ == '__main__':
Expand Down

0 comments on commit c33f9fd

Please sign in to comment.