annotate pmlst/pmlst_db/INSTALL.py @ 0:cfab64885f66 draft default tip

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