Skip to content

Commit 0661659

Browse files
committed
few updates
1 parent 5203e07 commit 0661659

4 files changed

Lines changed: 149 additions & 8 deletions

File tree

bioinformatics.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ Programming skills
123123
- [golang] [Biogo](https://github.com/biogo)
124124
- [golang] [bio](https://github.com/shenwei356/bio) - A simple but high-performance bioinformatics package in Go
125125

126+
## Sequencing
127+
128+
### About reads duplicates
129+
130+
> I recommend optical duplicate removal for all HiSeq platforms, for any kind of project in which you expect high library complexity (such as WGS). By optical duplicate, I mean removal of duplicates with very close coordinates on the flow cell
131+
132+
- [Duplicates on Illumina](https://www.biostars.org/p/229842/)
133+
- [Remove duplicates from reads: best practices?](https://www.biostars.org/p/230822/)
134+
- [`bbmap clumpify` can remove PCR and optical duplicates](https://www.biostars.org/p/225338/#230178)
135+
- [Deduplication Improves Cost-Efficiency and Yields of De Novo Assembly and Binning of Shotgun Metagenomes in Microbiome Research](https://journals.asm.org/doi/10.1128/spectrum.04282-22)
136+
126137
## General file formats
127138

128139
- [zindex](https://github.com/mattgodbolt/zindex) - Create an index on a compressed text file

golang.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,4 @@ See more on [awesome-go](https://github.com/avelino/awesome-go), [golang openso
557557

558558
- [range over interface{} which stores a slice](https://stackoverflow.com/questions/14025833/range-over-interface-which-stores-a-slice/14026030#14026030)
559559
- [calendarheatmap](https://github.com/nikolaydubina/calendarheatmap)
560+
- [Dump any data as valid syntax in Go](https://github.com/Code-Hex/dd)

notes/r-note.md

Lines changed: 133 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ regular expression capture
6161
# str_match_all() to match all groups in a regex
6262
```
6363

64+
## font
65+
66+
https://stackoverflow.com/questions/61204259/how-can-i-resolve-the-no-font-name-issue-when-importing-fonts-into-r-using-ext
67+
68+
```R
69+
library(extrafont)
70+
font_import(paths="/home/shenwei/.fonts/a/", prompt = FALSE)
71+
72+
73+
```
74+
75+
6476
## Data Structures
6577

6678
### Vector
@@ -515,14 +527,28 @@ show_col(colors)
515527
# https://rdrr.io/cran/ggthemes/man/colorblind.html
516528
colors <- colorblind_pal()(8)
517529

518-
colors <- colorblind_pal()(n+1)[2:n+1] # begin with 2nd color
530+
colors <- colorblind_pal()(n+1)[2:(n+1)] # begin with 2nd color
519531

520532
show_col(colors)
521533

522534
colors <- c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00" "#CC79A7")
523535

524536
n <- 18 # give me 18 colors
525537
show_col(rep(colors, ceiling(n/length(colors)))[1:n])
538+
539+
540+
# colorblind
541+
n <- length(unique(df$tool))
542+
colors0 <- c("grey30", "grey50", "grey70", "grey90")
543+
if (n>7) {
544+
colors <- colorblind_pal()(7 + 1)[2:(7 + 1)] # begin with 2nd color
545+
for (i in seq(1, n-7)) {
546+
colors <- append(colors, colors0[i])
547+
}
548+
} else {
549+
colors <- colorblind_pal()(n + 1)[2:(n + 1)] # begin with 2nd color
550+
}
551+
526552
```
527553

528554
reverse gradient color
@@ -693,12 +719,17 @@ p <- plot_grid(
693719
ncol = 1,
694720
nrow = 3,
695721
labels = c("HSC", "ENDO", "MAC"),
722+
label_size = 10.5,
723+
label_fontface = "plain",
696724
rel_heights = c(1, 1, 1)
697725
),
698726
legend,
699727
ncol = 2,
700728
rel_widths = c(1, 0.2)
701-
)
729+
) + theme ( # fill the gap in sub figures
730+
panel.background = element_rect(fill = "white", colour = NA),
731+
)
732+
702733

703734
```
704735

@@ -733,7 +764,7 @@ p <- p + stat_pvalue_manual(stat.test,
733764
hide.ns = TRUE,
734765
)
735766

736-
p <- p + scale_y_continuous(expand = expansion(mult = c(0, 0.1)))
767+
p <- p + scale_y_continuous(expand = expansion(mult = c(0, 0.1))) No space below the bars but 10% above them
737768

738769
```
739770

@@ -770,15 +801,41 @@ minor_breaks
770801

771802
[dual y-axis (second axis)](https://www.r-graph-gallery.com/line-chart-dual-Y-axis-ggplot2.html)
772803

804+
[How to plot a 2- y axis chart with bars side by side without re-scaling the data](https://stackoverflow.com/questions/54413787/how-to-plot-a-2-y-axis-chart-with-bars-side-by-side-without-re-scaling-the-data/54426831#54426831)
805+
773806
```R
774-
scale <- xxxx
775807

776-
geom_line(aes(y = -log10(fpr) / scale, color = rlen), size = 0.9) +
808+
every_nth <- function(x,
809+
nth,
810+
empty = TRUE,
811+
inverse = FALSE) {
812+
if (!inverse) {
813+
if (empty) {
814+
x[1:nth == 1] <- ""
815+
x
816+
} else {
817+
x[1:nth != 1]
818+
}
819+
} else {
820+
if (empty) {
821+
x[1:nth != 1] <- ""
822+
x
823+
} else {
824+
x[1:nth == 1]
825+
}
826+
}
827+
}
828+
829+
830+
831+
s <- max(left)/max(right)
832+
833+
geom_line(aes(y = -log10(fpr) / s, color = rlen), size = 0.9) +
777834

778835
scale_y_continuous(
779836
name = "Recall(%)",
780837
sec.axis = sec_axis(
781-
~ . * scale,
838+
~ . /s,
782839
name = "-log10(Query FPR)",
783840
breaks = custom_breaks_y2,
784841
labels = every_nth(custom_breaks_y2, 2)
@@ -788,6 +845,40 @@ scale_y_continuous(
788845
labels = every_nth(custom_breaks_y, 2, inverse = TRUE)
789846
)
790847

848+
# --- another example
849+
850+
s <- max(df2$time2) / max(df2$mem2)
851+
852+
p <- ggplot(df2, aes(app)) +
853+
geom_col(aes(y = time2),
854+
width = 0.4,
855+
position = position_nudge(x = -.2),
856+
fill = "#E69F00") +
857+
geom_col(aes(y = mem2*s),
858+
width = 0.4,
859+
position = position_nudge(x = +.2),
860+
fill = "#56B4E9") +
861+
xlab(NULL) +
862+
scale_y_continuous(
863+
name = "Time (seconds)",
864+
sec.axis = sec_axis(
865+
~ . / s,
866+
name = "Peak memory (GB)"
867+
),
868+
expand = c(0, 0)
869+
) +
870+
theme1 +
871+
theme(
872+
legend.position = "none",
873+
axis.text.x = element_text(color = "grey10", angle=30, hjust=1, vjust=1), # label of axis
874+
875+
axis.title.y.left = element_text(color="#E69F00"),
876+
axis.text.y.left = element_text(color="#E69F00"),
877+
axis.title.y.right = element_text(color="#56B4E9"),
878+
axis.text.y.right = element_text(color="#56B4E9"),
879+
)
880+
881+
791882
```
792883

793884

@@ -887,6 +978,7 @@ p <- ggplot(df_m) +
887978

888979
scale_x_discrete(labels = c('0','1','2')) +
889980
scale_y_continuous(expand=c(0,0)) # delete space between bar and x axis
981+
scale_y_continuous(expand = expansion(mult = c(0, 0.1))) + # No space below the bars but 10% above them +
890982
scale_x_continuous(limits=c(0, args$x_limit), breaks = seq(0, args$x_limit, by = args$x_break))+
891983
scale_y_continuous(labels = comma) +
892984
expand_limits(y=0) + # equal to ylim(0, max(BOD$demand))
@@ -896,6 +988,8 @@ p <- ggplot(df_m) +
896988

897989
scale_fill_manual(values=c("#CCEEFF", "#FFDDDD"), guide=FALSE)
898990

991+
scale_color_gradient_tableau(palette = "Orange", guide = "legend") + # combine/merge color/fill and size legends
992+
899993
scale_colour_gradient2_tableau("Orange-Blue Diverging") +
900994
scale_colour_gradient2_tableau(trans = "reverse")
901995

@@ -1096,7 +1190,23 @@ p <- plot_grid(
10961190
ggsave(
10971191
p, file = "Figure 2.png", width = 8, height = 5, dpi = 600
10981192
# compression = "lzw"
1099-
)
1193+
) + theme ( # fill the gap in sub figures
1194+
panel.background = element_rect(fill = "white", colour = NA),
1195+
)
1196+
1197+
1198+
1199+
# move legend to anywhere
1200+
legend <- get_legend(pn)
1201+
1202+
plot_grid(
1203+
pn + theme(legend.position = "none"),
1204+
pc,
1205+
ncol = 2,
1206+
labels = c("a", "c"),
1207+
rel_widths = c(1, 1)
1208+
) + draw_plot(legend, 0.005, 0.65, 0.4, 0.4) ,
1209+
11001210

11011211

11021212
# with title
@@ -1107,7 +1217,9 @@ p <- plot_grid(
11071217
plot_grid(p1, p2, ncol=2),
11081218
nrow = 2,
11091219
rel_heights=c(0.1, 1)
1110-
)
1220+
) + theme ( # fill the gap in sub figures
1221+
panel.background = element_rect(fill = "white", colour = NA),
1222+
)
11111223

11121224
```
11131225

@@ -1116,3 +1228,16 @@ recode a continuous variable to another variable
11161228
```
11171229
pg$wtclass <- cut(pg$weight, breaks = c(0, 5, 6, Inf))
11181230
```
1231+
1232+
plyr::mapvalues with dplyr
1233+
```R
1234+
df %>% mutate(sex=recode(sex,
1235+
`1`="Male",
1236+
`2`="Female"))
1237+
```
1238+
1239+
add index (unique number) with in group
1240+
1241+
```R
1242+
df <- df %>% group_by(sample) %>% mutate(id = seq_along(taxid))
1243+
```

notes/shell.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- [How do I use a Bash variable (string) containing quotes in a command?](https://superuser.com/questions/360966/how-do-i-use-a-bash-variable-string-containing-quotes-in-a-command)
2+
3+
outfmt=("6 qseqid sseqid pident")
4+
blastn ... -outfmt "${outfmt[@]}"

0 commit comments

Comments
 (0)