-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathto_libraries.py
More file actions
executable file
·39 lines (32 loc) · 1.24 KB
/
to_libraries.py
File metadata and controls
executable file
·39 lines (32 loc) · 1.24 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
#!/usr/bin/env python3
from Bash import mkdir_p
from os import listdir
from os import rename
from os.path import join
from os.path import basename
from sys import argv
from os.path import isfile
# Script to enter large raw directory for Illumina data, then split the files
# into sub-directories according to the first chunk of their names (the library
# name). This facilitates read grouping and individual analysis of samples.
exclusions = []
def main(directory):
filenames = [x for x in listdir(directory) if isfile(join(directory, x))]
for exclusion in exclusions:
for filename in list(filenames):
if exclusion in filename:
filenames.remove(filename)
libraries = list(set([basename(x).split("_")[0] for x in filenames]))
[mkdir_p(join(directory, f)) for f in libraries]
for lib in libraries:
for filename in filenames:
if "{}_".format(lib) in filename:
initial = join(directory, filename)
library = join(directory, lib)
final = join(library, filename)
try:
rename(initial, final)
except Exception as err:
print(err)
if __name__ == "__main__":
main(argv[1])