-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpilercr_wrapper.py
More file actions
56 lines (38 loc) · 1.5 KB
/
pilercr_wrapper.py
File metadata and controls
56 lines (38 loc) · 1.5 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
54
55
56
'''
Wrapper script for Piler-CR, an ab-initio tool for detecting CRISPR spaces and repeats in bacterial genome.
Piler-CR requires contig fasta files as input. We will be using the contig files generated by the Genome Assembly group.
WARNING: Using "gene" sequences will not give the desired results.
'''
#!/usr/bin/env python
import subprocess,os,sys
def pilercr_runner(input_directory_path,contig_file,output_directory_path):
#Creating file path
input_file=input_directory_path + contig_file
#Creating a subdirectory in the output directory
output_subdir=output_directory_path+"pilercr/"
#Creating output file
mod_contig_file_name=contig_file.replace(".fasta","_crispr")
output_file=output_subdir+mod_contig_file_name
#Checking if the subdirectory exists
if not "pilercr" in os.listdir(output_directory_path):
os.mkdir(output_subdir)
#Executing PilerCR
try:
print("Running PilerCR for "+contig_file)
pilercr_output=subprocess.check_output(["pilercr", "-in", input_file, "-out",output_file, "-noinfo", "-quiet"])
except subprocess.CalledProcessError as err:
print("Error running PilerCR. Check the input files")
print("Error thrown: "+err.output)
return False
print("Completed running PilerCR")
return True
def main():
inputpath=sys.argv[1]
outputpath=sys.argv[2]
files=os.listdir(inputpath)
if len(files) == 0:
print("No files present in the directory.")
for name in files:
pilercr=pilercr_runner(inputpath,name,outputpath)
if __name__ == "__main__":
main()