#!/bin/bash

if [ $# -ne 1 ];
then
  echo "ERROR. Usage: $0 <species name>";
else
  function scriptDir {
    source="${BASH_SOURCE[0]}";
    while [ -h "$source" ];
    do
      dir="$( cd -P "$( dirname "$source" )" && pwd )";
      source="$(readlink "$source")";
      [[ $source != /* ]] && source="$dir/$source"; # if $source was a relative symlink, we need to resolve it relative to the path where the symlink file was located
    done;
    
    echo "$( cd -P "$( dirname "$source" )" && pwd )";
  }

  location=$(scriptDir);

  echo "START TRANSACTION;";

  for fasta in "$location"/fasta/"${1}".fasta;
  do
    "$location/fasta/to_sql.sh" "$fasta";
  done;

  for interactome in "$location"/interactome/"${1}"*.tsv;
  do
    "$location/interactome/to_sql.sh" "$interactome";
  done;

  for dictionary in "$location"/dictionary/"${1}".tsv;
  do
    "$location/dictionary/to_sql.sh" "$dictionary";
  done;

  echo "COMMIT;";
fi;