#!/usr/bin/ipython
; -*- mode: python -*- 

import sys
import os

## This is the master script to call all scripts for analysis of ESX genes
## present in each species
## INPUT: 
##	-NCBI nucleotide sequence of species with all ESX genes (M.tb)
##	-Directory of blast results from blasting NCBI sequence with
##	 all species to be used in analysis 
##	 ***File names in blast results directory should match the file names 
##	 of PROKKA annotation files for the species***
##	-File containing the names of all the ESX gene (one per line)
##	-File containing the last four (or less) letters of the PROKKA
##	 annotation file names (one per line)
##	-groups.txt file of the orthomcl run of all species 

def usage():
    print "extract_headers.ipy\n \
        <NCBI FASTA nucleotide sequence>\n \
	<blast results directory>\n \
	<file of gene names>\n \
	<file of last four letters of PROKKA annotation directory names>\n \
	<groups.txt file from orthoMCL output>"

if len(sys.argv) != 6:
    usage()
search_file = sys.argv[1]
blast_dir = sys.argv[2]
gene_file = sys.argv[3]
species_file = sys.argv[4]
groups_file = sys.argv[5]

## Find NC numbers corresponding to gene names
!/home/aweber/scripts/T7SS/SpeciesESXgenes/geneToNC.ipy {search_file} {gene_file}

## Search for NC number in blast results
!/home/aweber/scripts/T7SS/SpeciesESXgenes/searchBlastFiles.ipy {blast_dir} ./codes/ 

## Create codes used by orthoMCL from blast results
!/home/aweber/scripts/T7SS/SpeciesESXgenes/orthoCodes.ipy ./blast_search/

## Create a file for each gene with its orthologous groups
!/home/aweber/scripts/T7SS/SpeciesESXgenes/orthoGeneGroups.ipy ./ortho_codes/ {groups_file}

## Create files of genes present in each species
!/home/aweber/scripts/T7SS/SpeciesESXgenes/bySpecies.ipy ./ortho_byGene/ {species_file}

!rm -r blast_search
!rm -r codes
!rm -r genes
!rm -r ortho_codes