Skip to content

Instantly share code, notes, and snippets.

View ShixiangWang's full-sized avatar
🀄
Open Source Better Science

Shixiang Wang (王诗翔) ShixiangWang

🀄
Open Source Better Science
View GitHub Profile
@ShixiangWang
ShixiangWang / survival-plot.R
Last active December 4, 2017 11:26
指定肿瘤表达数据矩阵和基因,根据基因分组绘制生存曲线,并按步长寻找最小p值(粗暴),需要先导入survival和survminer两个包
#' @function survival analysis according to gene expression for primary tumor
#' @param geneSymbol identify gene symbol
#' @param exp TCGA format gene expression dataset
#' @param cli Clinical information dataset
#' @param method method use to dive samples into groups. Options are "quantile", "median", "mean". the "quartile" use first and third quartile as threshold
#' @param trans transform the clinical IDs from '-' separate to '.' separate
#' @return include the plot and p value
#' @author Shixiang Wang
# input test data
@ShixiangWang
ShixiangWang / t_test.R
Created December 5, 2017 14:35
对分组基因表达数据进行t检验并矫正p value
T_test = function(data, group1, group2, adj.method="fdr"){
# the first column of data is identifier
# the others columns cotain gene expression, samples' name should be colnames
# group1, group2 are used to compare two groups of data
# adj.method defines which method used to adjust p values
colnames(data)[1] = "geneSymbol"
# only get samples we wanna to compare, be sure
# all names in group1 and group2 can match colnames of data
@ShixiangWang
ShixiangWang / plotDifference.R
Created December 10, 2017 14:55
绘制组间差异箱线图
pltDiff = function(data=NULL, sample=NULL, target=NULL,
group1, group2, group1.name="group1",
group2.name="group2", title="data", x_lab="", y_lab="",
notch=TRUE){
require(ggpubr, quietly = TRUE)
if(!is.data.frame(data)) stop("Wrong input! Please check your dataset. The input data type must be data.frame.")
a = data.frame(value=data[, target], group=ifelse(!(data[,sample]%in%c(group1,group2)),
NA, ifelse(data[,sample]%in%group1, group1.name, group2.name)))
a = a[a$group%in%c(group1.name, group2.name), ]
@ShixiangWang
ShixiangWang / getID.R
Created December 10, 2017 14:57
按四分位数、均值或中位数分组,返回名称
getID = function(exp_value, method){
# compute threshold according to method parameter
if(method=="quartile"){
symbol_stat <- summary(exp_value)
ths1 <- as.numeric(symbol_stat[2])
ths2 <- as.numeric(symbol_stat[5])
down_id <- names(exp_value[exp_value<=ths1])
up_id <- names(exp_value[exp_value>=ths2])
}else if(method=="mean"){
ths <- mean(exp_value)
@ShixiangWang
ShixiangWang / summary_fun.R
Created December 10, 2017 14:59
数据总结函数
#' @function Summary functions for error bar plot.
#' @references http://www.jianshu.com/p/003138ac593b
## Gives count, mean, standard deviation, standard error of the mean, and confidence interval (default 95%).
## data: a data frame.
## measurevar: the name of a column that contains the variable to be summariezed
## groupvars: a vector containing names of columns that contain grouping variables
## na.rm: a boolean that indicates whether to ignore NA's
## conf.interval: the percent range of the confidence interval (default is 95%)
summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
@ShixiangWang
ShixiangWang / gist:a49818115256f7d8a38c43482a12d0e9
Created January 9, 2018 05:55 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
# ---------------------------
# Accessing the material
# https://tinyurl.com/bioc2017-ELMER
# ---------------------------
library("Bioc2017.TCGAbiolinks.ELMER")
Biobase::openVignette("Bioc2017.TCGAbiolinks.ELMER")
# ---------------------------
# Section 1:
# Aims:
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@ShixiangWang
ShixiangWang / product-info.csv
Created August 28, 2018 15:00 — forked from renkun-ken/product-info.csv
Demo data of products
id name type class released
T01 SupCar toy vehicle yes
T02 SupPlane toy vehicle no
M01 JeepX model vehicle yes
M02 AircraftX model vehicle yes
M03 Runner model people yes
M04 Dancer model people no
#!/bin/bash
# function Extract for common file formats
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
if [ -f "$1" ] ; then
NAME=${1%.*}