#! /usr/bin/env python 
###################################
#    Davi Ortega 8/22/2012 
###################################
# graduated september 2012
###################################
import sys
import bitk
import random
if '-h' in sys.argv:
	print 'Randomly select N sequences from given fasta file.\nSintaxe sel.rand.fasta fastafile.fa N'
	sys.exit()

seq_dic, seq_list = bitk.fastareader(sys.argv[1])
N = int(sys.argv[2])

new_list = random.sample(seq_list,N)

output = ''

for tag in new_list:
	output += '>' + tag + '\n' + seq_dic[tag] + '\n'

outfile = open(sys.argv[1][:-2] + 'sel.rand.' + str(N) + '.fa', 'w')
outfile.write(output)
outfile.close()



