Skip to content

Instantly share code, notes, and snippets.

@simon-anders
Created July 17, 2020 13:28
Show Gist options
  • Save simon-anders/b09bd19cda3900318e21b04f90bd0512 to your computer and use it in GitHub Desktop.
Save simon-anders/b09bd19cda3900318e21b04f90bd0512 to your computer and use it in GitHub Desktop.
seegene_curves.R
library( tidyverse )
readRDS("~/sds/sd17l002/p/covidTests/data/allCurvesSeegene.rds") %>% ungroup() -> tbl
readRDS("~/sds/sd17l002/p/covidTests/data/testResults.rds" ) -> testres
tbl %>% pull( plateId ) %>% unique()
c( "FAM" = "E", "HEX" = "IC", "Cal Red 610" = "R", "Quasar 670" = "N" ) ->flph2gene
tbl %>%
left_join( testres %>% select( Sample=labId, reportedRes ) %>% distinct ) %>%
mutate_at( "reportedRes", replace_na, "NA" ) %>%
mutate( sampleType = ifelse( str_starts( Sample, fixed("V20") ),
str_c( "sample/", reportedRes ),
Sample ) ) %>%
mutate( sampleType = ifelse( sampleType %in% as.character( 1:42 ), "numbered", sampleType ) ) %>%
mutate_at( "sampleType", factor ) %>%
mutate_at( "sampleType", fct_relevel, "NC", "PC", "sample/negative", "sample/positive",
"sample/inconclusive", "sample/NA", "numbered" ) -> tbl2
pdf( width=12, height=7 )
tbl2 %>% pull(plateId) %>% unique() %>% walk( function(plt) {
(tbl2 %>%
filter( plateId == plt ) %>%
mutate( facet = sprintf( "%s (%s)", gene, flph ) ) %>%
arrange( sampleType != "sample/negative" ) %>%
mutate_at( "Well", fct_inorder ) %>%
ggplot +
geom_line( aes( x=Cycle, y=value, group=Well, col=sampleType ), alpha=.6 ) +
facet_wrap( ~ facet, scales = "free_y" ) +
ggtitle( plt ) +
scale_color_manual( drop=FALSE, values = c( "darkblue", "red", "lightblue", "orange",
"brown", "gray", "darkgray" ) ) ) %>% print
} )
dev.off()
@kloivenn
Copy link

kloivenn commented Jul 17, 2020

With thick lines for samples that are positive according to TibMolBio E-gene, but negative for Seegene's E-gene

https://drive.google.com/file/d/1K5s7J_tUI1imGSX1MkFFv2xraZwysQLH/view?usp=sharing
(pdf)

library( tidyverse )

readRDS("data/allCurvesSeegene.rds") %>% ungroup() -> tbl
readRDS("data/testResults.rds" ) -> testres

tbl %>% pull( plateId ) %>% unique()

c( "FAM" = "E", "HEX" = "IC", "Cal Red 610" = "R", "Quasar 670" = "N" ) ->flph2gene

testres %>%
  filter(gene == "E", manufactor %in% c("SeeGene", "TibMolBio")) %>%
  group_by(labId) %>%
  filter(length(labId) > 1) %>%
  select(labId, manufactor, result) %>%
  pivot_wider(names_from = manufactor, values_from = result)  %>%
  filter(is.finite(TibMolBio), is.infinite(SeeGene)) -> sgNegs

tbl %>%
  left_join( testres %>% select( Sample=labId, reportedRes ) %>% distinct ) %>%
  mutate_at( "reportedRes", replace_na, "NA" ) %>%
  mutate( sampleType = ifelse( str_starts( Sample, fixed("V20") ), 
                               str_c( "sample/", reportedRes ), 
                               Sample ) ) %>%
  mutate(tibmolPos = Sample %in% sgNegs$labId) %>%
  mutate( sampleType = ifelse( sampleType %in% as.character( 1:42 ), "numbered", sampleType ) ) %>%
  mutate_at( "sampleType", factor ) %>%
  mutate_at( "sampleType", fct_relevel, "NC", "PC", "sample/negative", "sample/positive", 
             "sample/inconclusive", "sample/NA", "numbered" ) -> tbl2


pdf( width=12, height=7 )
tbl2 %>% pull(plateId) %>% unique()  %>% walk( function(plt) {
  (tbl2 %>%
     filter( plateId == plt ) %>%
     mutate( facet = sprintf( "%s (%s)", gene, flph ) ) %>%
     arrange( sampleType != "sample/negative" ) %>%
     mutate_at( "Well", fct_inorder ) %>%
     ggplot +
     geom_line( aes( x=Cycle, y=value, group=Well, col=sampleType, size = tibmolPos ), alpha=.6 ) +
     facet_wrap( ~ facet, scales = "free_y" ) +
     ggtitle( plt ) + 
     scale_color_manual( drop=FALSE, values = c( "darkblue", "red", "lightblue", "orange", 
                                                 "brown", "gray", "darkgray" ) ) + 
     scale_size_manual(values = c(0.5, 1.5), breaks = c(F, T))) %>% print
} )
dev.off()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment