Mercurial > repos > dcouvin > pmlst_v2
comparison pmlst/pmlst_db/INSTALL.py @ 0:cfab64885f66 draft default tip
Uploaded
author | dcouvin |
---|---|
date | Mon, 06 Sep 2021 18:27:45 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cfab64885f66 |
---|---|
1 #!/usr/bin/python3 | |
2 import shutil, os, sys | |
3 | |
4 # This scripts installs the pMLST database for using KMA | |
5 # KMA should be installed before running this script | |
6 # The scripts assumes that it is placed together with the pMLST scheme fasta files | |
7 # First clone the repository: git clone https://bitbucket.org/genomicepidemiology/pmlst_db.git | |
8 | |
9 # Check if executable kma_index program is installed, if not promt the user for path | |
10 | |
11 interactive = True | |
12 if len(sys.argv) >= 2: | |
13 kma_index = sys.argv[1] | |
14 if "non_interactive" in sys.argv: | |
15 interactive = False | |
16 else: | |
17 kma_index = "kma_index" | |
18 | |
19 while shutil.which(kma_index) is None: | |
20 if not interactive: | |
21 sys.exit("KMA index program, {}, does not exist or is not executable".format(kma_index)) | |
22 ans = input("Please input path to executable kma_index program or enter 'q'/'quit' to exit:") | |
23 if ans == "q" or ans == "quit": | |
24 print("Exiting!\n\n \ | |
25 Please install executable KMA programs in order to install this database.\n\n \ | |
26 KMA can be obtained from bitbucked:\n\n\ | |
27 git clone https://bitbucket.org/genomicepidemiology/kma.git\n\n\ | |
28 KMA programs must afterwards be compiled:\n\n\ | |
29 gcc -O3 -o kma KMA.c -lm -lpthread\n\ | |
30 gcc -O3 -o kma_index KMA_index.c -lm") | |
31 sys.exit() | |
32 | |
33 kma_index = ans | |
34 | |
35 if shutil.which(kma_index) is None: | |
36 print("Path, {}, is not an executable path. Please provide absolute path\n".format(ans)) | |
37 | |
38 | |
39 # Index databases | |
40 | |
41 | |
42 # Use config_file to go through database files | |
43 dirname = os.path.dirname(sys.argv[0]) | |
44 | |
45 config_file = open(os.path.join(dirname, "config"), "r") | |
46 for line in config_file: | |
47 if line.startswith("#"): | |
48 continue | |
49 else: | |
50 line = line.rstrip().split("\t") | |
51 scheme = line[0] | |
52 f = os.path.join(dirname, scheme) + ".fsa" | |
53 if not os.path.isfile(f): | |
54 sys.exit("Database file '{}' does not exists".format(f)) | |
55 # for each dir index the fasta files | |
56 os.system("{} -i {} -o {}".format(kma_index, f, os.path.join(dirname, scheme))) | |
57 | |
58 config_file.close() | |
59 | |
60 print("Done") | |
61 |