-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakeKSNP4infile.py
executable file
·62 lines (49 loc) · 1.59 KB
/
MakeKSNP4infile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
"""
Description: Writes a kSNP4 infile for the files in the target directory. Must be run from
within the directory ENCLOSING the target directory
Usage: MakeKSNP4infile -indir Target directory -outfile name of outfile [S] where
S is an optional argument for the semi-automatic mode. The mode is A for automatic by default
"""
#********************* MODULES**********************
import sys
import os
#******************* FUNCTION DEFINITIONS *******************
#********************** Main *************************
#variables
mode = 'A' #A is the automtic mode, the alternative is S
indir = ''
outfile = ''
home = os.getcwd()
thisPath = ''
genomeID = ''
Files = [] #list of files in target directory
fileList = [] #col0 is path col1 is file name
numElements = 0
#get command line arguments
for i in range(1, len(sys.argv)):
if sys.argv[i] == '-indir':
indir = sys.argv[i+1]
if sys.argv[i] == '-outfile':
outfile = sys.argv[i+1]
if sys.argv[i] == 'S':
mode = 'S'
os.chdir(indir) #make the target directory the cwd
thePath = os.getcwd()
#print(thePath)
#print('After changing to the input directory the path is now {0}\n'.format(thePath))
#get the list of files
Files = os.listdir('.')
for file in Files:
if not file.startswith('.'):
#sys.stdout.write("{0}\n".format(file))
thePath = os.path.abspath(file)
temp = file.split('.')
genomeID = temp[0]
fileList.append([thePath, genomeID])
#print(Files[0])
os.chdir(home)
OUTFILE = open(outfile, 'w')
for i in range(len(fileList)):
OUTFILE.write('{0}\t{1}\n'.format(fileList[i][0], fileList[i][1]))
OUTFILE.close()