#!/usr/bin/env bash input_file="$1" output_file="$2" chromInfo_file="$3" chrom="$4" score_col="$5" hilbert_curve_level="$6" summarization_mode="$7" chrom_col="$8" start_col="$9" end_col="${10}" strand_col="${11}" ## use first sequence if chrom filed is empty if [ -z "$chrom" ]; then chrom=$( head -n 1 "$input_file" | cut -f$chrom_col ) fi ## get sequence length if [ ! -r "$chromInfo_file" ]; then echo "Unable to read chromInfo_file $chromInfo_file" 1>&2 exit 1 fi chrom_len=$( awk '$1 == chrom {print $2}' chrom=$chrom $chromInfo_file ) ## error if we can't find the chrom_len if [ -z "$chrom_len" ]; then echo "Can't find length for sequence \"$chrom\" in chromInfo_file $chromInfo_file" 1>&2 exit 1 fi ## make sure chrom_len is positive if [ $chrom_len -le 0 ]; then echo "sequence \"$chrom\" length $chrom_len <= 0" 1>&2 exit 1 fi ## modify R script depending on the inclusion of a score column, strand information input_cols="\$${start_col}, \$${end_col}" col_types='beg=0, end=0, strand=""' # if strand_col == 0 (strandCol metadata is not set), assume everything's on the plus strand if [ $strand_col -ne 0 ]; then input_cols="${input_cols}, \$${strand_col}" else input_cols="${input_cols}, \\\"+\\\"" fi # set plot value (either from data or use a constant value) if [ $score_col -eq -1 ]; then value=1 else input_cols="${input_cols}, \$${score_col}" col_types="${col_types}, score=0" value='chunk$score[i]' fi R --vanilla &> /dev/null <