changeset 53:0ef7f80ea061 draft

Uploaded
author davidvanzessen
date Thu, 25 Feb 2021 13:39:50 +0000
parents 124b7fd92a3e
children 81b3eb11ed2c
files .gitattributes complete.sh experimental_design/experimental_design.sh igblast/igblast.sh imgt_loader/imgt_loader.sh report_clonality/r_wrapper.sh
diffstat 6 files changed, 571 insertions(+), 569 deletions(-) [+]
line wrap: on
line diff
--- a/.gitattributes	Thu Feb 25 13:36:15 2021 +0000
+++ b/.gitattributes	Thu Feb 25 13:39:50 2021 +0000
@@ -1,2 +1,4 @@
 # Auto detect text files and perform LF normalization
 * text=auto
+# Convert to LF line endings on checkout.
+*.sh text eol=lf
--- a/complete.sh	Thu Feb 25 13:36:15 2021 +0000
+++ b/complete.sh	Thu Feb 25 13:39:50 2021 +0000
@@ -1,72 +1,72 @@
-#!/bin/bash
-set -e
-inputFiles=($1)
-outputDir=$3
-outputFile=$3/index.html #$1
-clonalType=$4
-species=$5
-locus=$6
-filterproductive=$7
-clonality_method=$8
-
-html=$2
-dir="$(cd "$(dirname "$0")" && pwd)"
-array=("$@")
-echo "<html><h3>Progress</h3><table><tr><td>info</td></tr>" > $html
-echo "<tr><td>-----------------------------------</td></tr>" >> $html
-
-#mkdir $PWD/igblastdatabase
-#unzip $dir/database.zip -d $PWD/igblastdatabase/
-#export IGDATA=$PWD/igblastdatabase/
-
-echo "python: `which python`"
-echo "R: `which R`"
-echo "Rscript: `which Rscript`"
-
-id=""
-forwardSlash="/"
-mergerInput=()
-echo "Before loop"
-count=1
-for current in "${inputFiles[@]}"
-do
-	if [[ "$current" != *"$forwardSlash"* ]]; then
-			id="$current"
-			mergerInput+=($id)
-			count=1
-			continue
-	fi
-	echo "working on $current"
-	fileName=$(basename $current)
-	fileName="${fileName%.*}"
-	parsedFileName="$PWD/$fileName.parsed"
-	f=$(file $current)
-	zipType="Zip archive"
-	zxType="XZ compressed data"
-	echo "filetype of ${id}: $f"
-  	if [[ "$f" == *"$zipType"* ]] || [[ "$f" == *"$zxType"* ]]
-	then
-		echo "<tr><td>Sample $count of patient $id is an archive file, using IMGT Loader</td></tr>" >> $html
-	  	fileName=$(basename $current)
-		bash ${dir}/imgt_loader/imgt_loader.sh $current $parsedFileName "${fileName}"
-	else
-		echo "<tr><td>Sample $count of patient $id is not a zip file so assuming fasta/fastq, using igBLASTn</td></tr>" >> $html
-		bash ${dir}/igblast/igblast.sh $current "$species" $locus $parsedFileName
-	fi
-	mergerInput+=($parsedFileName)
-	count=$((count+1))
-done
-
-echo "<tr><td>-----------------------------------</td></tr>" >> $html
-echo "<tr><td>merging</td></tr>" >> $html
-
-bash $dir/experimental_design/experimental_design.sh ${mergerInput[*]} $PWD/merged.txt
-
-echo "<tr><td>done</td></tr>" >> $html
-echo "<tr><td>-----------------------------------</td></tr>" >> $html
-echo "<tr><td>plotting</td></tr>" >> $html
-
-echo "after ED"
-
-bash $dir/report_clonality/r_wrapper.sh $PWD/merged.txt $2 $outputDir $clonalType "$species" "$locus" $filterproductive $clonality_method
-
+#!/bin/bash
+set -e
+inputFiles=($1)
+outputDir=$3
+outputFile=$3/index.html #$1
+clonalType=$4
+species=$5
+locus=$6
+filterproductive=$7
+clonality_method=$8
+
+html=$2
+dir="$(cd "$(dirname "$0")" && pwd)"
+array=("$@")
+echo "<html><h3>Progress</h3><table><tr><td>info</td></tr>" > $html
+echo "<tr><td>-----------------------------------</td></tr>" >> $html
+
+#mkdir $PWD/igblastdatabase
+#unzip $dir/database.zip -d $PWD/igblastdatabase/
+#export IGDATA=$PWD/igblastdatabase/
+
+echo "python: `which python`"
+echo "R: `which R`"
+echo "Rscript: `which Rscript`"
+
+id=""
+forwardSlash="/"
+mergerInput=()
+echo "Before loop"
+count=1
+for current in "${inputFiles[@]}"
+do
+	if [[ "$current" != *"$forwardSlash"* ]]; then
+			id="$current"
+			mergerInput+=($id)
+			count=1
+			continue
+	fi
+	echo "working on $current"
+	fileName=$(basename $current)
+	fileName="${fileName%.*}"
+	parsedFileName="$PWD/$fileName.parsed"
+	f=$(file $current)
+	zipType="Zip archive"
+	zxType="XZ compressed data"
+	echo "filetype of ${id}: $f"
+  	if [[ "$f" == *"$zipType"* ]] || [[ "$f" == *"$zxType"* ]]
+	then
+		echo "<tr><td>Sample $count of patient $id is an archive file, using IMGT Loader</td></tr>" >> $html
+	  	fileName=$(basename $current)
+		bash ${dir}/imgt_loader/imgt_loader.sh $current $parsedFileName "${fileName}"
+	else
+		echo "<tr><td>Sample $count of patient $id is not a zip file so assuming fasta/fastq, using igBLASTn</td></tr>" >> $html
+		bash ${dir}/igblast/igblast.sh $current "$species" $locus $parsedFileName
+	fi
+	mergerInput+=($parsedFileName)
+	count=$((count+1))
+done
+
+echo "<tr><td>-----------------------------------</td></tr>" >> $html
+echo "<tr><td>merging</td></tr>" >> $html
+
+bash $dir/experimental_design/experimental_design.sh ${mergerInput[*]} $PWD/merged.txt
+
+echo "<tr><td>done</td></tr>" >> $html
+echo "<tr><td>-----------------------------------</td></tr>" >> $html
+echo "<tr><td>plotting</td></tr>" >> $html
+
+echo "after ED"
+
+bash $dir/report_clonality/r_wrapper.sh $PWD/merged.txt $2 $outputDir $clonalType "$species" "$locus" $filterproductive $clonality_method
+
--- a/experimental_design/experimental_design.sh	Thu Feb 25 13:36:15 2021 +0000
+++ b/experimental_design/experimental_design.sh	Thu Feb 25 13:39:50 2021 +0000
@@ -1,4 +1,4 @@
-
-dir="$(cd "$(dirname "$0")" && pwd)"
-
-Rscript --verbose $dir/experimental_design.r $@ 2>&1
+
+dir="$(cd "$(dirname "$0")" && pwd)"
+
+Rscript --verbose $dir/experimental_design.r $@ 2>&1
--- a/igblast/igblast.sh	Thu Feb 25 13:36:15 2021 +0000
+++ b/igblast/igblast.sh	Thu Feb 25 13:39:50 2021 +0000
@@ -1,28 +1,28 @@
-set -e
-
-dir="$(cd "$(dirname "$0")" && pwd)"
-
-input=$1
-species=$2
-locus=$3
-output=$4
-
-declare -A speciesdict
-
-speciesdict=(["Rattus norvegicus functional"]="rat" ["Rattus norvegicus non-functional"]="rat" ["Oryctolagus cuniculus functional"]="rabbit" ["Oryctolagus cuniculus non-functional"]="rabbit" ["Mus musculus functional"]="mouse" ["Mus musculus non-functional"]="mouse" ["Homo sapiens functional"]="human" ["Homo sapiens non-functional"]="human" ["Macaca mulatta non-functional"]="rhesus_monkey" ["Macaca mulatta functional"]="rhesus_monkey")
-
-echo "Species: $species ${speciesdict[$species]}"
-
-species="${speciesdict[$species]}"
-
-if [ "$species" == "" ]
-then
-	>&2 echo "Species not possible with igBLASTn, use IMGT"
-	exit 1
-fi
-
-echo "$input $species $locus $output"
-
-java -Xmx16G -jar $IGBLASTWRP/igblastwrp.jar -p 4 -S $species -R $locus ${input} $PWD/blasted_output 2>&1
-
-Rscript --verbose $dir/igblast.r "$PWD/blasted_output.L2.txt" "$output" 2>&1
+set -e
+
+dir="$(cd "$(dirname "$0")" && pwd)"
+
+input=$1
+species=$2
+locus=$3
+output=$4
+
+declare -A speciesdict
+
+speciesdict=(["Rattus norvegicus functional"]="rat" ["Rattus norvegicus non-functional"]="rat" ["Oryctolagus cuniculus functional"]="rabbit" ["Oryctolagus cuniculus non-functional"]="rabbit" ["Mus musculus functional"]="mouse" ["Mus musculus non-functional"]="mouse" ["Homo sapiens functional"]="human" ["Homo sapiens non-functional"]="human" ["Macaca mulatta non-functional"]="rhesus_monkey" ["Macaca mulatta functional"]="rhesus_monkey")
+
+echo "Species: $species ${speciesdict[$species]}"
+
+species="${speciesdict[$species]}"
+
+if [ "$species" == "" ]
+then
+	>&2 echo "Species not possible with igBLASTn, use IMGT"
+	exit 1
+fi
+
+echo "$input $species $locus $output"
+
+java -Xmx16G -jar $IGBLASTWRP/igblastwrp.jar -p 4 -S $species -R $locus ${input} $PWD/blasted_output 2>&1
+
+Rscript --verbose $dir/igblast.r "$PWD/blasted_output.L2.txt" "$output" 2>&1
--- a/imgt_loader/imgt_loader.sh	Thu Feb 25 13:36:15 2021 +0000
+++ b/imgt_loader/imgt_loader.sh	Thu Feb 25 13:39:50 2021 +0000
@@ -1,74 +1,74 @@
-#!/bin/bash
-input=$1
-output=$2
-name=$3
-dir="$(cd "$(dirname "$0")" && pwd)"
-mkdir -p $PWD/$name/files
-f=$(file $input)
-zip7Type="7-zip archive"
-tarType="tar archive"
-bzip2Type="bzip2 compressed"
-gzipType="gzip compressed"
-zipType="Zip archive"
-rarType="RAR archive"
-zxType="XZ compressed data"
-
-if [[ "$f" == *"$zip7Type"* ]]; then
-	echo "7-zip"
-	echo "Trying: 7za e $input -o$PWD/files/"
-	7za e $input -o$PWD/$name/files
-fi
-
-if [[ "$f" == *"$tarType"* ]]
-then
-	echo "tar archive"
-	echo "Trying: tar xvf $input -C $PWD/files/"
-	tar -xvf $input -C $PWD/$name/files
-fi
-
-if [[ "$f" == *"$bzip2Type"* ]]
-then
-	echo "bzip2 compressed data"
-	echo "Trying: tar jxf $input -C $PWD/files/"
-	tar -jxf $input -C $PWD/$name/files
-fi
-
-if [[ "$f" == *"$gzipType"* ]]
-then
-	echo "gzip compressed data"
-	echo "Trying: tar xvzf $input -C $PWD/files/"
-	tar -xvzf $input -C $PWD/$name/files
-fi
-
-if [[ "$f" == *"$zipType"* ]]
-then
-	echo "Zip archive"
-	echo "Trying: unzip $input -d $PWD/files/"
-	unzip $input -d $PWD/$name/files > $PWD/unziplog.log
-fi
-
-if [[ "$f" == *"$rarType"* ]]
-then
-	echo "RAR archive"
-	echo "Trying: unrar e $input $PWD/files/"
-	unrar e $input $PWD/$name/files
-fi
-
-if [[ "$f" == *"$zxType"* ]]
-then
-	echo "xz compressed data"
-	echo "Trying: tar -xJf $input -C $PWD/files/"
-	tar xJf $input -C $PWD/$name/files
-fi
-find $PWD/$name/files -iname "1_*" -exec cat {} + > $PWD/$name/summ.txt
-find $PWD/$name/files -iname "3_*" -exec cat {} + > $PWD/$name/sequences.txt
-find $PWD/$name/files -iname "4_*" -exec cat {} + > $PWD/$name/gapped_aa.txt
-find $PWD/$name/files -iname "5_*" -exec cat {} + > $PWD/$name/aa.txt
-find $PWD/$name/files -iname "6_*" -exec cat {} + > $PWD/$name/junction.txt
-
-echo "summ.txt `cat $PWD/$name/summ.txt | wc -l`"
-echo "aa.txt `cat $PWD/$name/aa.txt | wc -l`"
-
-#python $dir/imgt_loader.py --summ $PWD/$name/summ.txt --aa $PWD/$name/aa.txt --junction $PWD/$name/junction.txt --output $output
-
-Rscript --verbose $dir/imgt_loader.r $PWD/$name/summ.txt $PWD/$name/sequences.txt $PWD/$name/aa.txt $PWD/$name/junction.txt $PWD/$name/gapped_aa.txt $output 2>&1
+#!/bin/bash
+input=$1
+output=$2
+name=$3
+dir="$(cd "$(dirname "$0")" && pwd)"
+mkdir -p $PWD/$name/files
+f=$(file $input)
+zip7Type="7-zip archive"
+tarType="tar archive"
+bzip2Type="bzip2 compressed"
+gzipType="gzip compressed"
+zipType="Zip archive"
+rarType="RAR archive"
+zxType="XZ compressed data"
+
+if [[ "$f" == *"$zip7Type"* ]]; then
+	echo "7-zip"
+	echo "Trying: 7za e $input -o$PWD/files/"
+	7za e $input -o$PWD/$name/files
+fi
+
+if [[ "$f" == *"$tarType"* ]]
+then
+	echo "tar archive"
+	echo "Trying: tar xvf $input -C $PWD/files/"
+	tar -xvf $input -C $PWD/$name/files
+fi
+
+if [[ "$f" == *"$bzip2Type"* ]]
+then
+	echo "bzip2 compressed data"
+	echo "Trying: tar jxf $input -C $PWD/files/"
+	tar -jxf $input -C $PWD/$name/files
+fi
+
+if [[ "$f" == *"$gzipType"* ]]
+then
+	echo "gzip compressed data"
+	echo "Trying: tar xvzf $input -C $PWD/files/"
+	tar -xvzf $input -C $PWD/$name/files
+fi
+
+if [[ "$f" == *"$zipType"* ]]
+then
+	echo "Zip archive"
+	echo "Trying: unzip $input -d $PWD/files/"
+	unzip $input -d $PWD/$name/files > $PWD/unziplog.log
+fi
+
+if [[ "$f" == *"$rarType"* ]]
+then
+	echo "RAR archive"
+	echo "Trying: unrar e $input $PWD/files/"
+	unrar e $input $PWD/$name/files
+fi
+
+if [[ "$f" == *"$zxType"* ]]
+then
+	echo "xz compressed data"
+	echo "Trying: tar -xJf $input -C $PWD/files/"
+	tar xJf $input -C $PWD/$name/files
+fi
+find $PWD/$name/files -iname "1_*" -exec cat {} + > $PWD/$name/summ.txt
+find $PWD/$name/files -iname "3_*" -exec cat {} + > $PWD/$name/sequences.txt
+find $PWD/$name/files -iname "4_*" -exec cat {} + > $PWD/$name/gapped_aa.txt
+find $PWD/$name/files -iname "5_*" -exec cat {} + > $PWD/$name/aa.txt
+find $PWD/$name/files -iname "6_*" -exec cat {} + > $PWD/$name/junction.txt
+
+echo "summ.txt `cat $PWD/$name/summ.txt | wc -l`"
+echo "aa.txt `cat $PWD/$name/aa.txt | wc -l`"
+
+#python $dir/imgt_loader.py --summ $PWD/$name/summ.txt --aa $PWD/$name/aa.txt --junction $PWD/$name/junction.txt --output $output
+
+Rscript --verbose $dir/imgt_loader.r $PWD/$name/summ.txt $PWD/$name/sequences.txt $PWD/$name/aa.txt $PWD/$name/junction.txt $PWD/$name/gapped_aa.txt $output 2>&1
--- a/report_clonality/r_wrapper.sh	Thu Feb 25 13:36:15 2021 +0000
+++ b/report_clonality/r_wrapper.sh	Thu Feb 25 13:39:50 2021 +0000
@@ -1,391 +1,391 @@
-#!/bin/bash
-
-inputFile=$1
-outputDir=$3
-outputFile=$3/index.html #$2
-clonalType=$4
-species=$5
-locus=$6
-filterproductive=$7
-clonality_method=$8
-
-dir="$(cd "$(dirname "$0")" && pwd)"
-useD="false"
-if grep -q "$species.*${locus}D" "$dir/genes.txt" ; then
-	echo "species D region in reference db"
-	useD="true"
-fi
-echo "$species"
-if [[ "$species" == *"custom"* ]] ; then
-	loci=(${locus//;/ })
-	useD="true"
-	echo "${loci[@]}"
-	if [[ "${#loci[@]}" -eq "2" ]] ; then
-		useD="false"
-	fi
-fi
-mkdir $3
-cp $dir/genes.txt $outputDir
-Rscript --verbose $dir/RScript.r $inputFile $outputDir $outputDir $clonalType "$species" "$locus" $filterproductive ${clonality_method} 2>&1
-cp $dir/tabber.js $outputDir
-cp $dir/style.css $outputDir
-cp $dir/script.js $outputDir
-cp $dir/jquery-1.11.0.min.js $outputDir
-cp $dir/pure-min.css $outputDir
-cp $dir/IGH_junctie_analyse.png $outputDir
-samples=`cat $outputDir/samples.txt`
-
-echo "<html><center><h1><a href='index.html'>Click here for the results</a></h1>Tip: Open it in a new tab (middle mouse button or right mouse button -> 'open in new tab' on the link above)<br />" > $2
-echo "<table border = 1>" >> $2
-echo "<thead><tr><th>Donor/Replicate</th><th>All</th><th>Productive</th><th>Unique Productive</th><th>Unproductive</th><th>Unique Unproductive</th></tr></thead>" >> $2
-while IFS=, read sample all productive perc_prod productive_unique perc_prod_un unproductive perc_unprod unproductive_unique perc_unprod_un
-	do
-		echo "<tr><td>$sample</td>" >> $2
-		echo "<td>$all</td>" >> $2
-		if [[ "$productive" != "0" ]] ; then
-			echo "<td>$productive (${perc_prod}%)</td>" >> $2
-			echo "<td>$productive_unique (${perc_prod_un}%)</td>" >> $2
-			echo "<td>$unproductive (${perc_unprod}%)</td>" >> $2
-			echo "<td>$unproductive_unique (${perc_unprod_un}%)</td></tr>" >> $2
-		else
-			echo "<td colspan='4' style='background-color: red;'>No productive sequences!</td>" >> $2
-		fi
-done < $outputDir/productive_counting.txt
-echo "</table><br />" >> $2
-echo "Table showing the number and percentage of (unique) productive and unproductive sequences per donor and per replicate. <br />" >> $2
-echo "The definition of unique sequences is based on the clonal type definition filter setting chosen. " >> $2
-echo "</center></html>" >> $2
-
-echo "<html><head><title>Report on:" >> $outputFile
-
-mkdir $outputDir/circos
-cp -R $dir/circos/* $outputDir/circos/
-
-USECIRCOS="no"
-path_to_circos=$(which circos)
-if [ -x "$path_to_circos" ]; then
-	USECIRCOS="yes"
-fi
-
-echo "Using Circos: $USECIRCOS"
-sed -i "s%DATA_DIR%$outputDir/circos%" $outputDir/circos/circos.conf
-for sample in $samples; do #output the samples to a file and create the circos plots with the R script output
-	echo " $sample" >> $outputFile
-	
-	if [[ "$USECIRCOS" != "yes" ]]; then
-		continue
-	fi
-	
-	circos_file="$outputDir/${sample}_VJ_circos.txt"
-	sed -i -- 's%/%:%g' $circos_file
-	echo -e -n "labels$(cat ${circos_file})" > ${circos_file}
-	echo "Circos tools command:"
-	echo "cat \"${circos_file}\" | parse-table -configfile $dir/circos/parse-table.conf 2>&1 | make-conf -dir $outputDir/circos/"
-	cat "${circos_file}" | parse-table -configfile $dir/circos/parse-table.conf 2>&1 | make-conf -dir $outputDir/circos/
-
-	echo "Circos command:"
-	echo "circos -conf $outputDir/circos/circos.conf 2>&1"
-	circos -conf $outputDir/circos/circos.conf 2>&1
-	mv $outputDir/circos/circos.png $outputDir/circosVJ_${sample}.png
-	mv $outputDir/circos/circos.svg $outputDir/circosVJ_${sample}.svg
-	
-	
-	if [[ "$useD" == "true" ]] ; then
-		circos_file="$outputDir/${sample}_VD_circos.txt"
-		sed -i -- 's%/%:%g' $circos_file
-		echo -e -n "labels$(cat ${circos_file})" > ${circos_file}
-		cat "${circos_file}" | parse-table -configfile $dir/circos/parse-table.conf 2>&1 | make-conf -dir $outputDir/circos/
-		sed -i -- 's%/%:%g' $outputDir/circos/cells.txt
-		circos -conf $outputDir/circos/circos.conf 2>&1
-		mv $outputDir/circos/circos.png $outputDir/circosVD_${sample}.png
-		mv $outputDir/circos/circos.svg $outputDir/circosVD_${sample}.svg
-		
-		circos_file="$outputDir/${sample}_DJ_circos.txt"
-		sed -i -- 's%/%:%g' $circos_file
-		echo -e -n "labels$(cat ${circos_file})" > ${circos_file}
-		cat "${circos_file}" | parse-table -configfile $dir/circos/parse-table.conf 2>&1 | make-conf -dir $outputDir/circos/
-		sed -i -- 's%/%:%g' $outputDir/circos/cells.txt
-		circos -conf $outputDir/circos/circos.conf 2>&1
-		mv $outputDir/circos/circos.png $outputDir/circosDJ_${sample}.png
-		mv $outputDir/circos/circos.svg $outputDir/circosDJ_${sample}.svg
-	fi
-done
-echo "</title><script type='text/javascript' src='jquery-1.11.0.min.js'></script>" >> $outputFile
-echo "<link rel='stylesheet' type='text/css' href='pure-min.css'>" >> $outputFile
-echo "<script type='text/javascript' src='tabber.js'></script>" >> $outputFile
-echo "<script type='text/javascript' src='script.js'></script>" >> $outputFile
-echo "<link rel='stylesheet' type='text/css' href='style.css'></head>" >> $outputFile
-echo "<div class='tabber'><div class='tabbertab' title='Gene frequencies'>" >> $outputFile
-
-
-echo "<a href='VFPlot.pdf'><img src='VFPlot.png'/></a>" >> $outputFile
-if [[ "$useD" == "true" ]] ; then
-	echo "<a href='DFPlot.pdf'><img src='DFPlot.png'/></a>" >> $outputFile
-fi
-echo "<a href='VPlot.pdf'><img src='VPlot.png'/></a>" >> $outputFile
-if [[ "$useD" == "true" ]] ; then
-	echo "<a href='DPlot.pdf'><img src='DPlot.png'/></a>" >> $outputFile
-fi
-echo "<a href='JPlot.pdf'><img src='JPlot.png'/></a> <br />" >> $outputFile
-
-echo "<a href='DReadingFrame.pdf'><img src='DReadingFrame.png'/></a>" >> $outputFile
-
-cat $dir/naive_gene_freq.htm >> $outputFile
-
-echo "</div>" >> $outputFile
-
-echo "<div class='tabbertab' title='CDR3 Characteristics'>" >> $outputFile
-echo "<a href='CDR3LengthPlot.pdf'><img src='CDR3LengthPlot.png'/></a><br />" >> $outputFile
-echo "<a href='AAComposition.pdf'><img src='AAComposition.png'/></a>" >> $outputFile
-
-
-echo "<table class='pure-table pure-table-striped'>" >> $outputFile
-echo "<thead><tr><th>Donor</th><th>Median CDR3 Length</th></tr></thead>" >> $outputFile
-while read Sample median
-do
-	echo "<tr><td>$Sample</td><td>$median</td></tr>" >> $outputFile
-done < $outputDir/AAMedianBySample.txt
-echo "</table>" >> $outputFile
-
-cat $dir/naive_cdr3_char.htm >> $outputFile
-
-echo "</div>" >> $outputFile
-
-#Heatmaps
-
-count=1
-echo "<div class='tabbertab' title='Heatmaps'><div class='tabber'>" >> $outputFile
-for sample in $samples; do
-	echo "<div class='tabbertab' title='$sample'><table border='1'><tr>" >> $outputFile
-	if [[ "$useD" == "true" ]] ; then
-		echo "<td><a href='HeatmapVD_$sample.pdf'><img src='HeatmapVD_$sample.png'/></a></td>" >> $outputFile
-	fi
-	echo "<td><a href='HeatmapVJ_$sample.pdf'><img src='HeatmapVJ_$sample.png'/></a></td>" >> $outputFile
-	if [[ "$useD" == "true" ]] ; then
-		echo "<td><a href='HeatmapDJ_$sample.pdf'><img src='HeatmapDJ_$sample.png'/></a></td>" >> $outputFile
-	fi
-	echo "</tr></table></div>" >> $outputFile
-	count=$((count+1))
-done
-
-cat $dir/naive_heatmap.htm >> $outputFile
-
-echo "</div></div>" >> $outputFile
-
-echo "<div class='tabbertab' title='Compare Heatmaps'><table class='pure-table pure-table-striped'><thead><tr><th>ID</th><th>Include</th></tr></thead>" >> $outputFile
-for sample in $samples; do
-	echo "<tr><td>$sample</td><td><input type='checkbox' onchange=\"javascript:compareAdd('$sample')\" id='compare_checkbox_$sample'/></td></tr>" >> $outputFile
-done
-echo "</table><div name='comparisonarea'>" >> $outputFile
-echo "<table><tr id='comparison_table_vd'></tr></table>" >> $outputFile
-echo "<table><tr id='comparison_table_vj'></tr></table>" >> $outputFile
-echo "<table><tr id='comparison_table_dj'></tr></table>" >> $outputFile
-
-cat $dir/naive_compare.htm >> $outputFile
-
-echo "</div></div>" >> $outputFile
-
-
-#circos
-
-if [[ "$USECIRCOS" == "yes" ]]; then
-
-	echo "<div class='tabbertab' title='Circos'><div class='tabber'>" >> $outputFile
-	for sample in $samples; do
-		echo "<div class='tabbertab' title='$sample'><table border='1'><center>" >> $outputFile
-		if [[ "$useD" == "true" ]] ; then
-			echo "<tr><td>V-D</td><td><a href='circosVD_${sample}.svg'><img src='circosVD_${sample}.png' width='700' height='700'/></td></tr>" >> $outputFile
-		fi
-		echo "<tr><td>V-J</td><td><a href='circosVJ_${sample}.svg'><img src='circosVJ_${sample}.png' width='700' height='700'/></td></tr>" >> $outputFile
-		if [[ "$useD" == "true" ]] ; then
-			echo "<tr><td>D-J</td><td><a href='circosDJ_${sample}.svg'><img src='circosDJ_${sample}.png' width='700' height='700'/></td></tr>" >> $outputFile
-		fi
-		echo "<center></table></div>" >> $outputFile
-		count=$((count+1))
-	done
-	
-	cat $dir/naive_circos.htm >> $outputFile
-	
-	echo "</div></div>" >> $outputFile
-fi
-#echo "<div class='tabbertab' title='Interactive'><svg class='chart'></svg><script src='http://d3js.org/d3.v3.min.js'></script></div>" >> $outputFile
-
-hasReplicateColumn="$(if head -n 1 $inputFile | grep -q 'Replicate'; then echo 'Yes'; else echo 'No'; fi)"
-echo "$hasReplicateColumn"
-#if its a 'new' merged file with replicate info
-if [[ "$hasReplicateColumn" == "Yes" && "${clonality_method}" != "none" ]] ; then
-	if [[ "${clonality_method}" == "boyd" ]] ; then
-		echo "<div class='tabbertab' title='Clonality'><div class='tabber'>" >> $outputFile
-	else
-		echo "<div class='tabbertab' title='Shared Clonal Types'><div class='tabber'>" >> $outputFile
-	fi
-	
-	for sample in $samples; do
-		echo "${clonality_method}"
-		
-		echo "<div class='tabbertab' title='$sample'><table class='pure-table pure-table-striped'>" >> $outputFile
-		
-		if [[ "${clonality_method}" == "boyd" ]] ; then
-			clonalityScore="$(cat $outputDir/lymphclon_clonality_${sample}.txt)"
-            echo "<tr><td>Clonality Score: </td><td>$clonalityScore</td></tr>" >> $outputFile
-		fi
-		
-		#replicate,reads,squared
-        echo "<tr><td>Replicate ID</td><td>Number of Sequences</td></tr>" >> $outputFile
-        while read replicate reads squared
-        do
-            echo "<tr><td>$replicate</td><td>$reads</td></tr>" >> $outputFile
-        done < $outputDir/ReplicateReads_$sample.txt
-        
-        #sum of reads and reads squared
-        while read readsSum squaredSum
-            do
-                echo "<tr><td>Sum</td><td>$readsSum</td></tr>" >> $outputFile
-        done < $outputDir/ReplicateSumReads_$sample.txt
-        
-        echo "<tr><td></td><td></td></tr>" >> $outputFile
-        
-        #overview
-        echo "<tr><td>Number of replicates containing the coincidence</td><td>Number of sequences shared between replicates</td></tr>" >> $outputFile
-        while read type count weight weightedCount
-        do
-            if [[ "$type" -eq "1" ]]; then
-                echo "<tr><td>$type</td><td>$count</td></tr>" >> $outputFile
-            else
-                echo "<tr><td><a href='coincidences_${sample}_${type}.txt'>$type</a></td><td>$count</td></tr>" >> $outputFile
-            fi
-        done < $outputDir/ClonalityOverView_$sample.txt
-        echo "</table></div>" >> $outputFile
-	done
-	
-	cat $dir/naive_clonality.htm >> $outputFile
-	
-	echo "</div></div>" >> $outputFile
-fi
-
-#hasJunctionData="$(if head -n 1 $inputFile | grep -qE '3V.REGION.trimmed.nt.nb'; then echo 'Yes'; else echo 'No'; fi)"
-
-#if [[ "$hasJunctionData" == "Yes" ]] ; then
-if [ -a "$outputDir/junctionAnalysisProd_mean_wD.txt" ] ; then
-	echo "<div class='tabbertab' title='Junction Analysis'>" >> $outputFile
-	echo "<img src='IGH_junctie_analyse.png' />" >> $outputFile
-	
-	echo "<center><p style='font-size: 20;'>Unique rearrangements with a V, D and J gene assigned</p></center>" >> $outputFile
-	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Productive mean</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
-	while read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP median
-	do
-		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>$median</td></tr>" >> $outputFile
-	done < $outputDir/junctionAnalysisProd_mean_wD.txt
-	echo "</tbody></table>" >> $outputFile
-	
-	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Unproductive mean</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
-	while read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP median
-	do
-		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>-</td></tr>" >> $outputFile
-	done < $outputDir/junctionAnalysisUnProd_mean_wD.txt
-	echo "</tbody></table>" >> $outputFile
-	
-	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Productive median</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
-	while read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP median
-	do
-		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>$median</td></tr>" >> $outputFile
-	done < $outputDir/junctionAnalysisProd_median_wD.txt
-	echo "</tbody></table>" >> $outputFile
-	
-	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Unproductive median</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
-	while read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP median
-	do
-		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>-</td></tr>" >> $outputFile
-	done < $outputDir/junctionAnalysisUnProd_median_wD.txt
-	echo "</tbody></table>" >> $outputFile
-	
-	# again for no-d
-	echo "<center><p style='font-size: 20;'>Unique rearrangements with only a V and J gene assigned</p></center>" >> $outputFile
-	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Productive mean</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N</th><th>P2</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
-	while read Sample unique VDEL P1 N1 P2 DELJ TotalDel TotalN TotalP median
-	do
-		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>$median</td></tr>" >> $outputFile
-	done < $outputDir/junctionAnalysisProd_mean_nD.txt
-	echo "</tbody></table>" >> $outputFile
-	
-	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Unproductive mean</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N</th><th>P2</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
-	while read Sample unique VDEL P1 N1 P2 DELJ TotalDel TotalN TotalP median
-	do
-		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>-</td></tr>" >> $outputFile
-	done < $outputDir/junctionAnalysisUnProd_mean_nD.txt
-	echo "</tbody></table>" >> $outputFile
-	
-	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Productive median</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N</th><th>P2</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
-	while read Sample unique VDEL P1 N1 P2 DELJ TotalDel TotalN TotalP median
-	do
-		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>$median</td></tr>" >> $outputFile
-	done < $outputDir/junctionAnalysisProd_median_nD.txt
-	echo "</tbody></table>" >> $outputFile
-	
-	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Unproductive median</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N</th><th>P2</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
-	while read Sample unique VDEL P1 N1 P2 DELJ TotalDel TotalN TotalP median
-	do
-		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>-</td></tr>" >> $outputFile
-	done < $outputDir/junctionAnalysisUnProd_median_nD.txt
-	echo "</tbody></table>" >> $outputFile
-	
-	cat $dir/naive_junction.htm >> $outputFile
-	
-	echo "</div>" >> $outputFile
-fi
-
-echo "<div class='tabbertab' title='Downloads'>" >> $outputFile
-echo "<table class='pure-table pure-table-striped'>" >> $outputFile
-echo "<thead><tr><th>Description</th><th>Link</th></tr></thead>" >> $outputFile
-echo "<tr><td>The filtered dataset</td><td><a href='allUnique.txt'>Download</a></td></tr>" >> $outputFile
-echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>Gene frequencies</td></tr>" >> $outputFile
-
-echo "<tr><td>The dataset used to generate the distribution of V gene families graph</td><td><a href='VFFrequency.txt'>Download</a></td></tr>" >> $outputFile
-if [[ "$useD" == "true" ]] ; then
-	echo "<tr><td>The dataset used to generate  the distribution of D gene families graph</td><td><a href='DFFrequency.txt'>Download</a></td></tr>" >> $outputFile
-fi
-
-echo "<tr><td>The dataset used to generate the relative frequency of V gene usage graph</td><td><a href='VFrequency.txt'>Download</a></td></tr>" >> $outputFile
-if [[ "$useD" == "true" ]] ; then
-	echo "<tr><td>The dataset used to generate the relative frequency of D gene usage graph</td><td><a href='DFrequency.txt'>Download</a></td></tr>" >> $outputFile
-fi
-echo "<tr><td>The dataset used to generate the relative frequency of J gene usage graph</td><td><a href='JFrequency.txt'>Download</a></td></tr>" >> $outputFile
-echo "<tr><td>The dataset used to generate the relative frequency of the D reading frame graph</td><td><a href='DReadingFrame.txt'>Download</a></td></tr>" >> $outputFile
-
-echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>CDR3 Characteristics</td></tr>" >> $outputFile
-echo "<tr><td>The dataset used to generate the CDR3 length frequency graph</td><td><a href='CDR3LengthPlot.txt'>Download</a></td></tr>" >> $outputFile
-echo "<tr><td>The dataset used to generate the Amino Acid Composition in the CDR3 graph</td><td><a href='AAComposition.txt'>Download</a></td></tr>" >> $outputFile
-
-echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>Heatmaps</td></tr>" >> $outputFile
-for sample in $samples; do
-	if [[ "$useD" == "true" ]] ; then
-		echo "<tr><td>The data used to generate the VD heatmap for $sample.</td><td><a href='HeatmapVD_$sample.txt'>Download</a></td></tr>" >> $outputFile
-	fi
-	echo "<tr><td>The data used to generate the VJ heatmap for $sample.</td><td><a href='HeatmapVJ_$sample.txt'>Download</a></td></tr>" >> $outputFile
-	if [[ "$useD" == "true" ]] ; then
-		echo "<tr><td>The data used to generate the DJ heatmap for $sample.</td><td><a href='HeatmapDJ_$sample.txt'>Download</a></td></tr>" >> $outputFile
-	fi
-done
-
-echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>Circos</td></tr>" >> $outputFile
-for sample in $samples; do
-	if [[ "$useD" == "true" ]] ; then
-		echo "<tr><td>The data used to generate the VD Circos plots for $sample.</td><td><a href='${sample}_VD_circos.txt'>Download</a></td></tr>" >> $outputFile
-	fi
-	echo "<tr><td>The data used to generate the VJ Circos plots for $sample.</td><td><a href='${sample}_VJ_circos.txt'>Download</a></td></tr>" >> $outputFile
-	if [[ "$useD" == "true" ]] ; then
-		echo "<tr><td>The data used to generate the DJ Circos plots for $sample.</td><td><a href='${sample}_DJ_circos.txt'>Download</a></td></tr>" >> $outputFile
-	fi
-done
-
-#echo "<tr><td>A frequency count of V Gene + J Gene + CDR3</td><td><a href='VJCDR3_count.txt'>Download</a></td></tr>" >> $outputFile
-
-echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>Clonality</td></tr>" >> $outputFile
-echo "<tr><td>The dataset used to calculate clonality score (Unique based on clonaltype, $clonalType)</td><td><a href='clonalityComplete.txt'>Download</a></td></tr>" >> $outputFile
-# echo "<tr><td>Sequences that are present in more than one replicate</td><td><a href='clonaltypes_replicates.txt'>Download</a></td></tr>" >> $outputFile
-
-echo "</table>" >> $outputFile
-
-cat $dir/naive_downloads.htm >> $outputFile
-
-echo "</div></html>" >> $outputFile
+#!/bin/bash
+
+inputFile=$1
+outputDir=$3
+outputFile=$3/index.html #$2
+clonalType=$4
+species=$5
+locus=$6
+filterproductive=$7
+clonality_method=$8
+
+dir="$(cd "$(dirname "$0")" && pwd)"
+useD="false"
+if grep -q "$species.*${locus}D" "$dir/genes.txt" ; then
+	echo "species D region in reference db"
+	useD="true"
+fi
+echo "$species"
+if [[ "$species" == *"custom"* ]] ; then
+	loci=(${locus//;/ })
+	useD="true"
+	echo "${loci[@]}"
+	if [[ "${#loci[@]}" -eq "2" ]] ; then
+		useD="false"
+	fi
+fi
+mkdir $3
+cp $dir/genes.txt $outputDir
+Rscript --verbose $dir/RScript.r $inputFile $outputDir $outputDir $clonalType "$species" "$locus" $filterproductive ${clonality_method} 2>&1
+cp $dir/tabber.js $outputDir
+cp $dir/style.css $outputDir
+cp $dir/script.js $outputDir
+cp $dir/jquery-1.11.0.min.js $outputDir
+cp $dir/pure-min.css $outputDir
+cp $dir/IGH_junctie_analyse.png $outputDir
+samples=`cat $outputDir/samples.txt`
+
+echo "<html><center><h1><a href='index.html'>Click here for the results</a></h1>Tip: Open it in a new tab (middle mouse button or right mouse button -> 'open in new tab' on the link above)<br />" > $2
+echo "<table border = 1>" >> $2
+echo "<thead><tr><th>Donor/Replicate</th><th>All</th><th>Productive</th><th>Unique Productive</th><th>Unproductive</th><th>Unique Unproductive</th></tr></thead>" >> $2
+while IFS=, read sample all productive perc_prod productive_unique perc_prod_un unproductive perc_unprod unproductive_unique perc_unprod_un
+	do
+		echo "<tr><td>$sample</td>" >> $2
+		echo "<td>$all</td>" >> $2
+		if [[ "$productive" != "0" ]] ; then
+			echo "<td>$productive (${perc_prod}%)</td>" >> $2
+			echo "<td>$productive_unique (${perc_prod_un}%)</td>" >> $2
+			echo "<td>$unproductive (${perc_unprod}%)</td>" >> $2
+			echo "<td>$unproductive_unique (${perc_unprod_un}%)</td></tr>" >> $2
+		else
+			echo "<td colspan='4' style='background-color: red;'>No productive sequences!</td>" >> $2
+		fi
+done < $outputDir/productive_counting.txt
+echo "</table><br />" >> $2
+echo "Table showing the number and percentage of (unique) productive and unproductive sequences per donor and per replicate. <br />" >> $2
+echo "The definition of unique sequences is based on the clonal type definition filter setting chosen. " >> $2
+echo "</center></html>" >> $2
+
+echo "<html><head><title>Report on:" >> $outputFile
+
+mkdir $outputDir/circos
+cp -R $dir/circos/* $outputDir/circos/
+
+USECIRCOS="no"
+path_to_circos=$(which circos)
+if [ -x "$path_to_circos" ]; then
+	USECIRCOS="yes"
+fi
+
+echo "Using Circos: $USECIRCOS"
+sed -i "s%DATA_DIR%$outputDir/circos%" $outputDir/circos/circos.conf
+for sample in $samples; do #output the samples to a file and create the circos plots with the R script output
+	echo " $sample" >> $outputFile
+	
+	if [[ "$USECIRCOS" != "yes" ]]; then
+		continue
+	fi
+	
+	circos_file="$outputDir/${sample}_VJ_circos.txt"
+	sed -i -- 's%/%:%g' $circos_file
+	echo -e -n "labels$(cat ${circos_file})" > ${circos_file}
+	echo "Circos tools command:"
+	echo "cat \"${circos_file}\" | parse-table -configfile $dir/circos/parse-table.conf 2>&1 | make-conf -dir $outputDir/circos/"
+	cat "${circos_file}" | parse-table -configfile $dir/circos/parse-table.conf 2>&1 | make-conf -dir $outputDir/circos/
+
+	echo "Circos command:"
+	echo "circos -conf $outputDir/circos/circos.conf 2>&1"
+	circos -conf $outputDir/circos/circos.conf 2>&1
+	mv $outputDir/circos/circos.png $outputDir/circosVJ_${sample}.png
+	mv $outputDir/circos/circos.svg $outputDir/circosVJ_${sample}.svg
+	
+	
+	if [[ "$useD" == "true" ]] ; then
+		circos_file="$outputDir/${sample}_VD_circos.txt"
+		sed -i -- 's%/%:%g' $circos_file
+		echo -e -n "labels$(cat ${circos_file})" > ${circos_file}
+		cat "${circos_file}" | parse-table -configfile $dir/circos/parse-table.conf 2>&1 | make-conf -dir $outputDir/circos/
+		sed -i -- 's%/%:%g' $outputDir/circos/cells.txt
+		circos -conf $outputDir/circos/circos.conf 2>&1
+		mv $outputDir/circos/circos.png $outputDir/circosVD_${sample}.png
+		mv $outputDir/circos/circos.svg $outputDir/circosVD_${sample}.svg
+		
+		circos_file="$outputDir/${sample}_DJ_circos.txt"
+		sed -i -- 's%/%:%g' $circos_file
+		echo -e -n "labels$(cat ${circos_file})" > ${circos_file}
+		cat "${circos_file}" | parse-table -configfile $dir/circos/parse-table.conf 2>&1 | make-conf -dir $outputDir/circos/
+		sed -i -- 's%/%:%g' $outputDir/circos/cells.txt
+		circos -conf $outputDir/circos/circos.conf 2>&1
+		mv $outputDir/circos/circos.png $outputDir/circosDJ_${sample}.png
+		mv $outputDir/circos/circos.svg $outputDir/circosDJ_${sample}.svg
+	fi
+done
+echo "</title><script type='text/javascript' src='jquery-1.11.0.min.js'></script>" >> $outputFile
+echo "<link rel='stylesheet' type='text/css' href='pure-min.css'>" >> $outputFile
+echo "<script type='text/javascript' src='tabber.js'></script>" >> $outputFile
+echo "<script type='text/javascript' src='script.js'></script>" >> $outputFile
+echo "<link rel='stylesheet' type='text/css' href='style.css'></head>" >> $outputFile
+echo "<div class='tabber'><div class='tabbertab' title='Gene frequencies'>" >> $outputFile
+
+
+echo "<a href='VFPlot.pdf'><img src='VFPlot.png'/></a>" >> $outputFile
+if [[ "$useD" == "true" ]] ; then
+	echo "<a href='DFPlot.pdf'><img src='DFPlot.png'/></a>" >> $outputFile
+fi
+echo "<a href='VPlot.pdf'><img src='VPlot.png'/></a>" >> $outputFile
+if [[ "$useD" == "true" ]] ; then
+	echo "<a href='DPlot.pdf'><img src='DPlot.png'/></a>" >> $outputFile
+fi
+echo "<a href='JPlot.pdf'><img src='JPlot.png'/></a> <br />" >> $outputFile
+
+echo "<a href='DReadingFrame.pdf'><img src='DReadingFrame.png'/></a>" >> $outputFile
+
+cat $dir/naive_gene_freq.htm >> $outputFile
+
+echo "</div>" >> $outputFile
+
+echo "<div class='tabbertab' title='CDR3 Characteristics'>" >> $outputFile
+echo "<a href='CDR3LengthPlot.pdf'><img src='CDR3LengthPlot.png'/></a><br />" >> $outputFile
+echo "<a href='AAComposition.pdf'><img src='AAComposition.png'/></a>" >> $outputFile
+
+
+echo "<table class='pure-table pure-table-striped'>" >> $outputFile
+echo "<thead><tr><th>Donor</th><th>Median CDR3 Length</th></tr></thead>" >> $outputFile
+while read Sample median
+do
+	echo "<tr><td>$Sample</td><td>$median</td></tr>" >> $outputFile
+done < $outputDir/AAMedianBySample.txt
+echo "</table>" >> $outputFile
+
+cat $dir/naive_cdr3_char.htm >> $outputFile
+
+echo "</div>" >> $outputFile
+
+#Heatmaps
+
+count=1
+echo "<div class='tabbertab' title='Heatmaps'><div class='tabber'>" >> $outputFile
+for sample in $samples; do
+	echo "<div class='tabbertab' title='$sample'><table border='1'><tr>" >> $outputFile
+	if [[ "$useD" == "true" ]] ; then
+		echo "<td><a href='HeatmapVD_$sample.pdf'><img src='HeatmapVD_$sample.png'/></a></td>" >> $outputFile
+	fi
+	echo "<td><a href='HeatmapVJ_$sample.pdf'><img src='HeatmapVJ_$sample.png'/></a></td>" >> $outputFile
+	if [[ "$useD" == "true" ]] ; then
+		echo "<td><a href='HeatmapDJ_$sample.pdf'><img src='HeatmapDJ_$sample.png'/></a></td>" >> $outputFile
+	fi
+	echo "</tr></table></div>" >> $outputFile
+	count=$((count+1))
+done
+
+cat $dir/naive_heatmap.htm >> $outputFile
+
+echo "</div></div>" >> $outputFile
+
+echo "<div class='tabbertab' title='Compare Heatmaps'><table class='pure-table pure-table-striped'><thead><tr><th>ID</th><th>Include</th></tr></thead>" >> $outputFile
+for sample in $samples; do
+	echo "<tr><td>$sample</td><td><input type='checkbox' onchange=\"javascript:compareAdd('$sample')\" id='compare_checkbox_$sample'/></td></tr>" >> $outputFile
+done
+echo "</table><div name='comparisonarea'>" >> $outputFile
+echo "<table><tr id='comparison_table_vd'></tr></table>" >> $outputFile
+echo "<table><tr id='comparison_table_vj'></tr></table>" >> $outputFile
+echo "<table><tr id='comparison_table_dj'></tr></table>" >> $outputFile
+
+cat $dir/naive_compare.htm >> $outputFile
+
+echo "</div></div>" >> $outputFile
+
+
+#circos
+
+if [[ "$USECIRCOS" == "yes" ]]; then
+
+	echo "<div class='tabbertab' title='Circos'><div class='tabber'>" >> $outputFile
+	for sample in $samples; do
+		echo "<div class='tabbertab' title='$sample'><table border='1'><center>" >> $outputFile
+		if [[ "$useD" == "true" ]] ; then
+			echo "<tr><td>V-D</td><td><a href='circosVD_${sample}.svg'><img src='circosVD_${sample}.png' width='700' height='700'/></td></tr>" >> $outputFile
+		fi
+		echo "<tr><td>V-J</td><td><a href='circosVJ_${sample}.svg'><img src='circosVJ_${sample}.png' width='700' height='700'/></td></tr>" >> $outputFile
+		if [[ "$useD" == "true" ]] ; then
+			echo "<tr><td>D-J</td><td><a href='circosDJ_${sample}.svg'><img src='circosDJ_${sample}.png' width='700' height='700'/></td></tr>" >> $outputFile
+		fi
+		echo "<center></table></div>" >> $outputFile
+		count=$((count+1))
+	done
+	
+	cat $dir/naive_circos.htm >> $outputFile
+	
+	echo "</div></div>" >> $outputFile
+fi
+#echo "<div class='tabbertab' title='Interactive'><svg class='chart'></svg><script src='http://d3js.org/d3.v3.min.js'></script></div>" >> $outputFile
+
+hasReplicateColumn="$(if head -n 1 $inputFile | grep -q 'Replicate'; then echo 'Yes'; else echo 'No'; fi)"
+echo "$hasReplicateColumn"
+#if its a 'new' merged file with replicate info
+if [[ "$hasReplicateColumn" == "Yes" && "${clonality_method}" != "none" ]] ; then
+	if [[ "${clonality_method}" == "boyd" ]] ; then
+		echo "<div class='tabbertab' title='Clonality'><div class='tabber'>" >> $outputFile
+	else
+		echo "<div class='tabbertab' title='Shared Clonal Types'><div class='tabber'>" >> $outputFile
+	fi
+	
+	for sample in $samples; do
+		echo "${clonality_method}"
+		
+		echo "<div class='tabbertab' title='$sample'><table class='pure-table pure-table-striped'>" >> $outputFile
+		
+		if [[ "${clonality_method}" == "boyd" ]] ; then
+			clonalityScore="$(cat $outputDir/lymphclon_clonality_${sample}.txt)"
+            echo "<tr><td>Clonality Score: </td><td>$clonalityScore</td></tr>" >> $outputFile
+		fi
+		
+		#replicate,reads,squared
+        echo "<tr><td>Replicate ID</td><td>Number of Sequences</td></tr>" >> $outputFile
+        while read replicate reads squared
+        do
+            echo "<tr><td>$replicate</td><td>$reads</td></tr>" >> $outputFile
+        done < $outputDir/ReplicateReads_$sample.txt
+        
+        #sum of reads and reads squared
+        while read readsSum squaredSum
+            do
+                echo "<tr><td>Sum</td><td>$readsSum</td></tr>" >> $outputFile
+        done < $outputDir/ReplicateSumReads_$sample.txt
+        
+        echo "<tr><td></td><td></td></tr>" >> $outputFile
+        
+        #overview
+        echo "<tr><td>Number of replicates containing the coincidence</td><td>Number of sequences shared between replicates</td></tr>" >> $outputFile
+        while read type count weight weightedCount
+        do
+            if [[ "$type" -eq "1" ]]; then
+                echo "<tr><td>$type</td><td>$count</td></tr>" >> $outputFile
+            else
+                echo "<tr><td><a href='coincidences_${sample}_${type}.txt'>$type</a></td><td>$count</td></tr>" >> $outputFile
+            fi
+        done < $outputDir/ClonalityOverView_$sample.txt
+        echo "</table></div>" >> $outputFile
+	done
+	
+	cat $dir/naive_clonality.htm >> $outputFile
+	
+	echo "</div></div>" >> $outputFile
+fi
+
+#hasJunctionData="$(if head -n 1 $inputFile | grep -qE '3V.REGION.trimmed.nt.nb'; then echo 'Yes'; else echo 'No'; fi)"
+
+#if [[ "$hasJunctionData" == "Yes" ]] ; then
+if [ -a "$outputDir/junctionAnalysisProd_mean_wD.txt" ] ; then
+	echo "<div class='tabbertab' title='Junction Analysis'>" >> $outputFile
+	echo "<img src='IGH_junctie_analyse.png' />" >> $outputFile
+	
+	echo "<center><p style='font-size: 20;'>Unique rearrangements with a V, D and J gene assigned</p></center>" >> $outputFile
+	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Productive mean</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
+	while read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP median
+	do
+		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>$median</td></tr>" >> $outputFile
+	done < $outputDir/junctionAnalysisProd_mean_wD.txt
+	echo "</tbody></table>" >> $outputFile
+	
+	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Unproductive mean</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
+	while read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP median
+	do
+		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>-</td></tr>" >> $outputFile
+	done < $outputDir/junctionAnalysisUnProd_mean_wD.txt
+	echo "</tbody></table>" >> $outputFile
+	
+	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Productive median</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
+	while read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP median
+	do
+		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>$median</td></tr>" >> $outputFile
+	done < $outputDir/junctionAnalysisProd_median_wD.txt
+	echo "</tbody></table>" >> $outputFile
+	
+	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Unproductive median</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
+	while read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP median
+	do
+		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>-</td></tr>" >> $outputFile
+	done < $outputDir/junctionAnalysisUnProd_median_wD.txt
+	echo "</tbody></table>" >> $outputFile
+	
+	# again for no-d
+	echo "<center><p style='font-size: 20;'>Unique rearrangements with only a V and J gene assigned</p></center>" >> $outputFile
+	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Productive mean</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N</th><th>P2</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
+	while read Sample unique VDEL P1 N1 P2 DELJ TotalDel TotalN TotalP median
+	do
+		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>$median</td></tr>" >> $outputFile
+	done < $outputDir/junctionAnalysisProd_mean_nD.txt
+	echo "</tbody></table>" >> $outputFile
+	
+	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Unproductive mean</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N</th><th>P2</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
+	while read Sample unique VDEL P1 N1 P2 DELJ TotalDel TotalN TotalP median
+	do
+		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>-</td></tr>" >> $outputFile
+	done < $outputDir/junctionAnalysisUnProd_mean_nD.txt
+	echo "</tbody></table>" >> $outputFile
+	
+	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Productive median</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N</th><th>P2</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
+	while read Sample unique VDEL P1 N1 P2 DELJ TotalDel TotalN TotalP median
+	do
+		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>$median</td></tr>" >> $outputFile
+	done < $outputDir/junctionAnalysisProd_median_nD.txt
+	echo "</tbody></table>" >> $outputFile
+	
+	echo "<table class='pure-table pure-table-striped' id='junction_table'> <caption>Unproductive median</caption><thead><tr><th>Donor</th><th>Number of sequences</th><th>V.DEL</th><th>P1</th><th>N</th><th>P2</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><th>CDR3.Length</th><thead></tr><tbody>" >> $outputFile
+	while read Sample unique VDEL P1 N1 P2 DELJ TotalDel TotalN TotalP median
+	do
+		echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td><td>-</td></tr>" >> $outputFile
+	done < $outputDir/junctionAnalysisUnProd_median_nD.txt
+	echo "</tbody></table>" >> $outputFile
+	
+	cat $dir/naive_junction.htm >> $outputFile
+	
+	echo "</div>" >> $outputFile
+fi
+
+echo "<div class='tabbertab' title='Downloads'>" >> $outputFile
+echo "<table class='pure-table pure-table-striped'>" >> $outputFile
+echo "<thead><tr><th>Description</th><th>Link</th></tr></thead>" >> $outputFile
+echo "<tr><td>The filtered dataset</td><td><a href='allUnique.txt'>Download</a></td></tr>" >> $outputFile
+echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>Gene frequencies</td></tr>" >> $outputFile
+
+echo "<tr><td>The dataset used to generate the distribution of V gene families graph</td><td><a href='VFFrequency.txt'>Download</a></td></tr>" >> $outputFile
+if [[ "$useD" == "true" ]] ; then
+	echo "<tr><td>The dataset used to generate  the distribution of D gene families graph</td><td><a href='DFFrequency.txt'>Download</a></td></tr>" >> $outputFile
+fi
+
+echo "<tr><td>The dataset used to generate the relative frequency of V gene usage graph</td><td><a href='VFrequency.txt'>Download</a></td></tr>" >> $outputFile
+if [[ "$useD" == "true" ]] ; then
+	echo "<tr><td>The dataset used to generate the relative frequency of D gene usage graph</td><td><a href='DFrequency.txt'>Download</a></td></tr>" >> $outputFile
+fi
+echo "<tr><td>The dataset used to generate the relative frequency of J gene usage graph</td><td><a href='JFrequency.txt'>Download</a></td></tr>" >> $outputFile
+echo "<tr><td>The dataset used to generate the relative frequency of the D reading frame graph</td><td><a href='DReadingFrame.txt'>Download</a></td></tr>" >> $outputFile
+
+echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>CDR3 Characteristics</td></tr>" >> $outputFile
+echo "<tr><td>The dataset used to generate the CDR3 length frequency graph</td><td><a href='CDR3LengthPlot.txt'>Download</a></td></tr>" >> $outputFile
+echo "<tr><td>The dataset used to generate the Amino Acid Composition in the CDR3 graph</td><td><a href='AAComposition.txt'>Download</a></td></tr>" >> $outputFile
+
+echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>Heatmaps</td></tr>" >> $outputFile
+for sample in $samples; do
+	if [[ "$useD" == "true" ]] ; then
+		echo "<tr><td>The data used to generate the VD heatmap for $sample.</td><td><a href='HeatmapVD_$sample.txt'>Download</a></td></tr>" >> $outputFile
+	fi
+	echo "<tr><td>The data used to generate the VJ heatmap for $sample.</td><td><a href='HeatmapVJ_$sample.txt'>Download</a></td></tr>" >> $outputFile
+	if [[ "$useD" == "true" ]] ; then
+		echo "<tr><td>The data used to generate the DJ heatmap for $sample.</td><td><a href='HeatmapDJ_$sample.txt'>Download</a></td></tr>" >> $outputFile
+	fi
+done
+
+echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>Circos</td></tr>" >> $outputFile
+for sample in $samples; do
+	if [[ "$useD" == "true" ]] ; then
+		echo "<tr><td>The data used to generate the VD Circos plots for $sample.</td><td><a href='${sample}_VD_circos.txt'>Download</a></td></tr>" >> $outputFile
+	fi
+	echo "<tr><td>The data used to generate the VJ Circos plots for $sample.</td><td><a href='${sample}_VJ_circos.txt'>Download</a></td></tr>" >> $outputFile
+	if [[ "$useD" == "true" ]] ; then
+		echo "<tr><td>The data used to generate the DJ Circos plots for $sample.</td><td><a href='${sample}_DJ_circos.txt'>Download</a></td></tr>" >> $outputFile
+	fi
+done
+
+#echo "<tr><td>A frequency count of V Gene + J Gene + CDR3</td><td><a href='VJCDR3_count.txt'>Download</a></td></tr>" >> $outputFile
+
+echo "<tr><td colspan='2' style='background-color:#E0E0E0;'>Clonality</td></tr>" >> $outputFile
+echo "<tr><td>The dataset used to calculate clonality score (Unique based on clonaltype, $clonalType)</td><td><a href='clonalityComplete.txt'>Download</a></td></tr>" >> $outputFile
+# echo "<tr><td>Sequences that are present in more than one replicate</td><td><a href='clonaltypes_replicates.txt'>Download</a></td></tr>" >> $outputFile
+
+echo "</table>" >> $outputFile
+
+cat $dir/naive_downloads.htm >> $outputFile
+
+echo "</div></html>" >> $outputFile