-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jon Palmer
committed
Mar 24, 2023
1 parent
28d817d
commit 1eb9631
Showing
5 changed files
with
103 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
VERSION = (1, 5, 5) | ||
VERSION = (1, 6, 0) | ||
|
||
__version__ = ".".join(map(str, VERSION)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"ITS": [ | ||
"https://osf.io/kse82/download?version=2", | ||
"https://osf.io/mx5gd/download?version=2" | ||
], | ||
"16S": "https://osf.io/m7v5q/download?version=4", | ||
"LSU": "https://osf.io/sqn5r/download?version=4", | ||
"COI": "https://osf.io/pax79/download?version=5", | ||
"PR2": "https://osf.io/6hjdq/download?version=2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#!/usr/bin/env python | ||
|
||
from __future__ import (absolute_import, division, | ||
print_function, unicode_literals) | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
import sys | ||
import os | ||
import argparse | ||
|
@@ -10,69 +9,117 @@ | |
import json | ||
import requests | ||
import shutil | ||
import subprocess | ||
from amptk import amptklib | ||
|
||
try: | ||
from urllib.request import urlopen | ||
except ImportError: | ||
from urllib2 import urlopen | ||
|
||
|
||
class MyFormatter(argparse.ArgumentDefaultsHelpFormatter): | ||
def __init__(self,prog): | ||
super(MyFormatter,self).__init__(prog,max_help_position=50) | ||
def __init__(self, prog): | ||
super(MyFormatter, self).__init__(prog, max_help_position=50) | ||
|
||
|
||
def main(args): | ||
parser=argparse.ArgumentParser(prog='amptk-install.py', | ||
description='''Script to download preformatted databases''', | ||
parser = argparse.ArgumentParser( | ||
prog="amptk-install.py", | ||
description="""Script to download preformatted databases""", | ||
epilog="""Written by Jon Palmer (2019) [email protected]""", | ||
formatter_class=MyFormatter) | ||
parser.add_argument('-i','--input', nargs='+', required=True, choices=['ITS', '16S', 'LSU', 'COI', 'PR2'], help='Install Databases') | ||
parser.add_argument('-f','--force', action='store_true', help='Overwrite existing databases') | ||
parser.add_argument('-l','--local', action='store_true', help='Use local downloads.json for links') | ||
args=parser.parse_args(args) | ||
formatter_class=MyFormatter, | ||
) | ||
parser.add_argument( | ||
"-i", | ||
"--input", | ||
nargs="+", | ||
required=True, | ||
choices=["ITS", "16S", "LSU", "COI", "PR2"], | ||
help="Install Databases", | ||
) | ||
parser.add_argument( | ||
"-f", "--force", action="store_true", help="Overwrite existing databases" | ||
) | ||
parser.add_argument( | ||
"-l", "--local", action="store_true", help="Use local downloads.json for links" | ||
) | ||
args = parser.parse_args(args) | ||
|
||
parentdir = os.path.join(os.path.dirname(amptklib.__file__)) | ||
|
||
# downd from github to get most recent databases | ||
if not args.local: | ||
try: | ||
print('Retrieving download links from GitHub Repo') | ||
URL = json.loads(requests.get("https://raw.githubusercontent.com/nextgenusfs/amptk/master/amptk/downloads.json").text) | ||
print("Retrieving download links from GitHub Repo") | ||
URL = json.loads( | ||
requests.get( | ||
"https://raw.githubusercontent.com/nextgenusfs/amptk/master/amptk/downloadsv1.6.0.json" | ||
).text | ||
) | ||
except: | ||
print('Unable to download links from GitHub, using funannotate version specific links') | ||
with open(os.path.join(os.path.dirname(__file__), 'downloads.json')) as infile: | ||
print( | ||
"Unable to download links from GitHub, using funannotate version specific links" | ||
) | ||
with open( | ||
os.path.join(os.path.dirname(__file__), "downloadsv1.6.0.json") | ||
) as infile: | ||
URL = json.load(infile) | ||
else: | ||
with open(os.path.join(os.path.dirname(__file__), 'downloads.json')) as infile: | ||
with open( | ||
os.path.join(os.path.dirname(__file__), "downloadsv1.6.0.json") | ||
) as infile: | ||
URL = json.load(infile) | ||
|
||
for x in args.input: | ||
udbfile = os.path.join(parentdir, 'DB', x+'.udb') | ||
udbfile = os.path.join(parentdir, "DB", x + ".udb") | ||
if os.path.isfile(udbfile): | ||
if not args.force: | ||
print("A formated database was found, to overwrite use '--force'. You can add more custom databases by using the `amptk database` command.") | ||
print( | ||
"A formated database was found, to overwrite use '--force'. You can add more custom databases by using the `amptk database` command." | ||
) | ||
sys.exit(1) | ||
#download | ||
# download | ||
if not x in URL: | ||
if args.force: | ||
continue | ||
print("%s not valid, choices are ITS, 16S, LSU, COI, PR2" % x) | ||
sys.exit(1) | ||
print("Downloading %s pre-formatted database" % x) | ||
# getting where some files need to be split, so check here if is a list or not | ||
# list of tar.gz files must be in proper order | ||
address = URL.get(x) | ||
if not os.path.isfile(x+'.amptk.tar.gz'): | ||
amptklib.download(address, x+'.amptk.tar.gz') | ||
tfile = tarfile.open(x+'.amptk.tar.gz', 'r:gz') | ||
if isinstance(address, list): | ||
dloads = [] | ||
for i, addy in enumerate(address): | ||
dloadname = "{}.part{}.tar.gz".format(x, i + 1) | ||
if not os.path.isfile(dloadname): | ||
amptklib.download(addy, dloadname) | ||
dloads.append(dloadname) | ||
concat_cmd = ["cat"] + dloads | ||
with open(x + ".amptk.tar.gz", "wb") as outfile: | ||
subprocess.call(concat_cmd, stdout=outfile) | ||
for f in dloads: | ||
os.remove(f) | ||
elif isinstance(address, str): | ||
if not os.path.isfile(x + ".amptk.tar.gz"): | ||
amptklib.download(address, x + ".amptk.tar.gz") | ||
# now extract and install | ||
tfile = tarfile.open(x + ".amptk.tar.gz", "r:gz") | ||
tfile.extractall(x) | ||
for file in os.listdir(x): | ||
shutil.move(os.path.join(x,file), os.path.join(parentdir, 'DB', file)) | ||
shutil.move(os.path.join(x, file), os.path.join(parentdir, "DB", file)) | ||
shutil.rmtree(x) | ||
os.remove(x+'.amptk.tar.gz') | ||
print('Extracting FASTA files for {:}'.format(x)) | ||
extracted = os.path.join(parentdir, 'DB', x+'.extracted.fa') | ||
cmd = ['vsearch', '--udb2fasta', udbfile, '--output', extracted] | ||
os.remove(x + ".amptk.tar.gz") | ||
print("Extracting FASTA files for {:}".format(x)) | ||
extracted = os.path.join(parentdir, "DB", x + ".extracted.fa") | ||
cmd = ["vsearch", "--udb2fasta", udbfile, "--output", extracted] | ||
amptklib.runSubprocess5(cmd) | ||
print("{:} taxonomy database installed to {:}".format(x, os.path.join(parentdir, 'DB'))) | ||
print( | ||
"{:} taxonomy database installed to {:}".format( | ||
x, os.path.join(parentdir, "DB") | ||
) | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters