def process_times(filename):
"""
Remove the path (dirname) from the second field of the 'times' file.
"""
try:
f=open(filename,'r')
for linenum,line in enumerate(f):
err = "input error in '%s' line %d: " % (filename, linenum+1)
line = line.strip()
flds = line.split('\t')
if len(flds) != 11:
sys.exit(err + "expecting 11 fields, found %d - is this a " \
"'poretools times' file?" % (len(flds)))
# First line: validate, then print as-is
if linenum==0:
if flds[0] != "channel":
sys.exit(err + "expecting header line (first word: " \
"'channel') - is this a 'poretools times' file?")
print '\t'.join(flds)
continue
# other lines - remove path from second field.
flds[1] = basename(flds[1])
print '\t'.join(flds)
except IOError as e:
if e.errno == errno.EPIPE:
sys.exit(0) # exit silently
# TODO: this is a cop-out, hard to tell what's the exact error
# and give informative,useful error message to the user.
sys.exit("I/O error: %s" % (str(e)))
poretools-basenames.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录