---
title: OGRDBstats Report
---

```{r, echo=FALSE, out.width="50%"}
  arrange_cols = function(grobs, cols) {
	  for (i in 1:length(grobs)/cols) {
		j = 1 + (i-1) * cols
		l = grobs[j:j+cols-1]
		l = l[!is.na(l)]
		
		if (length(l) > 0) {
			gridExtra::grid.arrange(grobs=l,ncol=cols)
		}
	  }		
  }
  
```

\newpage

`r if('SEQUENCE_IMGT' %in% names(input_sequences)){"# Novel sequence analysis"}`

`r if('SEQUENCE_IMGT' %in% names(input_sequences) && length(end_composition_grobs) > 0) {"## End-nucleotide composition"}`

```{r, echo=FALSE, fig.width=8, out.width="50%"}
    if('SEQUENCE_IMGT' %in% names(input_sequences) && length(end_composition_grobs) > 0) {
		for (i in 1:length(end_composition_grobs)) {
			gridExtra::grid.arrange(grobs=end_composition_grobs[i],ncol=1)
		}
    }

```

`r if('SEQUENCE_IMGT' %in% names(input_sequences) && length(cons_composition_grobs) > 0) {"## Per-nucleotide consensus where previous nucleotides match the consensus"}`

```{r, echo=FALSE, fig.width=8, out.width="50%"}
    if('SEQUENCE_IMGT' %in% names(input_sequences) && length(cons_composition_grobs) > 0) {
		for (i in 1:length(cons_composition_grobs)) {
			gridExtra::grid.arrange(grobs=cons_composition_grobs[i],ncol=1)
		}
    }

```

`r if('SEQUENCE_IMGT' %in% names(input_sequences) && length(whole_composition_grobs) > 0) {"## Whole-sequence composition of each assigned read"}`

```{r, echo=FALSE, fig.width=8, out.width="50%"}
    if('SEQUENCE_IMGT' %in% names(input_sequences) && length(whole_composition_grobs) > 0) {
      arrange_cols(whole_composition_grobs, 1)
    }

```


`r if('SEQUENCE_IMGT' %in% names(input_sequences) && length(triplet_composition_grobs) > 0) {"## Final three nucleotides: frequency of each observed triplet"}`

```{r, echo=FALSE, fig.width=6, fig.height=3, out.width="30%"}
    if('SEQUENCE_IMGT' %in% names(input_sequences) && length(triplet_composition_grobs) > 0) {
		for (i in 1:length(triplet_composition_grobs)) {
			gridExtra::grid.arrange(grobs=triplet_composition_grobs[i],ncol=1)
		}
    }

```

## CDR3 length distribution, in assignments to novel alleles


```{r, echo=FALSE, fig.width=4, fig.height=4, out.width="30%"}
  
	if (length(cdr3_dist_grobs) > 0) {
	  for (i in 1:length(cdr3_dist_grobs)) {
		  gridExtra::grid.arrange(grobs=cdr3_dist_grobs[i],ncol=1)
	  }
	}

```


\newpage
# Variation from germline, in assignments to each allele


```{r, echo=FALSE, fig.width=4, fig.height=4, out.width="30%"}
  
	if (length(barplot_grobs) > 0) {
	  for (i in 1:length(barplot_grobs)) {
		  gridExtra::grid.arrange(grobs=barplot_grobs[i],ncol=1)
	  }
	}

```


\newpage
# Allele usage in potential haplotype anchor genes

```{r, echo=FALSE, fig.width=8, out.width="80%"}
  
  gridExtra::grid.arrange(a_allele_plot, ncol=1)

```

\newpage
# Haplotype plots

```{r, echo=FALSE, fig.width=5, out.width="50%"}
  
	if (length(haplo_grobs) > 0) {
	  for (i in 1:length(haplo_grobs)) {
		  gridExtra::grid.arrange(grobs=haplo_grobs[i],ncol=1)
	  }
	}

```


\newpage
# Configuration settings

```{r, echo=FALSE, out.width="50%"}
  
	m = gsub("\\\\", "/", message)
  cat(gsub("([*+-])", " ", m))

```

