####################################################################
# tRNAsTrack.txt describe how to create tRNAs track for the following 44
# assemblies: 
ailMel1 caePb1 canFam2 danRer5 felCat3 gorGor3 ornAna1 panTro3 susScr2
anoCar2 caePb2 cavPor3 danRer6 felCat4 loxAfr3 oryCun2 petMar1 taeGut1
bosTau4 caeRem2 cb3 danRer7 fr2 melGal1 oryLat2 ponAbe2 tetNig2
bosTau6 caeRem3 ce4 equCab1 galGal3 monDom5 oviAri1 priPac1 xenTro3
caeJap1 calJac3 ce6 equCab2 gasAcu1 nomLeu1 panTro2 rheMac2

    # get the data 
    mkdir -p  /hive/data/inside/loweLab
    cd /hive/data/inside/loweLab 
    cp -pr /hive/users/pchan/tRNAs . 

    # Move the following (from mm9, rn4, hg18 and hg19) 
    # to top level trackDb.ra
track tRNAs
shortLabel tRNA Genes
longLabel Transfer RNA genes identified with tRNAscan-SE
group genes
priority 53.5
visibility hide
color 0,20,150
type bed 6 +
nextItemButton on
noScoreFilter .

searchName tRNA-name
searchTable tRNAs
searchType bed
searchMethod fuzzy
query select chrom,chromStart,chromEnd,name from %s where name like '%%%s%%'
searchDescription tRNAscan-SE tRNA Name
searchPriority 63

    # load the tRNAs data
    mkdir ~/tRNAsTemp
    cd ~/tRNAsTemp


    # Create tRNAs track for the assemblies
    cat << '_EOF_' > createtRNAsTrack.sh
# Script to create tRNAs track for the 44 assembliese entries
#!/bin/sh
DBLIST='ailMel1 caePb1 canFam2 danRer5 felCat3 gorGor3 ornAna1 panTro3 susScr2
anoCar2 caePb2 cavPor3 danRer6 felCat4 loxAfr3 oryCun2 petMar1 taeGut1
bosTau4 caeRem2 cb3 danRer7 fr2 melGal1 oryLat2 ponAbe2 tetNig2
bosTau6 caeRem3 ce4 equCab1 galGal3 monDom5 oviAri1 priPac1 xenTro3
caeJap1 calJac3 ce6 equCab2 gasAcu1 nomLeu1 panTro2 rheMac2'

for DB in ${DBLIST}   
  do
      echo Processing ${DB}
      rm -rf /hive/data/genomes/${DB}/bed/tRNAs/gif
      mkdir -p /hive/data/genomes/${DB}/bed/tRNAs/gif
      cp -pf /hive/data/inside/loweLab/tRNAs/Eukaryota/${DB}/${DB}-tRNAs.bed  /hive/data/genomes/${DB}/bed/tRNAs/
    hgsql ${DB} -e 'drop table if exists tRNAs'
    hgLoadBed -tab ${DB} tRNAs /hive/data/genomes/${DB}/bed/tRNAs/${DB}-tRNAs.bed -sqlTable=$HOME/kent/src/hg/lib/tRNAs.sql
     cp -pf /hive/data/inside/loweLab/tRNAs/Eukaryota/${DB}/images/* /hive/data/genomes/${DB}/bed/tRNAs/gif/
     rm /hive/data/gbdb/${DB}/RNA-img
     ln -s  /hive/data/genomes/${DB}/bed/tRNAs/gif /hive/data/gbdb/${DB}/RNA-img
  done
'_EOF_'
    # << happy emacs
    chmod +x createtRNAsTrack.sh
    ./createtRNAsTrack.sh

    # link RNA-img in gbdb to htdocs
    cat << '_EOF_' > genetRNAsDbList.sh
# Script to generate entries
# (i.e. "<TAB>ln -sfn /gbdb/${DB)/RNA-img  ${destDir}/RNA-img/${DB}" 
# put into ~/kent/src/hg/htdocs/makefile 
#!/bin/sh

DBLIST='ailMel1 caePb1 canFam2 danRer5 felCat3 gorGor3 ornAna1 panTro3 susScr2
anoCar2 caePb2 cavPor3 danRer6 felCat4 loxAfr3 oryCun2 petMar1 taeGut1
bosTau4 caeRem2 cb3 danRer7 fr2 melGal1 oryLat2 ponAbe2 tetNig2
bosTau6 caeRem3 ce4 equCab1 galGal3 monDom5 oviAri1 priPac1 xenTro3
caeJap1 calJac3 ce6 equCab2 gasAcu1 nomLeu1 panTro2 rheMac2'

for DB in ${DBLIST}
  do
     echo ${DB} |
        awk '{print "\tln -sfn /gbdb/"$0"/RNA-img  ${destDir}/RNA-img/"$0}'
  done
'_EOF_'
    # << happy emacs
    chmod +x genetRNAsDbList.sh 
    ./genetRNAsDbList.sh > tRNAsDb.txt
    # insert tRNAsDb.txt into  ~/kent/src/hg/htdocs/makefile
    cd  ~/kent/src/hg/htdocs
    make alpha



