Skip to content

Instantly share code, notes, and snippets.

View soh-i's full-sized avatar

Soh Ishiguro soh-i

View GitHub Profile
@soh-i
soh-i / gg.R
Created January 5, 2024 22:03
ggplot with nice log ticks
LINE.W <- 0.232 # 0.5pt
breaks_log10 <- function(x) {
low <- floor(log10(min(x)))
high <- ceiling(log10(max(x)))
10^(seq.int(low, high))
}
... scale_y_log10(
limits = c(1e-3, 10),
@soh-i
soh-i / thesis.md
Last active July 12, 2023 07:42
Writing a thesis with Tex+Texpad

なぜTexで書く?

150ページ以上の英語のドキュメント (PhD thesis)を作成するにあたり、Wordはファイルを分割したり図や表を別のファイルに置いて、コンパイル時にだけ読み出したりすることができない。このため、最終的に巨大な重いファイルを編集してとてもつらまる可能性が目に見えていた。したがって、テキストベースの段組処理ソフトウェアであるTexを使って書くことにした。当初は2020年にもなってTex書くのかーという気分であったが、この選択は正解であったと思う。

Texで生成されたPDFは見た目は非常に美しい。またただのテキストなので好きなエディタで執筆できる。難点としては、独自の記法を覚える必要があること、それからエラーメッセージが不親切でどの個所がエラーなのかときに非常に分かりにくいところである。筆者は数年ぶりにtexを書いたので、ほぼ書き方を忘れていた。

Texは段組ソフトウェアなので、見た目のあらゆるカスタマイズが可能であるが、歴史的に蓄積された様々なノウハウ(謎のバッドノウハウやworkaround)がインターネット上にあふれており、良い感じにするために時間を消費しがちなところ。沼なので、あまり細部に入り込まないほうがよい。時短のためには最初によくできたテンプレートを拝借して、それを使うのがよいと思う。

最近だとOverleaf (https://ja.overleaf.com/) というオンラインでTexがかける環境も整備されているようで、もしかするとこっちのほうが時流なのかもしれない。とくに複数人で書く場合などは。Thesis用のtemplateはインターネットにいろいろあるが、例えばOverleafでは https://ja.overleaf.com/gallery/tagged/thesis にギャラリーがある。ダウンロードしてローカルで使うことも可能だ。

どのTexのディストリビューションを使うか

@soh-i
soh-i / merge_fcs.R
Created March 16, 2022 19:25
Merge multiple FCS files into a single fcs file
# premessa::concatenate_fcs_files
# modified based on the following code:
# https://rdrr.io/github/ParkerICI/premessa/src/R/fcs_io.R
update_flowFrame_keywords <- function(flowFrame, exprs.m, desc = NULL, data.range = "data") {
params <- flowCore::parameters(flowFrame)
pdata <- flowCore::pData(params)
if (is.null(desc)) {
desc <- colnames(exprs.m)
@soh-i
soh-i / template.Rmd
Created January 17, 2022 22:57
Rmarkdown template
---
title: "notebook title"
author: "Soh Ishiguro"
date: "`r Sys.Date()`"
output:
html_document:
toc: yes
toc_float: no
number_sections: yes
keep_md: yes
@soh-i
soh-i / gs.R
Created February 17, 2022 19:08
Get single cell expression from GatingSet object
...
sample.names <- sampleNames(gs.trans)
gs.exp.df <- data.table()
for (sample in sample.names) {
message(sprintf("Processing: %s", sample))
df <- gs_get_singlecell_expression(gs.trans, c("P1"),
threshold = FALSE, marginal = FALSE, inverse.transform = TRUE,
other.markers = c("SSC-A", "FL1-A", "FL5-A")
)[[sample]] %>%
data.table() %>%
@soh-i
soh-i / ggcyto.R
Last active September 19, 2022 17:19
FACS plot with user-defined gate
library(CytoML)
library(flowWorkspace)
library(ggcyto)
xmlfile <- 'gate.xml' # Gating-ML xml file generated by Cytobank
fcsFiles <- list.files(pattern='.fcs', path='./FCS/', full.names=TRUE)
gs <- cytobank2GatingSet(xmlfile, fcsFiles)
fs <- getData(gs, "P1") # FCS file object filtered by P1 gate (live cell)
P2 <- getGate(gs, "P2") # P2 gate object (EGFP gate)
@soh-i
soh-i / dyna_gates.R
Created February 24, 2022 02:50
Generate dynamic rectangleGate object with flowCore and flowWorkspace
compute_dynamic_gate <- function(gs, inv.bins) {
df.stat <- data.frame()
for (min.cutoff in inv.bins) {
# Create dynamic FL1-A gate
rg_gfp <- flowCore::rectangleGate(
"FL1-A" = c(min.cutoff, Inf), "FSC-A" = c(-Inf, Inf),
filterId = "_dynamic"
)
gates <- flowWorkspace::gs_get_pop_paths(gs)
if ("/P1/_dynamic" %in% gates) {
@soh-i
soh-i / config.json
Created February 19, 2022 23:05
VScode config
{
//Theme
"workbench.colorTheme": "Monokai Dimmed",
//Editor configs
"files.autoSave": "afterDelay",
"editor.minimap.enabled": false,
"workbench.colorCustomizations": {"editorIndentGuide.background": "#00000000" }, // hide via 100% transparency.
"git.ignoreLegacyWarning": true,
"workbench.editor.enablePreview": false,
@soh-i
soh-i / vs_knit.json
Created February 8, 2022 06:52
Knit initialized snippet for VScode
{
"init_knit": {
"prefix": "init_knit",
"body": [
"---",
"title: $1",
"author: \"Soh Ishiguro\"",
"date: \"`r Sys.Date()`\"",
"output:",
" html_document: ",
@soh-i
soh-i / gist:5866222
Last active May 5, 2021 13:49
Convert XLSX/XLS to CSV file
#!/usr/bin/env perl
use strict;
use warnings;
use Carp;
use Getopt::Long;
use Pod::Usage;
use File::Basename qw/fileparse/;
use File::Spec;
use Spreadsheet::ParseExcel;