comparison createHTML.sh @ 2:3c160414da2e default tip

initial upload
author shiltemann
date Thu, 26 Feb 2015 14:05:23 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 2:3c160414da2e
1 gbcount=0
2
3 ##
4 ## Create Cover Page
5 ##
6 function makeIntroPage ( ){
7 echo "Creating Intro Page"
8 title="$1"
9 coverimage=$2
10 link=$3
11 htmlout=$4
12 zipireport=$5
13
14 echo -e "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
15 <html>
16 <head>
17 </head>
18 <body>
19 <br/>
20 <br/>
21 <center>
22 <b><font size=\"15\"> iReport: ${title} </font></b><br/>
23 <br/>
24 <br/>
25 <a href=\"$link\"> Click here to view report </a> <br/><br/>
26 <a href=\"$link\"> <img src="$coverimage" width=\"50%\" alt=\"loading image..\"/> </a><br/><br/>
27 <a href=\"$zipireport\"> Click here to download a copy of this iReport </a> <br/><br/>
28 </center>
29 </body>
30 </html>" > $htmlout
31
32 }
33
34 ##
35 ## Decompress archive fiels
36 ## -> will detect archive formats: zip, tar, gzip, tar.gz, bzip2
37 ## -> input: path to archive
38 ## -> files will be located in ${galaxypath}/archive_${fname}/
39 ##
40 function decompressArchive (){
41 archive=$1
42
43 fname=`basename ${archive}`
44 fname=${fname%.dat}
45 ftype=`file $archive`
46
47 if [[ ! -d ${galaxypath}/archive_${fname}/ ]]
48 then
49 mkdir ${galaxypath}/archive_${fname}/
50
51 #echo "archive type: `file $archive`"
52 # decompress archive
53 if [[ $ftype == *Zip* ]]
54 then
55 #echo "detected zip file"
56 cp $archive ${galaxypath}/archive_${fname}/${fname}.zip
57 wd=`pwd`
58 cd ${galaxypath}/archive_${fname}/
59 unzip -q ${fname}.zip
60 rm ${fname}.zip
61 cd $wd
62 fi
63 if [[ $ftype == *tar* ]]
64 then
65 cp $archive ${galaxypath}/archive_${fname}/${fname}.tar
66 wd=`pwd`
67 cd ${galaxypath}/archive_${fname}/
68 tar xf ${fname}.tar
69 rm ${fname}.tar
70 cd $wd
71 fi
72 if [[ $ftype == *gzip* ]]
73 then
74 cp $archive ${galaxypath}/archive_${fname}/${fname}.gz
75 gunzip ${galaxypath}/archive_${fname}/${fname}.gz
76 #ls ${galaxypath}/archive_${fname}/
77
78 # check for tar.gz
79 ftype=`file ${galaxypath}/archive_${fname}/${fname}`
80 if [[ $ftype == *tar* ]]
81 then
82 # turns out it was tar.gz
83 rm -Rf ${galaxypath}/archive_${fname}/*
84 ls ${galaxypath}/archive_${fname}/
85 cp $archive ${galaxypath}/archive_${fname}/${fname}.tar.gz
86
87 wd=`pwd`
88 cd ${galaxypath}/archive_${fname}/
89 tar xzf ${fname}.tar.gz
90 cd $wd
91 fi
92 wait
93 rm -f ${galaxypath}/archive_${fname}/*.tar
94 rm -f ${galaxypath}/archive_${fname}/*.tar.gz
95 fi
96 if [[ $ftype == *bzip2* ]]
97 then
98 cp $archive ${galaxypath}/archive_${fname}/${fname}.gz
99 gunzip2 ${galaxypath}/archive_${fname}/${fname}.gz
100 fi
101 fi
102 }
103
104 ##
105 ## Create HTML content for the tabs specified by user
106 ##
107 function makeTabContent ( ){
108 tab=$1 # name of current tab
109 itemslist=$2 # list of all items
110 tracklist=$3 # genome browser tracks info
111 contentline="" # HTML code for tab
112 imgcount=0 # keep track of the number of images on the current tab
113 iframecount=0
114
115 for item in $itemslist
116 do
117 ## Parse items lists
118 item=${item/::/:emptycol:}
119 declare -a myarr=(`echo $item |sed 's/:/ /g'`)
120
121 ## Create the tab contents HTML code
122 if [ ${myarr[0]} == $tab ]
123 then
124
125 ##
126 ## Text Field
127 ##
128 if [ ${myarr[1]} == "text" ]
129 then
130 text=${myarr[2]}
131 md=${myarr[4]}
132
133 # if markdown, convert to html
134 if [ $md == "Y" ]
135 then
136 ## resubstitute sanitized charachters
137 text=${text//==space==/ }
138 text=${text//==colon==/:}
139 text=${text//==comma==/,}
140 text=${text//==slash==/\/}
141 text=${text//==lt==/<}
142 text=${text//==gt==/>}
143 text=${text//==apos==/\'}
144 text=${text//==quote==/\"}
145 text=${text//==backtick==/\`}
146 text=${text//==dollar==/$}
147 text=${text//==bar==/|}
148 text=${text//&&/&}
149 text=${text//\\n/\\n}
150 text=${text//\\t/\\t}
151 text=${text//\&r\&n/\\n}
152 text=${text//\&r/\\n}
153 text=${text//\&n/\\n}
154 text=${text//\&c/:}
155
156
157 ## convert markdown in textfield to html
158 echo -e "$text" > mytext.md
159
160 if [ -z `type -p pandoc` ]
161 then
162 # pandoc missing
163 ${repositorypath}/Markdown/markdown2.py mytext.md > mytext.html
164
165 else
166 # pandoc exists
167 pandoc -f markdown -o mytext.html mytext.md
168 pandoc -f markdown -o standalone.html -s mytext.md
169
170 #get css generated by pandoc and add as scoped attribute (HTML5)
171 pandocstyle=`sed -n '/<style/,/style>/p' standalone.html`
172 fi
173
174 markdowntext=$(cat mytext.html)
175 contentline="${contentline}\n<div class=\"markdown-body\">${pandocstyle} ${markdowntext}</div>\n"
176
177 else # If not markdown, print verbatim (with exception of few html tags)
178
179 ## allow some html formatting tags
180 text=${text//==lt==strong==gt==/<strong>} # search for strong tags
181 text=${text//==lt====slash==strong==gt==/<\/strong>} # search for strong tags
182 text=${text//==lt==em==gt==/<em>} # search for strong tags
183 text=${text//==lt====slash==em==gt==/<\/em>} # search for strong tags
184
185 text=${text//==lt==b==gt==/<strong>} # search for strong tags
186 text=${text//==lt====slash==b==gt==/<\/strong>} # search for strong tags
187 text=${text//==lt==i==gt==/<em>} # search for strong tags
188 text=${text//==lt====slash==i==gt==/<\/em>} # search for strong tags
189
190 text=${text//==lt==br==gt==/<br\/>} # search for strong tags
191 text=${text//==lt====br==slash==gt==/<br\/>} # search for strong tags
192 text=${text//==lt==h1==gt==/<h1>} # search for h1-h6 tags
193 text=${text//==lt==h2==gt==/<h2>} # search for h1-h6 tags
194 text=${text//==lt==h3==gt==/<h3>} # search for h1-h6 tags
195 text=${text//==lt==h4==gt==/<h4>} # search for h1-h6 tags
196 text=${text//==lt==h5==gt==/<h5>} # search for h1-h6 tags
197 text=${text//==lt==h6==gt==/<h6>} # search for h1-h6 tags
198 text=${text//==lt====slash==h1==gt==/<\/h1>} # search for h1-h6 closing tags
199 text=${text//==lt====slash==h2==gt==/<\/h2>} # search for h1-h6 closing tags
200 text=${text//==lt====slash==h3==gt==/<\/h3>} # search for h1-h6 closing tags
201 text=${text//==lt====slash==h4==gt==/<\/h4>} # search for h1-h6 closing tags
202 text=${text//==lt====slash==h5==gt==/<\/h5>} # search for h1-h6 closing tags
203 text=${text//==lt====slaxh==h6==gt==/<\/h6>} # search for h1-h6 closing tags
204
205 ## display everything else verbatim
206 text=${text//==space==/ }
207 text=${text//==colon==/:}
208 text=${text//==comma==/,}
209 text=${text//==slash==/\/}
210 text=${text//==lt==/&lt;}
211 text=${text//==gt==/&gt;}
212 text=${text//==apos==/&apos;}
213 text=${text//==quote==/&quot;}
214 text=${text//&&/&amp;}
215 text=${text//\\n/<br/>}
216 text=${text//\\t/&emsp;}
217 text=${text//\&r\&n/<br/>}
218 text=${text//\&r/<br/>}
219 text=${text//\&n/<br/>}
220 text=${text//\&c/:}
221 text=${text//==backtick==/&#96;}
222 text=${text//==dollar==/$}
223 text=${text//==bar==/|}
224 contentline="${contentline}\n${text}\n"
225 fi
226
227
228 fi
229
230 ##
231 ## Text File
232 ##
233 if [ ${myarr[1]} == "textfile" ]
234 then
235 tfile=${myarr[2]}
236 md=${myarr[4]}
237 fname=`basename ${tfile}`
238 fname=${fname%.*}
239 fname="${fname}.txt"
240 cp ${tfile} "${galaxypath}/${fname}"
241
242 #estimate height for iframe based on number oflines in the file
243 numlines=`wc -l ${tfile} | cut -d" " -f1`
244 minheight=$[$numlines*17]
245
246 # if markdown, convert to html
247 if [ $md == "Y" ]
248 then
249
250 if [ -z `type -p pandoc` ]
251 then
252 # pandoc missing
253 ${repositorypath}/Markdown/markdown2.py ${tfile} > mytext.html
254
255 else
256 # pandoc exists
257 pandoc -o mytext.html ${tfile}
258 pandoc -o standalone.html -s ${tfile}
259
260 # get css generated by pandoc and add as scoped attribute (HTML5)
261 pandocstyle=`sed -n '/<style/,/style>/p' standalone.html`
262
263 fi
264
265 markdowntext=$(cat mytext.html)
266 contentline="${contentline}\n<div class=\"markdown-body\">${pandocstyle} ${markdowntext}</div>\n"
267 else
268 contentline="${contentline}\n<iframe class=\"invisibleframe\" src=\"${fname}\" width=\"100%\" height=\"$minheight\"> </iframe>\n"
269 fi
270 fi
271
272 ##
273 ## Image
274 ##
275 if [ ${myarr[1]} == "image" ]
276
277 then
278 imgcount=$[$imgcount+1]
279 #restore file suffix for html
280 ftype=`file ${myarr[2]}`
281 zoomlevel=${myarr[4]}
282 zoomenable=${myarr[5]}
283 align=${myarr[6]}
284 #####echo "zoomenable:${zoomenable}, align:${align}"
285 if [[ $ftype == *JPEG* ]]
286 then
287 suffix=".jpg"
288 fi
289 if [[ $ftype == *SVG* ]]
290 then
291 suffix=".svg"
292 fi
293 if [[ $ftype == *PNG* ]]
294 then
295 suffix=".png"
296 fi
297
298 image=`basename ${myarr[2]}`
299 image=${image%.dat}
300 image="${image}${suffix}"
301 cp ${myarr[2]} ${galaxypath}/${image}
302
303 if [[ ${align} == "none" ]]
304 then
305 alignstring=""
306 alignstring2=""
307 else
308 alignstring="<div float=\"${align}\">"
309 alignstring2="</div>"
310
311 alignstring="align=\"${align}\""
312 alignstring2=""
313 fi
314
315
316 if [[ ${zoomlevel} -eq 0 ]]
317 then
318 widthstring=""
319 else
320 widthstring="width=\"${zoomlevel}\""
321 fi
322
323 if [[ ${zoomlevel} -eq 0 || ${zoomenable} == "N" ]]
324 then
325 contentline="${contentline}<span id=\"img${imgcount}\"> <img src=\"${image}\" ${alignstring} ${widthstring} alt=\"loading image..\"/></span>"
326 else
327 contentline="${contentline}<span class=\"zoomme\" id=\"img${imgcount}\"> <img src=\"${image}\" ${alignstring} ${widthstring} alt=\"loading image..\"/></span>"
328 fi
329
330 fi
331
332 ##
333 ## Table
334 ##
335 if [ ${myarr[1]} == "table" ]
336 then
337
338 maxlines=50000
339 tsvfile_orig=${myarr[2]}
340 tsvfile="tablehead.tsv"
341 fname=`basename ${tsvfile_orig}`
342 fname=${fname%.*}
343 fancy=${myarr[4]}
344 makelinks=${myarr[5]}
345 iframeid="iframe"$iframecount
346 #echo "\nmakelinks: $makelinks fancy: $fancy <br>"
347
348 #TODO client side database for large files. For now only display first section of file and add download link
349 numlines=`wc -l ${tsvfile_orig} |cut -d" " -f1`
350
351 head -${maxlines} ${tsvfile_orig} > tsvtmpfile
352
353 #remove any empty or header lines (lines starting with #, unless vcf file, then keep #CHROM line)
354 awk 'BEGIN{
355 FS="\t"
356 OFS="\t"
357 }{
358 if((index($0,"#")==1 && index($0,"#CHROM")!=1) || $0==""){
359 headerlines++
360 }
361 else print $0
362
363 }END{}' tsvtmpfile > ${tsvfile}
364
365 if [[ $makelinks == "Y" ]]
366 then
367 col=${myarr[6]}
368 prefix=${myarr[7]}
369 suffix=${myarr[8]}
370 urlitems=${myarr[9]}
371 minw=${myarr[10]}
372 suffix=${suffix/emptycol/}
373 suffix=${suffix/==quote==/&}
374 prefix=${prefix/emptycol/}
375 prefix=${prefix/==quote==/&}
376 prefix=${prefix/==colon==/:}
377
378 # unpack archive of files to link to if present
379 if [[ ${urlitems} != None ]]
380 then
381 oldfname=$fname
382 decompressArchive ${urlitems}
383 prefix=archive_${fname}/${prefix}
384 fname=$oldfname
385 fi
386
387
388 #edit the table to include links
389 awk 'BEGIN{
390 FS="\t"
391 OFS="\t"
392 url="'"$prefix"'"
393 url2="'"$suffix"'"
394 iframeid="'"$iframeid"'"
395 prefix="<a href=\42"
396 suffix="\42 onclick=\42resizeIframe("iframeid")\42>"
397 col="'"$col"'"
398 end="</a>"
399 }{
400 if(FNR==1)
401 print $0
402 else{
403 $col=prefix""url""$col""url2""suffix""$col""end
404 print $0
405 }
406 }END{}' ${tsvfile} > ${tsvfile}2
407
408 else
409 minw=${myarr[6]}
410 cp ${tsvfile} ${tsvfile}2
411 fi
412
413 iframecount=$[$iframecount+1]
414 if [ $fancy == "Y" ]
415 then
416 perl ${repositorypath}/tsv2html.pl < ${tsvfile}2 > ${galaxypath}/htmltable_${fname}.html
417 contentline="${contentline}\n<iframe class=\"invisibleframe fancyiframe\" id=\"$iframeid\" src=\"htmltable_${fname}.html\" width=\"100%\" style=\"height: 760px; min-height: 525px; overflow-y: hidden; overflow-x: scroll\" ></iframe>"
418 iframecount=$[$iframecount+1]
419 else
420 perl ${repositorypath}/tsv2html_simple.pl < ${tsvfile}2 > ${galaxypath}/htmltable_${fname}.html
421 contentline="${contentline}\n<iframe class=\"unfancyiframe invisibleframe\" id=\"$iframeid\" src=\"htmltable_${fname}.html\" scrolling=\"no\" style=\"min-width: ${minw}px; max-width: 100%; vertical-align: top;\" onload=\"resizeIframe(this)\"></iframe>"
422 iframecount=$[$iframecount+1]
423 fi
424
425 if [[ $numlines -gt ${maxlines} ]]
426 then
427 tablename=`basename ${tsvfile_orig}`
428 cp ${tsvfile_orig} ${galaxypath}/$tablename
429 contentline="${contentline}<br/>\nLarge tables will be supported soon. The first ${maxlines} lines are shown here, and you can download the full file <a href=\"${tablename}\">here</a>."
430 fi
431 fi
432
433 ##
434 ## PDF
435 ##
436 if [[ ${myarr[1]} == "pdf" ]]
437 then
438 pdffile=${myarr[2]}
439 fname=`basename ${pdffile}`
440 fname=${fname%.dat}
441 pdfname="${fname}.pdf"
442 cp ${pdffile} "${galaxypath}/${pdfname}"
443
444 width=1000
445 height=800
446 echo -e "<html><body><object data=\"${pdfname}\" type=\"application/pdf\" width=\"$width\" height=\"$height\"><embed src=\"${pdfname}\" type=\"application/pdf\" /><p>It appears you have no PDF plugin for your browser. No biggie... you can <a href=\"${pdfname}\">click here to download the PDF file.</a></p></object></body></html>" > "${galaxypath}/${fname}.html"
447 width=$[$width+10]
448 height=$[$height+10]
449 contentline="${contentline}\n<iframe src=\"${fname}.html\" width=\"${width}\" height=\"${height}\"></iframe>\n"
450
451 fi
452
453 ##
454 ## HTML
455 ##
456 if [[ ${myarr[1]} == "htmlfile" ]]
457 then
458 htmlfile=${myarr[2]}
459 height=${myarr[4]}
460 fname=`basename ${htmlfile}`
461 fname=${fname%.dat}
462 htmlname="${fname}.html"
463 cp ${htmlfile} "${galaxypath}/${htmlname}"
464
465 contentline="${contentline}\n<iframe class=\"invisibleframe\" src=\"${htmlname}\" width=\"100%\" height=\"${height}px\"></iframe>\n"
466 fi
467
468
469 if [[ ${myarr[1]} == "htmlpage" ]]
470 then
471 url=${myarr[2]}
472 url=${url//==colon==/:}
473 url=${url//==fslash==//}
474 height=${myarr[4]}
475
476 contentline="${contentline}\n<iframe class=\"invisibleframe\" src=\"${url}\" width=\"100%\" height=\"${height}px\"></iframe>\n"
477 fi
478
479 ##
480 ## Web Link
481 ##
482 if [ ${myarr[1]} == "weblink" ]
483 then
484 url=${myarr[2]}
485 linktext=${myarr[4]}
486 url=${url/==colon==/:}
487 url=${url/==quote==/&}
488
489 contentline="${contentline}<a href=\"${url}\" target=\"_blank\">${linktext}</a>"
490 fi
491
492
493 ##
494 ## Genome Browser
495 ##
496 if [ ${myarr[1]} == "genomebrowser" ]
497 then
498 # parse inputs
499
500 apiid=${myarr[4]}
501 servername=${myarr[5]}
502 buildver=${myarr[2]}
503
504 #TODO
505 ftype="vcf"
506
507 servername=${servername/==colon==/:}
508
509 ## parse and prepare all tracks
510 gbcount=$[$gbcount+1]
511 gbfilelist=${tracklist}
512 userTracks=""
513 #IFS=',' read -a gbfilearray <<< ${gbfilelist}
514 gbfilearray=(${gbfilelist//,/ })
515 for gbfile in "${gbfilearray[@]}"
516 do
517 # gbfile is in format "browsernum:file"
518 #IFS=':' read -a gbfileinfo <<< ${gbfile}
519 gbfileinfo=(${gbfile//:/ })
520 if [[ ${gbfileinfo[0]} == $gbcount ]]
521 then
522
523 ftype=${gbfileinfo[3]}
524 if [ $ftype == "vcf" ]
525 then
526 gbfilename=${gbfileinfo[1]}
527 gbfilelabel=${gbfileinfo[2]}
528 gbfilelabel=${gbfilelabel//==space==/ }
529 fname=`basename ${gbfilename}`
530 fname=${fname%.dat}
531 newgbfilename="${fname}.vcf"
532
533
534 cp ${gbfilename} "${galaxypath}/${newgbfilename}"
535 bgzip "${galaxypath}/${newgbfilename}"
536 tabix -p vcf "${galaxypath}/${newgbfilename}.gz"
537
538 userTracks="${userTracks},
539 {name: '${gbfilelabel}',
540 uri: '${servername}/datasets/${apiid}/display/${newgbfilename}.gz',
541 tier_type: 'tabix',
542 payload: 'vcf'}
543 "
544 fi
545
546 if [ $ftype == "bam" ]
547 then
548 gbfilename=${gbfileinfo[1]}
549 gbfilelabel=${gbfileinfo[2]}
550 gbfilelabel=${gbfilelabel//==space==/ }
551 fname=`basename ${gbfilename}`
552 fname=${fname%.dat}
553 newgbfilename="${fname}.bam"
554
555 # link to bam instead of copying
556 ln -s ${gbfilename} "${galaxypath}/${newgbfilename}"
557 samtools index "${galaxypath}/${newgbfilename}"
558
559 userTracks="${userTracks},
560 {name: '${gbfilelabel}',
561 bamURI: '${servername}/datasets/${apiid}/display/${newgbfilename}'}
562 "
563
564 fi
565 fi
566 done
567
568
569
570 if [ ${buildver} == "hg18" ]
571 then
572 coordSystem="coordSystem: {
573 speciesName: 'Human',
574 taxon: 9606,
575 auth: 'NCBI',
576 version: '36',
577 ucscName: 'hg18'
578 },"
579
580 chains="chains: {
581 hg19ToHg18: new Chainset('https://www.biodalliance.org/das/hg19ToHg18/', 'GRCh37', 'NCBI36',
582 {
583 speciesName: 'Human',
584 taxon: 9606,
585 auth: 'GRCh',
586 version: 37
587 })
588 },"
589
590 genesTrack="{name: 'Genes',
591 desc: 'Gene structures from Ensembl 54',
592 uri: 'https://www.biodalliance.org/das/hsa_54_36p/',
593 collapseSuperGroups: true,
594 provides_karyotype: true,
595 provides_search: true,
596 provides_entrypoints: true,
597 maxbins: false}, "
598
599 repeatsTrack="{name: 'Repeats',
600 desc: 'Repeat annotation from Ensembl 59',
601 bwgURI: 'https://www.biodalliance.org/datasets/repeats.bb',
602 stylesheet_uri: 'https://www.biodalliance.org/stylesheets/bb-repeats.xml'}"
603
604
605 # default is hg19
606 else
607 coordSystem="coordSystem: {
608 speciesName: 'Human',
609 taxon: 9606,
610 auth: 'NCBI',
611 version: '37',
612 ucscName: 'hg19'
613 },"
614
615 chains=""
616
617 genesTrack="{name: 'Genes',
618 desc: 'Gene structures from GENCODE 19',
619 bwgURI: 'https://www.biodalliance.org/datasets/gencode.bb',
620 stylesheet_uri: 'https://www.biodalliance.org/stylesheets/gencode.xml',
621 collapseSuperGroups: true,
622 trixURI: 'https://www.biodalliance.org/datasets/geneIndex.ix'},"
623
624 repeatsTrack="{name: 'Repeats',
625 desc: 'Repeat annotation from Ensembl 59',
626 bwgURI: 'https://www.biodalliance.org/datasets/repeats.bb',
627 stylesheet_uri: 'https://www.biodalliance.org/stylesheets/bb-repeats.xml'},"
628
629 fi
630
631 contentline="${contentline}
632 <script language=\"javascript\" src=\"https://www.biodalliance.org/release-0.13/dalliance-compiled.js\"></script>
633 <script language=\"javascript\">
634 new Browser({
635 chr: '1',
636 viewStart: 0,
637 viewEnd: 100000,
638 cookieKey: 'human',
639
640 ${coordSystem}
641
642 ${chains}
643 sources: [{name: 'Genome',
644 twoBitURI: 'https://www.biodalliance.org/datasets/${buildver}.2bit',
645 tier_type: 'sequence'},
646 ${genesTrack},
647 ${repeatsTrack},
648 {name: 'Conservation',
649 desc: 'Conservation',
650 bwgURI: 'https://www.biodalliance.org/datasets/phastCons46way.bw',
651 noDownsample: true}
652 ${userTracks}
653 ],
654
655
656
657
658 browserLinks: {
659 Ensembl: 'http://www.ensembl.org/Homo_sapiens/Location/View?r=${chr}:${start}-${end}',
660 UCSC: 'http://genome.ucsc.edu/cgi-bin/hgTracks?db=${buildver}&position=chr${chr}:${start}-${end}',
661 Sequence: 'http://www.derkholm.net:8080/das/${buildver}comp/sequence?segment=${chr}:${start},${end}'
662 }
663
664 });
665 </script>
666
667 <div id=\"svgHolder\"></div>
668 "
669 fi
670
671 ##
672 ## Link to Dataset
673 ##
674 if [ ${myarr[1]} == "link" ]
675 then
676 linkfile=${myarr[2]}
677 apiid=${myarr[4]}
678 isireport=${myarr[5]}
679 linkfilename=`basename ${linkfile}`
680 linktext=${myarr[6]}
681
682
683 #check for some basic filetypes
684 ftype=`file $linkfile`
685 if [[ $ftype == *HTML* ]]
686 then
687 linkfilename=${linkfilename%.dat}
688 linkfilename=${linkfilename}.html
689 fi
690 if [[ $ftype == *PNG* ]]
691 then
692 linkfilename=${linkfilename%.dat}
693 linkfilename=${linkfilename}.png
694 fi
695 if [[ $ftype == *SVG* ]]
696 then
697 linkfilename=${linkfilename%.dat}
698 linkfilename=${linkfilename}.svg
699 fi
700 if [[ $ftype == *JPEG* ]]
701 then
702 linkfilename=${linkfilename%.dat}
703 linkfilename=${linkfilename}.jpg
704 fi
705
706
707 if [[ ${isireport} == "Y" ]]
708 then
709 linkfilename="/datasets/${apiid}/display/"
710 else
711 cp ${linkfile} "${galaxypath}/${linkfilename}"
712 fi
713
714 contentline="${contentline}<a href=\"${linkfilename}\">${linktext}</a>"
715 fi
716
717 ##
718 ## Links to Archive Contents
719 ##
720 if [[ ${myarr[1]} == "links" ]]
721 then
722 archive=${myarr[2]}
723 decompressArchive $archive
724
725 # add links to webpage
726 # separate line for each folder, files within folder on same line
727 for linkfile in `ls ${galaxypath}/archive_${fname}/ |sort -V`
728 do
729 #echo "<br/> ->making link to file: $linkfile "
730 if [ -d ${galaxypath}/archive_${fname}/$linkfile ] # if directory, add break, and list all contained files, max level 1 deep
731 then
732 #echo "<br/> ->is directory, entering: $linkfile "
733 #ls ${galaxypath}/archive_${fname}/$linkfile
734 contentline="${contentline}"
735 for linkfile2 in `ls ${galaxypath}/archive_${fname}/$linkfile | sort -V`
736 do
737 #echo "<br/> ->making link to file: ${galaxypath}/archive_${fname}/$linkfile2"
738 if [ -f ${galaxypath}/archive_${fname}/$linkfile/$linkfile2 ] # if directory, add break, and list all contained files, max level 1 deep
739 then
740 #echo "<br/> ->is file, making link: $linkfile "
741 label=`basename $linkfile2`
742 label=${label%.*}
743 contentline="${contentline}<a class=\"mylinks\" href=\"archive_${fname}/${linkfile}/${linkfile2}\">${label}</a>&nbsp;\n "
744 fi
745 done
746 elif [ -f ${galaxypath}/archive_${fname}/$linkfile ]
747 then
748 label=`basename ${galaxypath}/archive_${fname}/$linkfile`
749 label=${label%.*}
750 contentline="${contentline}<a class=\"mylinks\" href=\"archive_${fname}/${linkfile}\">$label</a>&nbsp;\n"
751 fi
752 done
753
754
755 fi
756
757 if [[ ${myarr[3]} == "Y" ]]
758 then
759 contentline="${contentline}<br/>\n"
760 fi
761 fi
762 done
763
764 echo "${contentline}"
765 }
766
767 ##
768 ## Create HTML content for iReport
769 ##
770 createMainPage (){
771 page=$1
772 tabtitles=$2 # comma-separated list of tab titles
773 tabitems=$3 # colon-sparated list of tabs specifications
774 iframecount=1 # keep track of number of iFrames so that they can be referenced by ID
775 minwidth=$4 # width of page
776 gbtracks=$5 # genome browser track information
777
778 echo "createMainPage: tabitems: $tabitems. tabtitles: $tabtitles. gbtracks: $gbtracks"
779 # create correct number of tabs
780 count=0
781
782 tabtitles=${tabtitles//,/ }
783 tabtitles=${tabtitles//==colon==/:}
784 tabslist="<ul>\n"
785 mytabs=""
786
787 for title in $tabtitles
788 do
789 # Create list of tabs
790 count=$[count+1]
791 title2=${title//_s_/ }
792 tabslist="${tabslist} <li><a href=\"#tabs-${count}\">${title2}</a></li>\n"
793
794 # Create tabs with content
795 tabcontent=$(makeTabContent $title "$tabitems" "$gbtracks")
796 mytabs="${mytabs}\n<div id=\"tabs-${count}\">\n"
797 mytabs="${mytabs}${tabcontent}"
798 mytabs="${mytabs}\n</div>\n"
799 done
800 tabslist="${tabslist}</ul>"
801
802 ## Output the webpage
803 echo -e "<!doctype html>
804 <head>
805 <meta charset=\"utf-8\">
806 <title>iReport</title>
807 <link rel=\"stylesheet\" href=\"jquery-ui.css\">
808 <link rel=\"stylesheet\" href=\"ireport_css.css\">
809 <link rel=\"stylesheet\" href=\"md.css\">
810 <script type=\"text/javascript\" src=\"jquery-1.10.2.js\"></script>
811 <script type=\"text/javascript\" src=\"jquery-ui.js\"></script>
812 <script type=\"text/javascript\" src=\"iframe-resizer/src/iframeResizer.js\"></script>
813 <script type=\"text/javascript\" src=\"jquery.zoom.js\"></script>
814 <script type=\"text/javascript\" src=\"ireport_jquery.js\"></script>
815 <script type=\"text/javascript\" src=\"ireport_javascript.js\"></script>
816 </head>
817 <body>
818 <div id=\"tabs\" style=\"display:inline-block; min-height:100%; min-width:${minwidth}px\">
819 $tabslist
820
821 $mytabs
822 </div>
823 </body>
824 </html>" > $page
825 }