Skip to content

Commit

Permalink
Create sweaveTB-WGS-Micro-Report.Rnw
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Sarovich committed Sep 26, 2019
1 parent 24499d9 commit 272eeb0
Showing 1 changed file with 338 additions and 0 deletions.
338 changes: 338 additions & 0 deletions Databases/Pseudomonas_aeruginosa_pao1/sweaveTB-WGS-Micro-Report.Rnw
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@
%%----------------------------------------------
% DETAILS FOR TB WGS CLINICAL REPORT TEMPLATE
%%---------------------------------------------
% Version : Sweave 1.0
% Latex template is also available on Overleaf: TBR
%
% Report template is not provided for diagnostic purposes.
% Report template's design decision outline in the following publication: TBR
% Maintained by: Anamaria Crisan ([email protected])


\documentclass{article}
%%------------------------------------------
% THIRD PARTY PACKAGES
%%------------------------------------------
% Note: make sure these packages are install on your machine before using
\usepackage[letterpaper, margin=0.75in,headheight=77pt,top=3.5cm]{geometry}
\usepackage{Sweave} %this needs to go before "fontspec" in order to get Lato font to work
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[table]{xcolor}
\usepackage{tabu}
\usepackage{collcell}
\usepackage{multirow}
\usepackage[skins]{tcolorbox}
\usepackage{fontspec}
% \setmainfont{Lato}

%--------- NEW COMMANDS
\newcolumntype{U}{>{\collectcell\MakeUppercase}l<{\endcollectcell}}

\tcbuselibrary{listings,breakable}

%bounding box for report sections
\newtcolorbox{reportSection}[2][]{%
attach boxed title to top left
= {xshift=10pt, yshift=-8pt},
colback = white!5!white,
colframe = white!75!black,
fonttitle = \bfseries,
colbacktitle = white,
title = \textbf{\large{#2}},
coltitle = black,
arc = 0mm,
opacityframe = 0.5,
boxrule=1pt,
boxed title style={%
sharp corners,
rounded corners=northwest,
colback=white,
boxrule=0pt,
titlerule=0mm},
enhanced,
}



%--------------------------------------------
% Creating Header & Footer with Text, Logo and Page Number
%-------------------------------------------

%-------------- HEADER CONTENT ------------
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}

% HEADER TEXT
\lhead{\Large{\textbf{PSEUDOMONAS AERUGINOSA\\ GENOME SEQUENCING REPORT}} \\ \normalsize{NOT FOR DIAGNOSTIC USE}}
\chead{}
\rhead{\includegraphics[scale=0.25]{ARDaP_logo}}

%-------------- FOOTER CONTENT ------------
\lfoot{Page \thepage\ of 2}
\rfoot{Patient ID: \Sexpr{pInfo$ID} | DATE: \Sexpr{pInfo$reportDate} | LOCATION: \Sexpr{pInfo$reportLab} }

%%------------------------------------------
% DOCUMENT CONTENT
%%------------------------------------------

\begin{document}
\SweaveOpts{concordance=TRUE}
%\SweaveOpts{concordance=TRUE}

\tabulinesep=5pt
\noindent
\taburulecolor{lightgray}
\noindent \begin{tabu} to \textwidth {|XU||XU|}
\hline

% Making the table manually
% you may wonder: where does magical pInfo variable come from, the answer is "runReportExample.R", the variable
% get's automatically passed to the text document by the Sweave commands in the "makeReport" function.

<<patientInfoTab, results=tex, echo=FALSE>>=
cat("Patient Name &",paste(pInfo$FName,pInfo$LName,sep=" "), "& Barcode &",pInfo$Barcode,"\\\\ \\hline ")
cat("Birth Date &", pInfo$DOB, "& Patient ID &",pInfo$ID,"\\\\ \\hline ")
cat("Location &", pInfo$Location, "& Sample Type &",pInfo$sampType,"\\\\ \\hline ")
cat("Sample Source &",pInfo$sampSource,"& Sample Date &", pInfo$sampDate, "\\\\ \\hline ")
cat("Sample ID &",pInfo$sampID,"& SequencedFrom &", pInfo$sampSeq, "\\\\ \\hline ")
cat("Reporting Lab &", pInfo$reportLab,"& Report Date/Time &", pInfo$reportDate,"\\\\ \\hline ")
cat("Requested By &", pInfo$requestor,"& Requester Contact &", "[email protected]","\\\\ \\hline ")
@

\end{tabu}
\vspace{5mm}

%---------------------------------------------------------
% SECTION 1 : SUMMARY OF REPORT CONTENT
%---------------------------------------------------------

\begin{reportSection}{Summary}

\vspace{1mm}

% This is a custom paragraph that needs to be automatically generated.
<<sec1:summaryTextGen,echo=FALSE,results=tex>>=
#Function that produces the summary paragraph automatically
#Specimen Summary
posStatus<-sprintf("The specimen was positive for \\textbf{%s}.",pInfo$organism)
#Drug Resistance Summary
tmp<-drugDat %>% filter(Status == "Resistant")
if(nrow(tmp) == 0){
rDrugStat<-"It is predicted to be \\textbf{susceptible to all drugs}. "
}else{
nItem<-nrow(tmp)
syntaxNice<-NULL
if(nItem==1){
syntaxNice<-tmp$Drug
}else if(nItem == 2){
syntaxNice<-paste(tmp$Drug,collapse=" and ")
}else{
syntaxNice<-paste(paste(tmp$Drug[1:(nrow(tmp)-1)],collapse=", "),tmp$Drug[nrow(tmp)],sep=", and ")
}
rDrugStat<-sprintf("It is predicted to be \\textbf{resistant to %s}. ",syntaxNice)
}
#Cluster status - I haven't implemented rules for this, so it's just going ot be hard coded
clustStat<-"It belongs to a cluster, suggesting \\textbf{recent transmission}"
#Summary sentence
cat(paste(posStatus,rDrugStat))
@

\end{reportSection}
\vspace{5mm}

%---------------------------------------------------------
% SECTION 2 : SUMMARY OF SPECIATION RESULTS
%---------------------------------------------------------

%\begin{reportSection}{Organism}
%\vspace{1mm}

%The specimen was positive for \textit{\textbf{\Sexpr{pInfo$organism}}}, lineage \Sexpr{pInfo$lineageNum} (\textbf{\Sexpr{pInfo$lineageName}})
%}

%\end{reportSection}
%\vspace{5mm}

%---------------------------------------------------------
% SECTION 3 : SUMMARY OF SDRUG SUSCEPTIBILITY RESULTS
%---------------------------------------------------------

%------ Some R functions that will fill in the drug susceptibility information
<<sec2:drugFunction,echo=FALSE,results=tex>>=
#NOTE: there is probably a better way to do this.....
#this is a function that provides that latex commands for the resistant and sensitive drugs status. Drugs that are resistant are highlighed in grey (cell colour) and sensitive drugs are always listed first. This function will be use to populat the drug susceptibility table below
susceptData<-function(drugDat=NULL,class=NULL){
fLineS<-filter(drugDat,Class==class) %>% filter(Status=="Sensitive")
fLineR<-filter(drugDat,Class==class) %>% filter(Status=="Resistant")
#sensitive drugs first
if(nrow(fLineS) > 0){
for(i in 1:nrow(fLineS)){
#special line
if(i == nrow(fLineS)){
if(nrow(fLineR)==0){
cat(sprintf("\\multirow{-%d}{*}{%s}",i,class),sprintf("& \\multirow{-%d}{*}{Susceptible} &",i), fLineS[i,]$Drug, "&", fLineS[i,]$Details, "\\\\")
}else{
cat(sprintf(" & \\multirow{-%d}{*}{Susceptible} &",i), fLineS[i,]$Drug, "&", fLineS[i,]$Details, "\\\\")
}
}else{
cat(" & &", fLineS[i,]$Drug, "&", fLineS[i,]$Details, "\\\\")
}
}
}
#followed by resistant drugs
if(nrow(fLineR) > 0){
for(i in 1:nrow(fLineR)){
#special line
if(i == nrow(fLineR)){
cat(sprintf("\\multirow{-%d}{*}{%s}",nrow(fLineS)+nrow(fLineR),class),sprintf("& \\cellcolor[HTML]{EFEFEF} \\multirow{-%d}{*}{Resistant} &",i),"\\cellcolor[HTML]{EFEFEF}",fLineR[i,]$Drug, "&", "\\cellcolor[HTML]{EFEFEF}",fLineR[i,]$Details, "\\\\")
}else{
cat(" & \\cellcolor[HTML]{EFEFEF} &","\\cellcolor[HTML]{EFEFEF}",fLineR[i,]$Drug, "&","\\cellcolor[HTML]{EFEFEF}",fLineR[i,]$Details, "\\\\")
}
}
}
}
#this function will summarize the suscepibility status in the tick boxes
drugSusceptTickBox<-function(drugDat=NULL){
tickStatus<-data.frame(threshold = c(0,1,2,"2+"),
status = c("No drug resistance predicted",
"Mono-resistance predicted",
"Multi-drug resistance predicted",
"Extensive drug resistance predicted"
),
stringsAsFactors = FALSE
)
nResist <- drugDat %>% filter(Status=="Resistant") %>% count()
nResist <-nResist$n
if(nResist>2)
nResist = "2+"
for(i in 1:nrow(tickStatus)){
status<-NULL
if(tickStatus[i,]$threshold == nResist){
status<-paste("& \\cellcolor[HTML]{EFEFEF} $\\text{\\rlap{$\\checkmark$}}\\square$",tickStatus[i,]$status,"\\\\")
}else{
status<-paste("&$\\square$",tickStatus[i,]$status,"\\\\")
}
cat(status)
}
}
@

\begin{reportSection}{Drug Susceptibility}
%--------- Text for drug susceptibility and also the summary tick boxes
\vspace{1mm}

\tabulinesep=2pt
\noindent
\taburulecolor{lightgray}
\noindent \begin{tabu} to \textwidth {X[1.1,l]X}
%------ Summary of drug susceptibility - tick boxes
\multirow{4}{*}{\parbox{7.5cm}{\footnotesize{Resistance is reported when a high-confidence resistance-conferring mutation is detected. \textbf{``No mutation detected'' does not exclude the possibility of resistance}}}}
<<sec2:susceptibililtyTickBox,echo=FALSE,results=tex>>=
drugSusceptTickBox(drugDat)
@
\end{tabu}
\vspace{3mm} %% Add a Bit of space between the entities

%--------- Summary of drug susceptibility - table
\tabulinesep=5pt
\noindent
\taburulecolor{lightgray}
\noindent \begin{tabu} to \textwidth {X[0.5,l]X[0.5,l]X[1.3,l]X[1.7,l]}
\hline
Drug class & Interpretation & Drug & Resistance Gene \scriptsize{(Amino Acid Mutation)} \\
\cline{1-4}
<<sec2:susceptibilityTestFirstLine,echo=FALSE,results=tex>>=
susceptData(drugDat,class="First-line")
@
\cline{1-4}
<<sec2:susceptibilityTestSecondLine,echo=FALSE,results=tex>>=
susceptData(drugDat,class="Second-line")
@
\end{tabu}
\end{reportSection}


%---------------------------------------------------------
% SECTION 4 : CLUSTER DETECTION RESULTS
%---------------------------------------------------------
% Not currently implemented

\pagebreak

%---------------------------------------------------------
% SECTION 5 : ADDITIONAL COMMENTS
%---------------------------------------------------------
\begin{reportSection}{Assay Details}
\vspace{1mm}
\tabulinesep=5pt
\noindent
\taburulecolor{lightgray}
\noindent \begin{tabu} to \textwidth {|XU||XU|}
\hline
% The table below contains the information that is required by ISO15189 reporting standards
%-------------------- v ADD YOUR TABLE CONTENTS BELOW v --------------------------
Sample ID & A12345678 & Barcode & \\ \hline
Sequencer & Illumina HiSeq 2500 & Method & WGS \\ \hline
Pipeline & ARDaP v1.4 & Reference & K96243 \\ \hline
%-------------------- ^ ADD YOUR TABLE CONTENTS ABOVE ^ --------------------------
\end{tabu}
\vspace{1mm}

\end{reportSection}
\vspace{1mm}

%---------------------------------------------------------
% SECTION 6 : ADDITIONAL COMMENTS
%---------------------------------------------------------
%Comments are for anything funny that was found by the
\begin{reportSection}{Comments}
% This is where any additional comments might go
\vspace{1mm}

\footnotesize{\Sexpr{pInfo$comments}}
\vspace{2mm}

\textcolor{gray}{\footnotesize{\textit{\textbf{Standard Disclaimer:} Low frequency hetero-resistance below the limit of detection by sequencing may affect typing results. The interpretation provided is based on the current understanding of genotype-phenotype relationships.}}}

\end{reportSection}
\vspace{1mm}

%---------------------------------------------------------
% SECTION 7 : AUTHORIZATION
%---------------------------------------------------------
\begin{reportSection}{Authorised}
% This section is required by ISO15189 standards
\vspace{1mm}
\tabulinesep=5pt
\noindent
\taburulecolor{lightgray}
\noindent \begin{tabu} to \textwidth {|XU||XU|}
\hline
%--------------- v ADD YOUR TABLE CONTENTS BELOW v ---------------------
Signature & & Name & \\ \hline
Position & & Date & \\ \hline
%--------------- ^ ADD YOUR TABLE CONTENTS ABOVE ^ ---------------------
\end{tabu}

\end{reportSection}


\end{document}

0 comments on commit 272eeb0

Please sign in to comment.