#!/bin/bash


#Blastinator 1.0.1; de Dios-Martinez A, Gordo-Baste M, Llopart-Ventura A, Marti i Sais X. Bioinformatics UPF 2015,

# Gavilials Gangeticus selenoproteom project

#_________________________________________________________________________________________________________________________

#_________________________________________________________________________________________________________________________

#_________________________________________________________________________________________________________________________

#_________________________________________________________________________________________________________________________

#_________________________________________________________________________________________________________________________

echo "Blastinator 1.0.1; de Dios-Martinez A, Gordo-Baste M, Llopart-Ventura A, Marti i Sais X. Bioinformatics UPF 2015,

Gavilials Gangeticus selenoproteom project"

echo "This progamme might have all python scripts in its folder"

echo "The programme may also create new folders"

echo "Remember to delete the previous Blastinator_data folder before runing the script for an other specie"

echo "Remember to delete #, % and other strange symbols from your query"

echo "Awsome Ascii titles at http://www.network-science.de/ascii/"

echo "Special thanks to Juan Carlos, Didac, Gireesh, Ramon and Neus"

#_________________________________________________________________________________________________________________________

#_________________________________________________________________________________________________________________________

#_________________________________________________________________________________________________________________________

echo "Exporting package"

#Its necessary to download:



export PATH=/cursos/BI/bin:$PATH #fastaseqfromGFF.pl

export PATH=/cursos/BI/bin/ncbiblast/x64/bin:$PATH #NCBI Blast

cp /cursos/BI/bin/ncbiblast/.ncbirc ~/ #NCBI Blast

export PATH=/cursos/BI/soft/exonerate/x86_64/bin:$PATH #exonerate

export PATH=/cursos/BI/soft/t_coffee/x86_64/bin:$PATH #t_coffee

export PATH=/cursos/BI/soft/genewise/x86_64/bin:$PATH #GeneWise

export WISECONFIGDIR=/cursos/BI/soft/genewise/x86_64/wise2.2.0/wisecfg/ #GeneWise



echo "Done"

#_________________________________________________________________________________________________________________________

#_________________________________________________________________________________________________________________________

#_________________________________________________________________________________________________________________________



FILE=$1 #Must be opened in the current directory

SPECIE=$2 #"Enter the full path"

#_________________________________________________________________________________________________________________________

#_________________________________________________________________________________________________________________________

#_________________________________________________________________________________________________________________________



mkdir Blastinator_data

mkdir Blastinator_data/Blastall_output

mkdir Blastinator_data/Corrected_blast

mkdir Blastinator_data/Pre_fastafetch

mkdir Blastinator_data/Fastafetch_output

mkdir Blastinator_data/Coordinates_fastasubseq

mkdir Blastinator_data/Fastasubseq_output

mkdir Blastinator_data/Translated_query

mkdir Blastinator_data/Exonerate_output

mkdir Blastinator_data/FastaseqfromGFF_output

mkdir Blastinator_data/Hipothetic_selenoprot

mkdir Blastinator_data/Fitxerint1

mkdir Blastinator_data/Fitxerint2

mkdir Blastinator_data/Fitxerint3

mkdir Blastinator_data/Fitxerint4

mkdir Blastinator_data/Fitxerint5

mkdir Blastinator_data/Fitxerint6

mkdir Blastinator_data/Exonerate_whole

mkdir Blastinator_data/Hipothetic_aa

mkdir Blastinator_data/Tcofee_input

mkdir Blastinator_data/Tcofee



#==================================================================================================================================

#======================================================================================================================================

echo "Starting tblastn"

#contador=1

for query in $FILE/* ; do {



var=$(basename $query)



blastall -p tblastn -i $query -d $SPECIE/genome.fa -o Blastinator_data/Blastall_output/$var.tblastn



cat Blastinator_data/Blastall_output/$var.tblastn | sed 's/ e-/ 1e-/g' > Blastinator_data/Corrected_blast/$var.tblastn



#echo "Query number" $contador "done\n"

#contador=$(1+$contador)



} done

echo "all tblast done"

#======================================================================================================================================

#======================================================================================================================================

echo "Searching for relevant Hits and Allingments"



for input in Blastinator_data/Corrected_blast/* ; do {



var=$(basename $input)



python filtrador.py $input $SPECIE/genome.lengths



} done

echo "done"

#======================================================================================================================================

#======================================================================================================================================

echo "Starting fastafetch"

for input in Blastinator_data/Pre_fastafetch/* ; do {





var=$(less $input)



var2=$(basename $input)



fastafetch $SPECIE/genome.fa $SPECIE/genome.index $var> Blastinator_data/Fastafetch_output/"output_"$var2



} done

echo "done"

#======================================================================================================================================

#======================================================================================================================================

echo "Searching for ID pairs"

for positions in Blastinator_data/Coordinates_fastasubseq/* ; do {



var=$(basename $positions)



python aparellador.py Blastinator_data/Coordinates_fastasubseq/$var



} done

echo "done"

#======================================================================================================================================

#======================================================================================================================================

echo "Starting fastasubseq"

for actions in Blastinator_data/Fitxerint1/* ; do {



var=$(less $actions)



var2=$(basename $actions)



$var >> Blastinator_data/Fastasubseq_output/fastasubseq$var2.txt



} done

echo "done\n"

#======================================================================================================================================

#======================================================================================================================================

echo "Correcting possible duplications of fastasubseq outputs"

for positions in Blastinator_data/Fastasubseq_output/* ; do {



python correctus.py $positions



} done

echo "done"

#======================================================================================================================================

#======================================================================================================================================

echo "Selecting Exonerate parameters, exhaustive = yes"

for cosa in Blastinator_data/Fitxerint3/* ; do {



python aparellador2.py $cosa



} done

echo "done"

#======================================================================================================================================

#======================================================================================================================================

echo "Removing selenocisteine from proteins fasta"



for query in $FILE/*; do {



var=$(basename $query)



cat $query | sed 's/U/X/g' > Blastinator_data/Translated_query/Trad_$var



} done

echo "done"

#======================================================================================================================================

#======================================================================================================================================

echo "Starting Exonerate, execution may last a while"

#contador=1

#total=0





for cutreactions in Blastinator_data/Fitxerint2/* ; do {





var=$(less $cutreactions)

var2=$(basename $cutreactions)

$var| egrep -w exon > Blastinator_data/Exonerate_output/Exonerate_$var2

#echo $($($contador/$total)*100) "% done\n"

$var > Blastinator_data/Exonerate_whole/Exonerate_$var2

} done



echo "done"

#======================================================================================================================================

#======================================================================================================================================

echo "Translating Sequences to DNA"



for arxiu in Blastinator_data/Exonerate_output/* ; do {



python aparellador3.py $arxiu



} done

#======================================================================================================================================

#======================================================================================================================================

for arxius in Blastinator_data/Fitxerint4/* ;do {



var=$(less $arxius)



var2=$(basename $arxius)



$var > Blastinator_data/Hipothetic_selenoprot/Tradprot_$var2



} done

#======================================================================================================================================

#======================================================================================================================================

echo "Translating Sequences to DNA"



for arxius in Blastinator_data/Hipothetic_selenoprot/* ;do {



var=$(basename $arxius)

fastatranslate -F 1 $arxius > Blastinator_data/Hipothetic_aa/$var



} done

echo "done"

#======================================================================================================================================

#======================================================================================================================================



for arxius in Blastinator_data/Hipothetic_aa/* ; do {





python corrector.py $arxius



} done



for arxius in Blastinator_data/Fitxerint5/* ; do {



python aparellador4.py $arxius

} done













#======================================================================================================================================

#======================================================================================================================================



echo "Starting and saving Tcofee"



for arxius in Blastinator_data/Fitxerint6/* ; do {



var=$(less $arxius)



var2=$(basename $arxius)



$var > Blastinator_data/Tcofee/$var2



} done

echo "end"



#Awsome Ascii titles at http://www.network-science.de/ascii/

#Special thanks to Juan Carlos, Didac, Gireesh, Ramon and Neus

#======================================================================================================================================

#======================================================================================================================================


#" Terminator, hasta que version de windows tienes?

# Hasta la Vista,baby