#!/bin/bash


tags=""

tmp_list=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)
tmp_list="tmp_${tmp_list}.list"
rm $tmp_list > /dev/null 2>&1

#https://stackoverflow.com/questions/19408649/pipe-input-into-a-script
if [ -p /dev/stdin ]; then
    while read tag; do
        echo $tag
        # tags+="$tag\n"
        # tags+="$tag\n"
    done > $tmp_list

fi

for tag in "$@"; do
    echo $tag
done >> $tmp_list


if [ ! -f $tmp_list ]; then
    echo >&2 ""
    echo >&2 "silentfrompdbs by bcov - a tool to make a silent file from pdbs"
    echo >&2 "Usage:"
    echo >&2 "        cat list_of_tags.list | silentfrompdbs > silent.silent"
    echo >&2 "                             or"
    echo >&2 "        silentfrompdbs tag1 tag2 tag3 > silent.silent"
    exit 1
fi




tmp_file=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)
tmp_file="tmp_${tmp_file}.silent"

score_jd2 -l $tmp_list -out:file:silent $tmp_file -out:file:silent_struct_type binary -extra_res_fa /home/bcov/from/jason/H3i.am1bcc.fa.mm.params 1>&2

silentls $tmp_file | sed 's/_0001$//g' | silentrename $tmp_file

rm $tmp_list
rm $tmp_file
rm $tmp_file.idx



