/** blastp all against all */

process BLAST_MAKEBLASTDB {

    label 'blast'

    input:
        val species
        path proteome

    output:
        path 'db.phr'
        path 'db.pin'
        path 'db.psq'

    script:
        """
    makeblastdb -in "${proteome}" -dbtype prot -out 'db' -title "${species}"
        """
}

process BLAST_BLASTP {

    label 'blast'

    input:
        val species
        path proteome
        path 'db.phr'
        path 'db.pin'
        path 'db.psq'
    output:
        path "${species}.all-against-all.blastp.tsv"

    script:
        """
    blastp -query "${proteome}" -db 'db' -outfmt '6' -num_threads 7  -out "${species}.all-against-all.blastp.tsv"
        """
}

workflow BLAST_ALL_AGAINST_ALL {

    take:
    proteome

    main:
    BLAST_MAKEBLASTDB(params.species, proteome)
    BLAST_BLASTP(params.species, proteome, BLAST_MAKEBLASTDB.out)

    emit:
    BLAST_BLASTP.out
}
