#!/usr/bin/python # -*- coding:utf-8 -*- '''Convert primers in RTPrimerDB into FASTA format The CSV file wad downloaded from: http://medgen.ugent.be/rtprimerdb/index.php?downloads PATTYN, F., SPELEMAN, F., DE PAEPE A. & VANDESOMPELE, J. (2003). RTPrimerDB: the Real-Time PCR primer and probe database. Nucleic Acids Research, 31(1): 122-123. by Wubin Qu , Copyright @ 2010, All Rights Reserved. ''' Author = 'Wubin Qu CZlab, BIRM, China' Date = 'Mar-08-2011 09:39:27' License = 'New-BSD License' Version = '1.0' import sys import os import re from optparse import OptionParser def get_opt(): '''Handle options''' usage = 'Usage: %prog -i InFile -o OutFile' version = '%prog Version: ' + '%s [%s]' % (Version, Date) parser = OptionParser(usage=usage, version=version) parser.add_option('-i', '--infile', dest='infile', help='Input file name. [String]') parser.add_option('-o', '--outfile', dest='outfile', help='Output file name. [String]') [options, args] = parser.parse_args() if len(args) > 1: parser.error('Incorrect argument, add" "-h" for help.') if not options.infile: parser.error('Infile needed, add" "-h" for help.') if not options.outfile: parser.error('OutFile needed, add" "-h" for help.') return options def main (): '''Main''' options = get_opt() fh = open(options.outfile, 'w') for line in open(options.infile): line = line.strip() if not re.match('(\d+)', line): continue fields = line.split('\t') rt_id = fields[0] fp = fields[8] rp = fields[7] if not (fp and rp): continue fh.write('>%s_fp\n%s\n>%s_rp\n%s\n' % (rt_id, fp, rt_id, rp)) fh.close() if __name__ == '__main__': main()