Skip to content

Commit

Permalink
Added ability to update ViralMSA
Browse files Browse the repository at this point in the history
  • Loading branch information
niemasd committed Jun 10, 2020
1 parent 29a230e commit 3cf23c7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion ViralMSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
# 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
from os.path import abspath,expanduser,isdir,isfile,split
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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 ===")
Expand Down

0 comments on commit 3cf23c7

Please sign in to comment.