Mercurial > repos > devteam > convert_characters
diff convert_characters.py @ 0:3100886bf698 draft
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/convert_characters commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
author | devteam |
---|---|
date | Mon, 09 Nov 2015 11:25:21 -0500 |
parents | |
children | 81a6c3de5de3 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/convert_characters.py Mon Nov 09 11:25:21 2015 -0500 @@ -0,0 +1,42 @@ +#!/usr/bin/env python +#By, Guruprasad Ananda. + +from galaxy import eggs +import sys, re + +def stop_err(msg): + sys.stderr.write(msg) + sys.exit() + +def main(): + if len(sys.argv) != 4: + stop_err("usage: convert_characters infile from_char outfile") + + try: + fin = open(sys.argv[1],'r') + except: + stop_err("Input file cannot be opened for reading.") + + from_char = sys.argv[2] + + try: + fout = open(sys.argv[3],'w') + except: + stop_err("Output file cannot be opened for writing.") + + char_dict = {'T':'\t','s':'\s','Dt':'\.','C':',','D':'-','U':'_','P':'\|','Co':':'} + from_ch = char_dict[from_char] + '+' #making an RE to match 1 or more occurences. + skipped = 0 + + for line in fin: + line = line.strip() + try: + fout.write("%s\n" %(re.sub(from_ch,'\t',line))) + except: + skipped += 1 + + if skipped: + print "Skipped %d lines as invalid." %skipped + +if __name__ == "__main__": + main() \ No newline at end of file