-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
47 lines (39 loc) · 1.04 KB
/
utils.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 1/4/2022 3:13 PM
# @Author : Runsheng
# @File : utils.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2016/12/8 16:58
# @Author : Runsheng
# @File : utils.py
import subprocess
import sys
import signal
import os
import fnmatch
import multiprocessing
import unittest
import gzip
from Bio import SeqIO
#### logger init
import logger
LOGGER=logger.get_logger()
####
def myexe(cmd, timeout=0):
"""
a simple wrap of the shell
mainly used to run the bwa mem mapping and samtool orders
"""
def setupAlarm():
signal.signal(signal.SIGALRM, alarmHandler)
signal.alarm(timeout)
def alarmHandler(signum, frame):
sys.exit(1)
LOGGER.info("running %s" % cmd)
proc=subprocess.Popen(cmd, shell=True, preexec_fn=setupAlarm,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,cwd=os.getcwd())
out, err=proc.communicate()
LOGGER.info(( err, "Run finished with return code:", proc.returncode))
return out