view reformat.py @ 2:13999e95b2d3 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/crt commit 4241c1d4b05a177bd2c74f5a139f51d4f65e0b55
author bgruening
date Tue, 13 Jun 2017 10:42:52 -0400
parents db0f5c1cb227
children
line wrap: on
line source

#!/usr/bin/env python

"""
    Extract importent information from the standard output file and put it in some standard format, like BED and tabular.
"""

import sys

bed = open(sys.argv[2], 'w+')
tabular = open(sys.argv[3], 'w+')

for line in open(sys.argv[1]):
    # ORGANISM:  gi|21226102|ref|NC_003901.1| Methanosarcina mazei Go1 chromosome, complete genome
    if line.startswith('ORGANISM:'):
        organism = line.lstrip('ORGANISM:').strip()
    # CRISPR 1   Range: 679197 - 682529
    if line.startswith('CRISPR '):
        start,end = line.split('Range:')[1].strip().split('-')
        start = start.strip()
        end = end.strip()
        bed.write('%s\t%s\t%s\n' % (organism, start, end))
    if line.rstrip().endswith(']'):
        cols = line.split()
        tabular.write("%s\t%s\t%s\t%s\t%s\t%s\n" % (organism, cols[0], cols[1], cols[2], cols[4].rstrip(','), cols[5]))