Guest User

Untitled

a guest
Dec 13th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from pipeline.bin.fastaSplit import fastaCut
  4. from pipeline.config import *
  5. from pipeline.lib.shell import *
  6. from pipeline.lib.system import *
  7. from pipeline.software.software import *
  8.  
  9. LOG = logging.getLogger(__name__)
  10.  
  11.  
  12. def HPCblast(cut_num, query, db, task, out="", cwd="", num_threads=3, done="blast.done", **params):
  13. """
  14.  
  15. :param query:
  16. :param db:
  17. :param cut_num: cut number
  18. :param out: blast out file
  19. :param out_dir: output dir of tmp
  20. :param num_threads: cpus used to blast, see more details in blastn -help
  21. :param done: done filename, default is "blast.done"
  22. :param params: other blast param in ALLOWED_BLAST_PARAMS
  23. :return: done filename
  24. """
  25. query, db = check_paths(query, db)
  26. cwd = os.path.abspath(cwd)
  27.  
  28. if task not in BLAST_TASK:
  29. msg = "not allowed blast task %r" % task
  30. LOG.error(msg)
  31. raise Exception(msg)
  32. if cwd:
  33. cwd = mkdir(cwd)
  34.  
  35. params = dict(params)
  36. params.update({"query": query, "db": db, "out": out, "num_threads": num_threads})
  37. LOG.info("running blast with %r " % params2str(params))
  38.  
  39. done = "%s/%s" % (cwd, done)
  40. # check for rerun
  41. if os.path.exists(done):
  42. LOG.info("%s has exists, pass blast step" % done)
  43. return done
  44.  
  45. # cut query file
  46. cut_cwd = mkdir("%s/%s.cut" % (cwd, os.path.basename(query)))
  47. cut_files = fastaCut(query, cut_num, mode="size", cwd=cut_cwd)
  48.  
  49. if not out:
  50. out = query+".blast"
  51.  
  52. # make blast database
  53. cmd = makeblastdb(input_file=db, dbtype=BLAST_TASK[task]["dbtype"])
  54. #os.system(cmd)
  55.  
  56. done_files = []
  57. out_files = []
  58.  
  59. # qsub blast script to
  60. for i in range(len(cut_files)):
  61. file = cut_files[i]
  62. out_dir = mkdir("%s/job_%s" % (cwd, i+1))
  63. out_fn = "%s/%s.blast" % (out_dir, os.path.basename(file))
  64. done_fn = out_fn+".done"
  65. if os.path.isfile(done_fn):
  66. LOG.info("%s.sh had done, pass it" % os.path.basename(out_fn))
  67. else:
  68. params.update({"task": task, "query": file, "db": db, "out": out_fn, "num_threads": num_threads})
  69. script = script_run_blast(params)
  70. script_name = write_script(script, out_fn+".sh", done_fn)
  71. qsub(cpu=num_threads, queue=QUEUE, script=script_name)
  72. done_files.append(done_fn)
  73. out_files.append(out_fn)
  74.  
  75.  
  76. # check blast status
  77. LOG.info("check blast status")
  78. check_status(done_files, 120)
  79.  
  80. LOG.info("blast done")
  81. cat(out_files, out)
  82. touch(done)
  83.  
  84. return out
  85.  
  86.  
  87. def main():
  88. pass
  89.  
  90. if __name__ == "__main__":
  91. main()
Add Comment
Please, Sign In to add comment