# Beginners Python procedure return value problem

Trouble you heroes help have a look what the return value of this program is not zero??? Thank you！

#! /usr/bin/python

import re
import os
import sys
import gzip

def rmN(Args):
if not Args:
print 'Usage: rmN <in.fq> <max_N_ratio><outfile>'
print 'Max_N_ratio [float] , e.g. 0.05'
sys.exit(0)
if re.search('gz\$|gzip\$', Args[0]):
infile = gzip.open(Args[0], 'rb')
else:
infile = open(Args[0], 'r')
maxN = float(Args[1])
outfile = Args[-1]
#fqname = os.path.basename(Args[0]).replace('.gz', '')
#fqname = fqname.replace(fqname.split('.')[-1], 'fq')
remain = open(outfile, 'w')
#remove = open(Args[-1] + '/removed_N_' + fqname, 'w')
#remove_log = open(outfile + '.log', 'w')
while True:
break
seqlen = len(seq)
N_count = seq.count('N')
N_ratio = float(N_count) / seqlen
if N_ratio <= maxN:
# remain.write('%s\n%s\n%s\n%s\n' %(readid, seq, mark, qual))
else:
infile.close()
remain.close()

if __name__ == '__main__':
if len(sys.argv) > 1:
rmN(sys.argv[1:])
#sys.exit(0)
else:
print 'Usage: rmN <in.fq> <max_N_ratio><outfile>'
print 'Max_N_ratio [float] , e.g. 0.05'
sys.exit(0)

Started by Jane at February 08, 2016 - 11:23 PM

What's the return value? return

Posted by Sidon at February 17, 2016 - 12:00 AM

def run_cmd(cmd_str):
"""
Throw exception if run command fails
"""
#process = subprocess.Popen(cmd_str, stdout = subprocess.PIPE,stderr = subprocess.PIPE, shell = True)
process = subprocess.Popen(cmd_str, stdout = subprocess.PIPE,stderr = subprocess.STDOUT, shell = True)
stdout_str, stderr_str = process.communicate()
if process.returncode != 0:
raise Exception("Failed to run '%s'\n%s%sNon-zero exit status %s" %(cmd_str, stdout_str, stderr_str, process.retu
rncode))

I define such a function, used to run the program always wrong Non-zero exit status 126

Posted by Jane at March 01, 2016 - 12:41 AM

Can't do this assignment
1. stdout_str, stderr_str = process.communicate()
process.communicate()Returns an array of objects

Posted by Andra at March 11, 2016 - 12:52 AM

I run the other functions are not submitted to this fault.

Posted by Jane at March 12, 2016 - 1:13 AM

I run the other functions are not submitted to this fault.

Posted by Jane at March 18, 2016 - 1:25 AM