#! /usr/bin/env python 
###################################
##    Davi Ortega                ##
###################################
import bitk
import sys

if '-h' in sys.argv:
	print 'Reads list generated by getorganism.py and delete the sequences from the given alignment of the organisms in the list\n\n\tSintaxe: python delorganism.py file.list alignment.fa'
	sys.exit()

listfile = open(sys.argv[1],'r')

list_org = []
for line in listfile:
	list_org.append(line.replace('\n',''))

seq_dic = bitk.fastareader(sys.argv[2])

for name in seq_dic.keys():
	name_org = name.split('-')[0]
	for organism in list_org:
		if organism == name_org:
			del seq_dic[name]

output = ''
for name, seq in seq_dic.iteritems():
	output += '>' + name + '\n' + seq + '\n'

datafile = open(sys.argv[2][:-3] + '.new.fa', 'w')
datafile.write(output)
datafile.close()
listfile.close()
		
