meta_path <- "/sc/arion/projects/bigbrain/data/BipSeq/Metadata/BipSeq_donor_to_sample_metadata.tsv"
mbv_path <- "/sc/arion/projects/bigbrain/data/MSBB/MBV_Pipeline/output_MSBB/MSBB_mbv_summary.txt"
mbv_output <- read.table(mbv_path)
meta <- read_tsv(meta_path)
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   individualID = col_character(),
##   fileName = col_character(),
##   specimenID = col_character()
## )
# clean MBV data a bit
mbv <- select(mbv_output, sample_id=V1, participant_id=V2, het=V10, hom=V11)
mbv$sample_id <- gsub('.bamstat.txt', '', basename(mbv$sample_id))

mbv.summary <- as.data.frame(
  mbv %>% group_by(het < .75) %>% tally()
)
chartTable <- cbind(c('Match', 'Non-Match'), mbv.summary[,2])

# plot initial het vs hom
ggplot(mbv, aes(x=het, y=hom)) + 
  geom_point(aes(color = ifelse(het>.8, 'non-matches', 'matches'))) +
  labs(color = "Key") +
  coord_cartesian(clip='off') +
  theme(
    plot.margin = margin(0,40,0,0)
  ) +
  annotation_custom(
    grob=tableGrob(chartTable, theme=ttheme_default(base_size = 9)),
    xmin=.8,
  )