R覚え書き

1.空白を含む行を削除する→glmを使ってlogistic regression analysis

> df2 <- df[!is.na(df$GAP.score), ]
> View(df2)
> gene<-glm(formula =GAP.index~gene,family="binomial",data=df2)
> summary(gene)

2. ノンパラメトリック検定

# independent 2-group Mann-Whitney U Test
wilcox.test(df2$DLco~df2$sex)
# where y is numeric and A is A binary factor

# independent 2-group Mann-Whitney U Test
wilcox.test(df2$DLco,df2$gene) 
# where y and x are numeric
# Kruskal Wallis Test One Way Anova by Ranks
kruskal.test(df2$y1~df2$A) # where y1 is numeric and A is a factor

3. Box plot & scatterplot

DESeq2で得られたデータを用いてscatterplotを出力してみる。geneの名前は"gene"で定義し、ggrepelで読みやすくする。有意なプロットは黒、それ以外はdark greyで描出している。

library(ggplot2)
library(ggrepel)
# Box plot
ggplot(data=bind,aes(x=A,y=X.Dlco.))+geom_point(size=2,shape=16)+geom_smooth(method=lm,se=F,color="black")+labs(x="A",y="%DLco")+theme_bw()+theme(axis.title = element_text(size=rel(1.5)))

#Scatter plot
bx<-bxAvsB
bx1=bx[abs(bx$logA)>1,]
bx2=bx1[abs(bx1$logB)>1,]
bx3=bx2[bx2$padj.A<0.05,]
bx4=bx3[bx3$padj.B<0.05,]
tiff("scatterbx.tif", unit="in", width=5, height=4,res=600,compression="lzw")
ggplot(data=bx,aes(x=logA,y=logB,label=gene))+geom_point(color="darkgrey")+geom_point(data=bx4,aes(x=logA,y=logB),color="black")+geom_abline()+geom_text_repel()+geom_vline(xintercept=1,colour="darkgrey")+geom_vline(xintercept=-1,color="darkgrey")+geom_hline(yintercept=1,color="darkgrey")+geom_hline(yintercept=-1,color="darkgrey")+ theme_bw()+geom_abline()+labs(x="log2FoldChange of bxA",y="log2FoldChange of bxB")+xlim(-15,15)+ylim(-15,15)
dev.off()

4. Volcano plot

|log2FoldChange|>2, adjusted p value<0.05を有意とした。

plot(log2FoldChange, -log10(padj), pch=19, col="lightgrey", main="A vs Control", xlab="Log2FoldChange",ylab="-log10(adjusted pvalue)")
with(subset(df, padj<0.05 ), points(log2FoldChange, -log10(padj), pch=19, col="blue"))
with(subset(df, abs(log2FoldChange)>2), points(log2FoldChange, -log10(padj), pch=19, col="black"))
with(subset(df, padj<0.05 & abs(log2FoldChange)>2), points(log2FoldChange, -log10(padj), pch=19, col="tomato"))
with(text(x=log2FoldChange, y=-log10(padj), labels=gene,col="black",pos=3))
with(abline(v=2,col="darkgrey"))
with(abline(v=-2,col="darkgrey"))
with(abline(h=1.3,col="darkgrey"))

など。写真は去年のBreckenridgeスキー場。今年は果たしてスキー行けるのか、、、

この記事が気に入ったらサポートをしてみませんか?