def cleanUpExecution( self, cmd, stdout, stderr, errcode ): """ Args: cmd: stdout: stderr: errcode: """ LE.debug(StringIO(stdout)) if errcode: LE.error(StringIO(stderr)) raise Exception( "CMD [{0}] exit with status [{1}]".format(cmd, errcode))
def execCommand( self, cmd ): """ Args: cmd: """ origcmd = cmd LE.debug("Running command: [{0}]".format(cmd)) cmd = shlex.split(cmd) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() errcode = p.wait() LE.debug(StringIO(stdout)) if errcode: LE.error(StringIO(stderr)) raise Exception( "CMD [{0}] exit with status [{1}]".format(origcmd, errcode))
def map(self): for i in self.readgroups: fq1 = self.tmpdir + "/" + i + "-A.fq" fq2 = self.tmpdir + "/" + i + "-B.fq" output = open(self.tmpdir + "/" + i + ".sam", "w") p = COMPASSCFG["tools"]["bwa"].popen( append="mem -R '@RG\\tID:{0}' {1} {2} {3} -L 20 -B 3 -O 6 -T 20" .format(i, self.ref, fq1, fq2), stderr=subprocess.PIPE, stdout=output) self.commandsHistory.append(p.cmd) LE.debug(p.stderr, "stderr") errcode = p.wait() if errcode: LE.error("BWA tool failed") raise Exception("BWA tool failed") os.unlink(fq1) os.unlink(fq2) output = self.tmpdir + "/" + i + ".sam" self.insertsizes[i] = self.generateSeqStats(output)
if not args.fq1 or (args.fq2 and args.shuffled): print( "You must specify at least one FastQ File(fq1). If you specify two -s parameter is not compatible" ) sys.exit(0) if args.header: LE.info("Reading header from {0}".format(args.header)) if args.rgroup == "UNKNOWN": head = open(args.header).read() if '@RG' in head: args.rgroup = re.findall( "[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}", head, re.I)[0] else: LE.error("Can not find read group on header file") md = COMPASSCFG['tools']['samtools'].popen( append="view -h -S -b -o {0} -".format(args.output), stderr=subprocess.PIPE, stdin=subprocess.PIPE) SamFile = Fq2Sam(open(args.header).read(), args.rgroup, args.fq1, args.fq2, md.stdin, shuffled=args.shuffled) else: try: rg, pl, lib, sn, cn = args.headerinfo.split(",") except: LE.error(
def dumpStdError(self): self.stderror.seek(0) LE.error(self.stderror)