comparison tabpad.py @ 2:9a01840eac52 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cat commit 6b978e61a7f66160f2577d907f52dd641f103986-dirty
author jjohnson
date Mon, 25 Nov 2019 15:09:24 -0500
parents ad7507073c3f
children
comparison
equal deleted inserted replaced
1:86cd2e70b0dc 2:9a01840eac52
5 5
6 6
7 def padfile(infile, outfile, fieldcnt=None): 7 def padfile(infile, outfile, fieldcnt=None):
8 with open(infile, 'r') as fh: 8 with open(infile, 'r') as fh:
9 out = open(outfile, 'w') 9 out = open(outfile, 'w')
10 commentlines = []
10 tabs = '\t' * fieldcnt if fieldcnt is not None else None 11 tabs = '\t' * fieldcnt if fieldcnt is not None else None
11 for i, txtline in enumerate(fh): 12 def pad_line(txtline, tabs=None):
12 line = txtline.rstrip('\r\n') 13 line = txtline.rstrip('\r\n')
13 fields = line.split('\t') 14 fields = line.split('\t')
14 if not tabs: 15 if not tabs:
15 tabs = '\t' * len(fields) 16 tabs = '\t' * len(fields)
16 out.write('%s%s\n' % (line, tabs[len(fields):])) 17 out.write('%s%s\n' % (line, tabs[len(fields):]))
18 for i, txtline in enumerate(fh):
19 if txtline.lstrip().startswith('#'):
20 commentlines.append(txtline)
21 else:
22 if commentlines:
23 for i in range(len(commentlines)-1):
24 out.write(commentlines[i])
25 pad_line(commentlines[-1], tabs=tabs)
26 commentlines = []
27 pad_line(txtline, tabs=tabs)
17 out.close() 28 out.close()
18 29
19 30
20 def fieldcount(infile): 31 def fieldcount(infile):
21 fieldcnt = 0 32 fieldcnt = 0