Skip to content

Commit

Permalink
re-implement nonltr
Browse files Browse the repository at this point in the history
  • Loading branch information
lee212 committed Feb 17, 2016
1 parent e68403c commit 8193304
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
6 changes: 4 additions & 2 deletions mgescan/nonltr/hmm/hmm_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,14 @@ void get_hydro(int start, int end, double *score, char *O){
}
memset(seq, '\0', 20000);

strcpy(temp_file1, out_dir);
//strcpy(temp_file1, out_dir);
strcpy(temp_file1, "/tmp/");
strcat(temp_file1, "ppppp.XXXXXX");
int fd1;
fd1 = mkstemp(temp_file1);

strcpy(temp_file2, out_dir);
//strcpy(temp_file2, out_dir);
strcpy(temp_file2, "/tmp/");
strcat(temp_file2, "qqqqq.XXXXXX");
int fd2;
fd2 = mkstemp(temp_file2);
Expand Down
58 changes: 53 additions & 5 deletions mgescan/nonltr/nonltr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ class NonLTR(object):
ver = 'MGEScan NonLTR 3.0.0'
mpi_cmd = "mpi_mgescan"
hmmerv = "3"
tag_for_backward = "_b"

def __init__(self):
self.set_inputs()
self.get_env()
self.set_param()
self.set_cmd()

def set_cmd(self):
self.run_hmm_cmd = self.base_path + "nonltr/" + "run_hmm.pl"
self.run_post_cmd = self.base_path + "nonltr/" + "post_process.pl"
self.run_post2_cmd = self.base_path + "nonltr/" + "post_process2.pl"

def get_env(self):
self.base_path = os.environ.get("MGESCAN_SRC") + "/mgescan/"
Expand All @@ -38,8 +43,9 @@ def set_param(self):
self.p_prg = "--prg " + self.name
self.p_mgescan_mpi_cmd = self.base_path + self.mpi_cmd
self.p_genome_f = "--genome " + self.genome_path
self.p_genome_b = "--genome " + self.genome_path + self.tag_for_backward
self.p_data = "--data " + self.output_path
self.p_genome_b = "--genome " + self.genome_path + "_b"
self.p_data_f = "--data " + self.output_path + "/f/"
self.p_data_b = "--data " + self.output_path + "/b/"
self.p_hmmerv = "--hmmerv " + self.hmmerv
self.set_mpi_option()

Expand All @@ -54,18 +60,57 @@ def read_mpi_host_file(self):
self.p_hf_option = ""

def forward(self):
utils.create_directory(self.output_path, False)
if self.nmpi:
cmd = self._padding("mpirun", self.p_np, self.p_mpi_option,
self.p_mgescan_mpi_cmd, self.p_prg, self.p_genome_f,
self.p_data, self.p_hmmerv)
self.p_data_f, self.p_hmmerv)
self.run_cmd(cmd)
else:
from os import listdir
from os.path import isfile, join
mypath = self.genome_path
for f in listdir(mypath):
fpath = join(mypath, f)
if isfile(fpath):
p = Process(target=self.run_hmm, args=("forward", fpath,))
p.start()
self.post_process("forward")

def post_process(self, t):
if t == "forward":
cmd = self.run_post_cmd + " --dna=" + self.genome_path + " --out=" + self.output_path + "/f/" + " --rev=0"
elif t == "backward":
cmd = self.run_post_cmd + " --dna=" + self.genome_path + " --out=" + self.output_path + "/b/" + " --rev=1"
self.run_cmd(cmd)

def run_hmm(self, t, fname):
if t == "forward":
cmd = self.run_hmm_cmd + " --dna=" + fname + " --out=" + self.output_path + "/f/" + " --hmmerv=" + self.hmmerv
elif t == "backward":
cmd = self.run_hmm_cmd + " --dna=" + fname + " --out=" + self.output_path + "/b/" + " --hmmerv=" + self.hmmerv
self.run_cmd(cmd)

def post_process2(self):
cmd = self.run_post2_cmd + " --data_dir=" + self.output_path + " --hmmerv=" + self.hmmerv
self.run_cmd(cmd)

def backward(self):
if self.nmpi:
cmd = self._padding("mpirun", self.p_np, self.p_mpi_option,
self.p_mgescan_mpi_cmd, self.p_prg, self.p_genome_b,
self.p_data, self.p_hmmerv)
self.p_data_b, self.p_hmmerv)
self.run_cmd(cmd)
else:
from os import listdir
from os.path import isfile, join
mypath = self.genome_path + "_b"
for f in listdir(mypath):
fpath = join(mypath, f)
if isfile(fpath):
p = Process(target=self.run_hmm, args=("backward",fpath,))
p.start()
self.post_process("backward")

def _padding(self, *args):
res = ""
Expand All @@ -75,6 +120,7 @@ def _padding(self, *args):
return res[1:]
else:
return res

def run_cmd(self, cmd):
print cmd
return
Expand Down Expand Up @@ -105,6 +151,8 @@ def run(self):
if 'p2' in locals():
p2.join()

self.post_process2()

if __name__ == '__main__':
obj = NonLTR()
obj.run()

0 comments on commit 8193304

Please sign in to comment.