From 3cf23c78edcb9ca397e7ff7ed12366cc8f791a5d Mon Sep 17 00:00:00 2001 From: Niema Moshiri Date: Wed, 10 Jun 2020 13:42:18 -0700 Subject: [PATCH] Added ability to update ViralMSA --- ViralMSA.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ViralMSA.py b/ViralMSA.py index f06b382..fb91607 100755 --- a/ViralMSA.py +++ b/ViralMSA.py @@ -6,6 +6,7 @@ # imports from Bio import Entrez from datetime import datetime +from json import load as jload from math import log2 from multiprocessing import cpu_count from os import chdir,getcwd,makedirs,remove @@ -13,10 +14,12 @@ from shutil import move from subprocess import call,check_output,PIPE,Popen,STDOUT from sys import argv,stderr,stdout +from urllib.request import urlopen import argparse # useful constants -VERSION = '1.0.0' +VERSION = '1.0.1' +RELEASES_URL = 'https://api.github.com/repos/niemasd/ViralMSA/tags' CIGAR_LETTERS = {'M','D','I','S','H','=','X'} # reference genomes for common viruses @@ -69,6 +72,22 @@ } } +# convert a ViralMSA version string to a tuple of integers +def parse_version(s): + return tuple(int(v) for v in s.split('.')) + +# update ViralMSA to the newest version +def update_viralmsa(): + tags = jload(urlopen(RELEASES_URL)) + newest = max(tags, key=lambda x: parse_version(x['name'])) + if parse_version(newest['name']) <= parse_version(VERSION): + print("ViralMSA is already at the newest version (%s)" % VERSION); exit(0) + url = 'https://raw.githubusercontent.com/niemasd/ViralMSA/%s/ViralMSA.py' % newest['commit']['sha'] + content = urlopen(url).read() + with open(__file__, 'wb') as f: + f.write(content) + exit(0) + # return the current time as a string def get_time(): return datetime.now().strftime("%Y-%m-%d %H:%M:%S") @@ -292,6 +311,10 @@ def align_star(seqs_path, out_sam_path, ref_genome_path, threads, verbose=True): # main content if __name__ == "__main__": + # check if user wants to update ViralMSA + if '-u' in argv or '--update' in argv: + update_viralmsa() + # check if user just wants to list references if '-l' in argv or '--list_references' in argv: print("=== List of ViralMSA Reference Sequences ===")