forked from mossmatters/HybPiper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.py
54 lines (39 loc) · 1.69 KB
/
cleanup.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
#!/usr/bin/env python
helptext ='''Cleanup Script for HybSeqPipeline
The structured directory system generated by HybSeqPipline generates a lot ot of files.
Many of these files are not needed for downstream analysis, and can be safely removed.
The options will allow you to specify which of the unneeded files you wish to delete.
'''
import argparse,os,sys,shutil
def list_sub_dirs(parentdir):
'''Given a parent directory return a list of all subdirectories'''
return next(os.walk(parentdir))[1]
def remove_velvet():
'''In the current directory, remove all directories that begin with 'velvet' '''
velvet_dirs = [v for v in os.listdir(".") if v.startswith("velvet") and os.path.isdir(v)]
for v in velvet_dirs:
shutil.rmtree(v)
def remove_spades():
'''In the current directory, remove the spades directory.'''
spades_dirs = [s for s in os.listdir(".") if s.endswith("spades") and os.path.isdir(s)]
for s in spades_dirs:
shutil.rmtree(s)
def main():
parser = argparse.ArgumentParser(description=helptext,formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("prefix",metavar="prefix",help="Directory generated by HybSeqPipeline.")
if len(sys.argv) < 2:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
try:
os.chdir(args.prefix)
gene_dirs = list_sub_dirs('.')
print("Found {} gene directories".format(len(gene_dirs)))
except OSError:
print("Directory '{}' does not exist!".format(args.prefix))
sys.exit(1)
for gene in gene_dirs:
os.chdir(gene)
remove_spades()
os.chdir("..")
if __name__ == "__main__":main()