# HG changeset patch # User devteam # Date 1594888581 0 # Node ID 4576d639d8058a7df58f4fc7a5d1239861ab0da3 # Parent 26d0d9bdbafc1133e6facddab80edcb10f67782f "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit ed2daf7024ea79a04bbb4a0896b9402ab2daf89f" diff -r 26d0d9bdbafc -r 4576d639d805 mergeCols.py --- a/mergeCols.py Wed Jun 03 14:22:15 2020 +0000 +++ b/mergeCols.py Thu Jul 16 08:36:21 2020 +0000 @@ -2,31 +2,25 @@ def __main__(): - try: - infile = open(sys.argv[1], 'r') - outfile = open(sys.argv[2], 'w') - except Exception: - sys.exit('Cannot open or create a file\n') - if len(sys.argv) < 4: sys.exit('No columns to merge\n') else: cols = sys.argv[3:] - skipped_lines = 0 + with open(sys.argv[1], 'r') as infile, open(sys.argv[2], 'w') as outfile: + skipped_lines = 0 + for line in infile: + line = line.rstrip('\r\n') + if line and not line.startswith('#'): + fields = line.split('\t') + line += '\t' + for col in cols: + try: + line += fields[int(col) - 1] + except Exception: + skipped_lines += 1 - for line in infile: - line = line.rstrip('\r\n') - if line and not line.startswith('#'): - fields = line.split('\t') - line += '\t' - for col in cols: - try: - line += fields[int(col) - 1] - except Exception: - skipped_lines += 1 - - print(line, file=outfile) + outfile.write("{}\n".format(line)) if skipped_lines > 0: print('Skipped %d invalid lines' % skipped_lines) diff -r 26d0d9bdbafc -r 4576d639d805 mergeCols.xml --- a/mergeCols.xml Wed Jun 03 14:22:15 2020 +0000 +++ b/mergeCols.xml Thu Jul 16 08:36:21 2020 +0000 @@ -1,18 +1,18 @@ - + together python - - mergeCols.py - "${input1}" - "${out_file1}" - "${col1}" - "${col2}" - #for $col in $columns - ${col.datacol} - #end for - +