Mercurial > repos > saskia-hiltemann > ireport
diff createHTML.sh @ 6:42076db43d42 draft
Fixed auto resizing plus various other minor bugs
author | saskia-hiltemann |
---|---|
date | Mon, 16 Nov 2015 08:56:22 -0500 |
parents | a4813532bbc6 |
children |
line wrap: on
line diff
--- a/createHTML.sh Tue Oct 07 08:49:14 2014 -0400 +++ b/createHTML.sh Mon Nov 16 08:56:22 2015 -0500 @@ -1,6 +1,9 @@ +gbcount=0 + ## ## Create Cover Page ## +#<a href=\"$zipireport\"> Click here to download a copy of this iReport </a> <br/><br/> function makeIntroPage ( ){ echo "Creating Intro Page" title="$1" @@ -20,9 +23,8 @@ <b><font size=\"15\"> iReport: ${title} </font></b><br/> <br/> <br/> - <a href=\"$link\"> Click here to view report </a> <br/><br/> + <a href=\"$link\"> Click image to view report </a> <br/><br/> <a href=\"$link\"> <img src="$coverimage" width=\"50%\" alt=\"loading image..\"/> </a><br/><br/> - <a href=\"$zipireport\"> Click here to download a copy of this iReport </a> <br/><br/> </center> </body> </html>" > $htmlout @@ -30,14 +32,86 @@ } ## +## Decompress archive fiels +## -> will detect archive formats: zip, tar, gzip, tar.gz, bzip2 +## -> input: path to archive +## -> files will be located in ${galaxypath}/archive_${fname}/ +## +function decompressArchive (){ + archive=$1 + + fname=`basename ${archive}` + fname=${fname%.dat} + ftype=`file $archive` + + if [[ ! -d ${galaxypath}/archive_${fname}/ ]] + then + mkdir ${galaxypath}/archive_${fname}/ + + #echo "archive type: `file $archive`" + # decompress archive + if [[ $ftype == *Zip* ]] + then + #echo "detected zip file" + cp $archive ${galaxypath}/archive_${fname}/${fname}.zip + wd=`pwd` + cd ${galaxypath}/archive_${fname}/ + unzip -q ${fname}.zip + rm ${fname}.zip + cd $wd + fi + if [[ $ftype == *tar* ]] + then + cp $archive ${galaxypath}/archive_${fname}/${fname}.tar + wd=`pwd` + cd ${galaxypath}/archive_${fname}/ + tar xf ${fname}.tar + rm ${fname}.tar + cd $wd + fi + if [[ $ftype == *gzip* ]] + then + cp $archive ${galaxypath}/archive_${fname}/${fname}.gz + gunzip ${galaxypath}/archive_${fname}/${fname}.gz + #ls ${galaxypath}/archive_${fname}/ + + # check for tar.gz + ftype=`file ${galaxypath}/archive_${fname}/${fname}` + if [[ $ftype == *tar* ]] + then + # turns out it was tar.gz + rm -Rf ${galaxypath}/archive_${fname}/* + ls ${galaxypath}/archive_${fname}/ + cp $archive ${galaxypath}/archive_${fname}/${fname}.tar.gz + + wd=`pwd` + cd ${galaxypath}/archive_${fname}/ + tar xzf ${fname}.tar.gz + cd $wd + fi + wait + rm -f ${galaxypath}/archive_${fname}/*.tar + rm -f ${galaxypath}/archive_${fname}/*.tar.gz + fi + if [[ $ftype == *bzip2* ]] + then + cp $archive ${galaxypath}/archive_${fname}/${fname}.gz + gunzip2 ${galaxypath}/archive_${fname}/${fname}.gz + fi + fi +} + +## ## Create HTML content for the tabs specified by user ## function makeTabContent ( ){ tab=$1 # name of current tab itemslist=$2 # list of all items + tracklist=$3 # genome browser tracks info contentline="" # HTML code for tab imgcount=0 # keep track of the number of images on the current tab - + iframename=`head -n 1 < /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1` + #iframename="test" for item in $itemslist do ## Parse items lists @@ -63,6 +137,12 @@ text=${text//==space==/ } text=${text//==colon==/:} text=${text//==comma==/,} + + text=${text//==braceopen==/(} + text=${text//==braceclose==/)} + text=${text//==cbraceopen==/{} + text=${text//==cbraceclose==/}} + text=${text//==slash==/\/} text=${text//==lt==/<} text=${text//==gt==/>} @@ -78,8 +158,8 @@ text=${text//\&r/\\n} text=${text//\&n/\\n} text=${text//\&c/:} - - + + ## convert markdown in textfield to html echo -e "$text" > mytext.md @@ -90,9 +170,8 @@ else # pandoc exists - echo "pandoc exists" - pandoc -o mytext.html mytext.md - pandoc -o standalone.html -s mytext.md + pandoc -f markdown -o mytext.html mytext.md + pandoc -f markdown -o standalone.html -s mytext.md #get css generated by pandoc and add as scoped attribute (HTML5) pandocstyle=`sed -n '/<style/,/style>/p' standalone.html` @@ -148,6 +227,10 @@ text=${text//==backtick==/`} text=${text//==dollar==/$} text=${text//==bar==/|} + text=${text//==braceopen==/(} + text=${text//==braceclose==/)} + text=${text//==cbraceopen==/{} + text=${text//==cbraceclose==/}} contentline="${contentline}\n${text}\n" fi @@ -208,6 +291,7 @@ zoomlevel=${myarr[4]} zoomenable=${myarr[5]} align=${myarr[6]} + typestring="" #####echo "zoomenable:${zoomenable}, align:${align}" if [[ $ftype == *JPEG* ]] then @@ -221,6 +305,11 @@ then suffix=".png" fi + if [[ $ftype == *TIFF* ]] + then + suffix=".tiff" + typestring="type=\"image/tiff\"" + fi image=`basename ${myarr[2]}` image=${image%.dat} @@ -248,8 +337,8 @@ fi if [[ ${zoomlevel} -eq 0 || ${zoomenable} == "N" ]] - then - contentline="${contentline}<span id=\"img${imgcount}\"> <img src=\"${image}\" ${alignstring} ${widthstring} alt=\"loading image..\"/></span>" + then + contentline="${contentline}<span id=\"img${imgcount}\"> <img src=\"${image}\" ${alignstring} ${widthstring} alt=\"loading image..\"/></span>" else contentline="${contentline}<span class=\"zoomme\" id=\"img${imgcount}\"> <img src=\"${image}\" ${alignstring} ${widthstring} alt=\"loading image..\"/></span>" fi @@ -261,6 +350,7 @@ ## if [ ${myarr[1]} == "table" ] then + maxlines=50000 tsvfile_orig=${myarr[2]} tsvfile="tablehead.tsv" @@ -268,6 +358,9 @@ fname=${fname%.*} fancy=${myarr[4]} makelinks=${myarr[5]} + #iframeid="iframe$giframecount" + iframeid="iframe-$iframename" + #echo "\nmakelinks: $makelinks fancy: $fancy <br>" #TODO client side database for large files. For now only display first section of file and add download link @@ -291,13 +384,25 @@ then col=${myarr[6]} prefix=${myarr[7]} - suffix=${myarr[8]} + suffix=${myarr[8]} + urlitems=${myarr[9]} + minw=${myarr[10]} + minh=${myarr[11]} suffix=${suffix/emptycol/} suffix=${suffix/==quote==/&} prefix=${prefix/emptycol/} prefix=${prefix/==quote==/&} prefix=${prefix/==colon==/:} - #echo "prefix: $prefix" + + # unpack archive of files to link to if present + if [[ ${urlitems} != None ]] + then + oldfname=$fname + decompressArchive ${urlitems} + prefix=archive_${fname}/${prefix} + fname=$oldfname + fi + #edit the table to include links awk 'BEGIN{ @@ -305,32 +410,37 @@ OFS="\t" url="'"$prefix"'" url2="'"$suffix"'" + iframeid="'"$iframeid"'" prefix="<a href=\42" - suffix="\42>" + suffix="\42 onclick=\42resizeIframe("iframeid")\42>" col="'"$col"'" end="</a>" }{ if(FNR==1) print $0 - else{ + else{ $col=prefix""url""$col""url2""suffix""$col""end print $0 } }END{}' ${tsvfile} > ${tsvfile}2 - + else + minw=${myarr[6]} + minh=${myarr[7]} cp ${tsvfile} ${tsvfile}2 fi + #iframecount=$[$iframecount+1] + if [ $fancy == "Y" ] then perl ${repositorypath}/tsv2html.pl < ${tsvfile}2 > ${galaxypath}/htmltable_${fname}.html - contentline="${contentline}\n<iframe class=\"invisibleframe fancyiframe\" src=\"htmltable_${fname}.html\" width=\"100%\" style=\"min-height: 525px; overflow-y: hidden; overflow-x: scroll\" ></iframe>" - iframecount=$[$iframecount+1] + contentline="${contentline}\n<iframe class=\"invisibleframe fancyiframe\" id=\"$iframeid\" src=\"htmltable_${fname}.html\" width=\"100%\" style=\"height: 350px; min-height: ${minh}px !important; overflow-y: hidden; overflow-x: scroll\" onClick=resizeIframe(\"$iframeid\")></iframe>" + else perl ${repositorypath}/tsv2html_simple.pl < ${tsvfile}2 > ${galaxypath}/htmltable_${fname}.html - contentline="${contentline}\n<iframe class=\"unfancyiframe invisibleframe\" src=\"htmltable_${fname}.html\" scrolling=\"no\" style=\"max-width: 100%; vertical-align: top;\" onload=\"resizeIframe(this)\"></iframe>" - iframecount=$[$iframecount+1] + contentline="${contentline}\n<iframe class=\"unfancyiframe invisibleframe\" id=\"$iframeid\" src=\"htmltable_${fname}.html\" scrolling=\"no\" style=\"min-width: ${minw}px; min-height: ${minh}px !important; max-width: 100%; vertical-align: top;\" onClick=resizeIframe(\"$iframeid\") ></iframe>" + fi if [[ $numlines -gt ${maxlines} ]] @@ -373,7 +483,29 @@ htmlname="${fname}.html" cp ${htmlfile} "${galaxypath}/${htmlname}" - contentline="${contentline}\n<iframe class=\"invisibleframe\" src=\"${htmlname}\" width=\"100%\" height=\"${height}px\"></iframe>\n" + apiid=${myarr[5]} + isireport=${myarr[6]} + localhost=${myarr[7]} + proxy=${myarr[8]} + localhost=${localhost//==colon==/:} + localhost=${localhost//==fslash==/\/} + if [[ ${isireport} == "Y" ]] + then + #cp ${localhost}/datasets/${apiid}/* "${galaxypath}/tst" + htmlname="/${proxy}/datasets/${apiid}/display/" + fi + + contentline="${contentline}\n<iframe class=\"invisibleframe\" src=\"${htmlname}\" width=\"100%\" height=\"${height}px\"></iframe>\n" + fi + + + if [[ ${myarr[1]} == "htmlpage" ]] + then + url=${myarr[2]} + url=${url//==colon==/:} + url=${url//==fslash==//} + height=${myarr[4]} + contentline="${contentline}\n<iframe class=\"invisibleframe\" src=\"${url}\" width=\"100%\" height=\"${height}px\"></iframe>\n" fi ## @@ -383,12 +515,280 @@ then url=${myarr[2]} linktext=${myarr[4]} - url=${url/==colon==/:} - url=${url/==quote==/&} + + echo -n "$url" > tmpfileb64 + url=`base64 -d tmpfileb64` + echo -n "$linktext" > tmpfileb64 + linktext=`base64 -d tmpfileb64` + + if [[ -z $linktext ]] + then + linktext=$url + fi contentline="${contentline}<a href=\"${url}\" target=\"_blank\">${linktext}</a>" fi + + ## + ## Genome Browser + ## + if [ ${myarr[1]} == "genomebrowser" ] + then + + # parse inputs + + apiid=${myarr[4]} + servername=${myarr[5]} + buildver=${myarr[2]} + + + region=${myarr[6]} + + + echo -n "$region" > tmpfileb64 + region=`base64 -d tmpfileb64` + + + initialchrom=${region%:*} + initialrange=${region#*:} + + initialstart=${initialrange%-*} + initialend=${initialrange#*-} + + + #TODO + ftype="vcf" + + servername=${servername/==colon==/:} + + ## parse and prepare all tracks + gbcount=$[$gbcount+1] + gbfilelist=${tracklist} + userTracks="" + #IFS=',' read -a gbfilearray <<< ${gbfilelist} + gbfilearray=(${gbfilelist//,/ }) + for gbfile in "${gbfilearray[@]}" + do + # gbfile is in format "browsernum:file" + #IFS=':' read -a gbfileinfo <<< ${gbfile} + gbfileinfo=(${gbfile//:/ }) + if [[ ${gbfileinfo[0]} == $gbcount ]] + then + + ftype=${gbfileinfo[3]} + + gbfilename=${gbfileinfo[1]} + gbfilelabel=${gbfileinfo[2]} + gbfilelabel=${gbfilelabel//==space==/ } + gbfilelabel=${gbfilelabel//==bopen==/(} + gbfilelabel=${gbfilelabel//==bclose==/)} + fname=`basename ${gbfilename}` + fname=${fname%.dat} + + if [[ $ftype == "vcftabix" ]] + then + newgbfilename="${fname}.vcf" + + + cp ${gbfilename} "${galaxypath}/${newgbfilename}" + bgzip "${galaxypath}/${newgbfilename}" + tabix -f -p vcf "${galaxypath}/${newgbfilename}.gz" + + userTracks="${userTracks}, + {name: '${gbfilelabel}', + uri: '${servername}/datasets/${apiid}/display/${newgbfilename}.gz', + tier_type: 'tabix', + payload: 'vcf'} + " + fi + + if [[ $ftype == "vcfmemstore" ]] + then + newgbfilename="${fname}.vcf" + + + cp ${gbfilename} "${galaxypath}/${newgbfilename}" + #bgzip "${galaxypath}/${newgbfilename}" + #tabix -p vcf "${galaxypath}/${newgbfilename}.gz" + + userTracks="${userTracks}, + {name: '${gbfilelabel}', + uri: '${servername}/datasets/${apiid}/display/${newgbfilename}', + tier_type: 'memstore', + payload: 'vcf'} + " + fi + + if [[ $ftype == "bam" ]] + then + newgbfilename="${fname}.bam" + + # link to bam instead of copying + ln -s ${gbfilename} "${galaxypath}/${newgbfilename}" + samtools index "${galaxypath}/${newgbfilename}" + + userTracks="${userTracks}, + {name: '${gbfilelabel}', + bamURI: '${servername}/datasets/${apiid}/display/${newgbfilename}'} + " + + fi + + if [[ $ftype == "bigbed" ]] + then + newgbfilename="${fname}.bigbed" + + cp ${gbfilename} "${galaxypath}/${newgbfilename}" + #bgzip "${galaxypath}/${newgbfilename}" + #tabix -f -p bed "${galaxypath}/${newgbfilename}.gz" + + userTracks="${userTracks}, + {name: '${gbfilelabel}', + bwgURI: '${servername}/datasets/${apiid}/display/${newgbfilename}'} + " + + fi + + if [[ $ftype == "bedtabix" ]] + then + newgbfilename="${fname}.bed" + + cp ${gbfilename} "${galaxypath}/${newgbfilename}" + bgzip "${galaxypath}/${newgbfilename}" + tabix -f -p bed "${galaxypath}/${newgbfilename}.gz" + + userTracks="${userTracks}, + {name: '${gbfilelabel}', + uri: '${servername}/datasets/${apiid}/display/${newgbfilename}.gz', + tier_type: 'tabix', + payload: 'bed'} + " + + fi + + if [[ $ftype == "bedmemstore" ]] + then + newgbfilename="${fname}.bed" + + cp ${gbfilename} "${galaxypath}/${newgbfilename}" + #bgzip "${galaxypath}/${newgbfilename}" + #tabix -p bed "${galaxypath}/${newgbfilename}.gz" + + userTracks="${userTracks}, + {name: '${gbfilelabel}', + uri: '${servername}/datasets/${apiid}/display/${newgbfilename}', + tier_type: 'memstore', + payload: 'bed'} + " + + fi + fi + done + + + + if [ ${buildver} == "hg18" ] + then + coordSystem="coordSystem: { + speciesName: 'Human', + taxon: 9606, + auth: 'NCBI', + version: '36', + ucscName: 'hg18' + }," + + chains="chains: { + hg19ToHg18: new Chainset('https://www.biodalliance.org/das/hg19ToHg18/', 'GRCh37', 'NCBI36', + { + speciesName: 'Human', + taxon: 9606, + auth: 'GRCh', + version: 37 + }) + }," + + genesTrack="{name: 'Genes', + desc: 'Gene structures from Ensembl 54', + uri: 'https://www.biodalliance.org/das/hsa_54_36p/', + collapseSuperGroups: true, + provides_karyotype: true, + provides_search: true, + provides_entrypoints: true, + maxbins: false}, " + + repeatsTrack="{name: 'Repeats', + desc: 'Repeat annotation from Ensembl 59', + bwgURI: 'https://www.biodalliance.org/datasets/repeats.bb', + stylesheet_uri: 'https://www.biodalliance.org/stylesheets/bb-repeats.xml'}" + + + # default is hg19 + else + coordSystem="coordSystem: { + speciesName: 'Human', + taxon: 9606, + auth: 'NCBI', + version: '37', + ucscName: 'hg19' + }," + + chains="" + + genesTrack="{name: 'Genes', + desc: 'Gene structures from GENCODE 19', + bwgURI: 'https://www.biodalliance.org/datasets/gencode.bb', + stylesheet_uri: 'https://www.biodalliance.org/stylesheets/gencode.xml', + collapseSuperGroups: true, + trixURI: 'https://www.biodalliance.org/datasets/geneIndex.ix'}," + + repeatsTrack="{name: 'Repeats', + desc: 'Repeat annotation from Ensembl 59', + bwgURI: 'https://www.biodalliance.org/datasets/repeats.bb', + stylesheet_uri: 'https://www.biodalliance.org/stylesheets/bb-repeats.xml'}," + + fi + + contentline="${contentline} +<script language=\"javascript\" src=\"https://www.biodalliance.org/release-0.13/dalliance-compiled.js\"></script> +<script language=\"javascript\"> + new Browser({ + chr: '$initialchrom', + viewStart: $initialstart, + viewEnd: $initialend, + cookieKey: 'human', + pageName: 'svgHolder${gbcount}', + ${coordSystem} + + ${chains} + sources: [{name: 'Genome', + twoBitURI: 'https://www.biodalliance.org/datasets/${buildver}.2bit', + tier_type: 'sequence'}, + ${genesTrack}, + ${repeatsTrack}, + {name: 'Conservation', + desc: 'Conservation', + bwgURI: 'https://www.biodalliance.org/datasets/phastCons46way.bw', + noDownsample: true} + ${userTracks} + ], + + + + + browserLinks: { + Ensembl: 'http://www.ensembl.org/Homo_sapiens/Location/View?r=${chr}:${start}-${end}', + UCSC: 'http://genome.ucsc.edu/cgi-bin/hgTracks?db=${buildver}&position=chr${chr}:${start}-${end}', + Sequence: 'http://www.derkholm.net:8080/das/${buildver}comp/sequence?segment=${chr}:${start},${end}' + } + + }); +</script> + +<div id=\"svgHolder${gbcount}\"></div> +" + fi + ## ## Link to Dataset ## @@ -400,6 +800,10 @@ linkfilename=`basename ${linkfile}` linktext=${myarr[6]} + localhost=${myarr[7]} + proxy=${myarr[8]} + localhost=${localhost//==colon==/:} + localhost=${localhost//==fslash==/\/} #check for some basic filetypes ftype=`file $linkfile` @@ -427,7 +831,7 @@ if [[ ${isireport} == "Y" ]] then - linkfilename="/datasets/${apiid}/display/" + linkfilename="/${proxy}/datasets/${apiid}/display/" else cp ${linkfile} "${galaxypath}/${linkfilename}" fi @@ -439,67 +843,10 @@ ## Links to Archive Contents ## if [[ ${myarr[1]} == "links" ]] - then - #echo "making links:" + then archive=${myarr[2]} - fname=`basename ${archive}` - fname=${fname%.dat} - ftype=`file $archive` - mkdir ${galaxypath}/archive_${fname}/ - - #echo "archive type: `file $archive`" - # decompress archive - if [[ $ftype == *Zip* ]] - then - #echo "detected zip file" - cp $archive ${galaxypath}/archive_${fname}/${fname}.zip - wd=`pwd` - cd ${galaxypath}/archive_${fname}/ - unzip -q ${fname}.zip - rm ${fname}.zip - cd $wd - fi - if [[ $ftype == *tar* ]] - then - cp $archive ${galaxypath}/archive_${fname}/${fname}.tar - wd=`pwd` - cd ${galaxypath}/archive_${fname}/ - tar xf ${fname}.tar - rm ${fname}.tar - cd $wd - fi - if [[ $ftype == *gzip* ]] - then - cp $archive ${galaxypath}/archive_${fname}/${fname}.gz - gunzip ${galaxypath}/archive_${fname}/${fname}.gz - #ls ${galaxypath}/archive_${fname}/ - - # check for tar.gz - ftype=`file ${galaxypath}/archive_${fname}/${fname}` - if [[ $ftype == *tar* ]] - then - # turns out it was tar.gz - rm -Rf ${galaxypath}/archive_${fname}/* - ls ${galaxypath}/archive_${fname}/ - cp $archive ${galaxypath}/archive_${fname}/${fname}.tar.gz - - wd=`pwd` - cd ${galaxypath}/archive_${fname}/ - tar xzf ${fname}.tar.gz - cd $wd - fi - wait - rm -f ${galaxypath}/archive_${fname}/*.tar - rm -f ${galaxypath}/archive_${fname}/*.tar.gz - fi - if [[ $ftype == *bzip2* ]] - then - cp $archive ${galaxypath}/archive_${fname}/${fname}.gz - gunzip2 ${galaxypath}/archive_${fname}/${fname}.gz - fi - - - + decompressArchive $archive + # add links to webpage # separate line for each folder, files within folder on same line for linkfile in `ls ${galaxypath}/archive_${fname}/ |sort -V` @@ -540,36 +887,55 @@ done echo "${contentline}" + + } ## ## Create HTML content for iReport ## createMainPage (){ + #export IFRAMECNT=1 page=$1 tabtitles=$2 # comma-separated list of tab titles tabitems=$3 # colon-sparated list of tabs specifications - iframecount=1 # keep track of number of iFrames so that they can be referenced by ID + #giframecount=1 # keep track of number of iFrames so that they can be referenced by ID minwidth=$4 # width of page + gbtracks=$5 # genome browser track information - echo "createMainPage: tabitems: $tabitems. tabtitles: $tabtitles" + echo "createMainPage: tabitems: $tabitems. tabtitles: $tabtitles. gbtracks: $gbtracks" # create correct number of tabs count=0 + tabtitles=${tabtitles/,/} tabtitles=${tabtitles//,/ } - tabtitles=${tabtitles//==colon==/:} + echo $tabtitles + + tabcount=0 + for tabt in $tabtitles + do + echo -n $tabt > tmpfileb64 + thistabtitle=`base64 -d tmpfileb64` + newtabtitles+=" $thistabtitle" + tabcount=$[tabcount+1] + done + + echo $newtabtitles + tabslist="<ul>\n" mytabs="" - for title in $tabtitles + for title in $newtabtitles do # Create list of tabs count=$[count+1] - title2=${title//_s_/ } + title2=${title//==space==/ } + title2=${title2//==dollar==/$} + title2=${title2//==colon==/} tabslist="${tabslist} <li><a href=\"#tabs-${count}\">${title2}</a></li>\n" # Create tabs with content - tabcontent=$(makeTabContent $title "$tabitems") + tabcontent=$(makeTabContent $title "$tabitems" "$gbtracks") mytabs="${mytabs}\n<div id=\"tabs-${count}\">\n" mytabs="${mytabs}${tabcontent}" mytabs="${mytabs}\n</div>\n" @@ -599,4 +965,4 @@ </div> </body> </html>" > $page -} \ No newline at end of file +}