#!/bin/bash


### NOTE: This script should usually only be called by bior_annotate_blaster
vcfIn=$1
start=$2
end=$3
vcfOutPartFileName=$4
configFile=$5
configOpt=
if [ -n "$configFile" ] ; then
  configOpt="-c $configFile"
fi

if [ -z $vcfIn ] || [ -z $start ] || [ -z $end ] || [ -z $vcfOutPartFileName ] ; then
    echo "usage:  _bior_annotate_blaster_chunker  <vcfIn>  <startDataLine>  <endDataLine>  <vcfOutPartFileName>  [biorAnnotateConfigFile]"
    exit 1;
fi

### Example file type that "cat" would use: ASCII text  (will have to see if it *contains* this string)
### If uname contains "Darwin", then we're on a Mac, so use gzcat instead of zcat (which demands .Z extensions)
### NOTE: Make sure to use the -L flag to dereference any symbolic links
fileType=$(file -L $vcfIn)
parser=zcat
if [[ "$fileType" == *ASCII* ]] ; then
    parser=cat
elif [[ "$(uname)" == "Darwin" ]]; then
    parser=gzcat
fi

$parser  $vcfIn  |  bior_chunk  -s $start  -e $end  |  bior_annotate $configOpt  | gzip -c > $vcfOutPartFileName

echo "Done - $vcfOutPartFileName"
touch "$vcfOutPartFileName.done"
