#!/usr/bin/env bash
#
# orthologer - Pipeline for deducing orthology from fasta files.
# Copyright (C) 2005-2023 E. Zdobnov lab: F. Tegenfeldt
# <fredrik.tegenfeldt@unige.ch> based on code by E. Kriventseva
#
# This file is part of orthologer.
#
# orthologer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# orthologer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with orthologer.  If not, see <http://www.gnu.org/licenses/>.
#
#
# This script tabulates the size and number of lines of all possible pairs
# for a given set of species.
#
set -u
if [ $# -ne 3 ]; then
    echo "Usage $0 <species file> <sequence dir> <suffix>"
    exit 255
fi


fsfiles="$1"
seqdir="$2"
suffix="$3"

allspec=`cat $fsfiles`

for specA in $allspec; do
    specA=`basename $specA $suffix`
    sizeA=`ls -sH ${seqdir}/${specA}${suffix} | cut -d ' ' -f 1`
    wlenA=`wc -l ${seqdir}/${specA}${suffix} | cut -d ' ' -f 1`
    for specB in $allspec; do
	specB=`basename $specB $suffix`
	sizeB=`ls -sH ${seqdir}/${specB}${suffix} | cut -d ' ' -f 1`
	wlenB=`wc -l ${seqdir}/${specB}${suffix} | cut -d ' ' -f 1`
	if [ $specA != $specB ]; then
	    sz=`awk "BEGIN{ print ${sizeA}*${sizeB} }"`
	    echo -e "$specA\t$specB\t$wlenA\t$wlenB\t$sizeA\t$sizeB"
	fi
    done
done
