diff 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
line wrap: on
line diff
--- a/tabpad.py	Sun Nov 24 22:35:05 2019 -0500
+++ b/tabpad.py	Mon Nov 25 15:09:24 2019 -0500
@@ -7,13 +7,24 @@
 def padfile(infile, outfile, fieldcnt=None):
     with open(infile, 'r') as fh:
         out = open(outfile, 'w')
+        commentlines = []
         tabs = '\t' * fieldcnt if fieldcnt is not None else None
-        for i, txtline in enumerate(fh):
+        def pad_line(txtline, tabs=None):
             line = txtline.rstrip('\r\n')
             fields = line.split('\t')
             if not tabs:
                 tabs = '\t' * len(fields)
             out.write('%s%s\n' % (line, tabs[len(fields):]))
+        for i, txtline in enumerate(fh):
+            if txtline.lstrip().startswith('#'):
+                commentlines.append(txtline)
+            else:
+                if commentlines:
+                    for i in range(len(commentlines)-1):
+                        out.write(commentlines[i])
+                    pad_line(commentlines[-1], tabs=tabs)
+                    commentlines = []
+                pad_line(txtline, tabs=tabs)
         out.close()