forked from zflowers/ListMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddPath.py
More file actions
executable file
·53 lines (46 loc) · 1.91 KB
/
Copy pathaddPath.py
File metadata and controls
executable file
·53 lines (46 loc) · 1.91 KB
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
import os
import fileinput
import sys
from optparse import OptionParser
#options
parser = OptionParser()
parser.add_option("-p", "--path", dest="directory",
help="Specify input directory containing the .txt files.", metavar="PATH")
(options, args) = parser.parse_args()
directory = options.directory
if not directory:
sys.exit("You need to specify the directory! (See help).")
txtfiles=[]
fastsim_txtfiles = []
fullsim_txtfiles = []
list_name = directory.split("/")[-2]
# loop over input files
for filename in os.listdir(directory):
if filename.endswith(".txt"):
txtfiles.append(filename)
if 'SMS' in list_name:
file_path = os.path.join(directory, filename)
for line in fileinput.input(file_path, inplace=True):
print(line, end='') # Ensure lines are preserved
if 'Fast' in line or 'FS' in line:
fastsim_txtfiles.append(os.path.join("samples/NANO", list_name, filename))
else:
fullsim_txtfiles.append(os.path.join("samples/NANO", list_name, filename))
# make root text file list
if not os.path.isdir("samples/NANO/Lists/"):
os.makedirs("samples/NANO/Lists/")
txtfiles.sort()
with open(("samples/NANO/Lists/"+list_name+".list"), 'w') as filehandle:
for listitem in txtfiles:
filehandle.write(f'samples/NANO/{list_name}/{listitem}\n')
if 'SMS' in list_name:
fastsim_txtfiles = list(set(fastsim_txtfiles))
fastsim_txtfiles.sort()
with open(("samples/NANO/Lists/"+list_name+"_FastSim.list"), 'w') as filehandle:
for listitem in fastsim_txtfiles:
filehandle.write(f'samples/NANO/{list_name}/{listitem}\n')
fullsim_txtfiles = list(set(fullsim_txtfiles))
fullsim_txtfiles.sort()
with open(("samples/NANO/Lists/"+list_name+"_FullSim.list"), 'w') as filehandle:
for listitem in fullsim_txtfiles:
filehandle.write(f'samples/NANO/{list_name}/{listitem}\n')