view extractHeaders.py @ 0:3de4fbd488a1 draft default tip

planemo upload commit 81955d80a45c04ad4874f19f43c36ca608b3735e
author yating-l
date Wed, 16 May 2018 17:33:35 -0400
parents
children
line wrap: on
line source

#!/usr/bin/python
""" Extract headers from Fasta file and write the headers to a Tabular file """

import sys

def extractHeaders(fasta_file, tab_file):
    
    with open(tab_file, 'w') as out:
        with open(fasta_file, 'r') as f:
            lines = f.readlines()
            for l in lines:
                if '>' in l:
                    l = l.split()
                    name = l[0].replace('>', '').rstrip()
                    desc = ''.join(l[1:]).rstrip()
                    out.write(name + '\t' + desc + '\n')
                


def main(argv):
    input_file = argv[1]
    output_file = argv[2]
    extractHeaders(input_file, output_file)

if __name__ == "__main__":
    main(sys.argv)