Skip to content

Instantly share code, notes, and snippets.

View ianyfchang's full-sized avatar

Ian YF Chang ianyfchang

  • Taipei, Taiwan
View GitHub Profile
# https://gist.github.com/bobthecat/5024079
bigcorPar <- function(x, nblocks = 10, verbose = TRUE, ncore="all",pvalue=0.05, ...){
library(ff, quietly = TRUE)
library(psych)
require(doMC)
if(ncore=="all"){
ncore = 30
registerDoMC(cores = ncore)
} else{
registerDoMC(cores = ncore)
bigcorPar <- function(x, nblocks = 10, verbose = TRUE, ncore="all", ...){
library(ff, quietly = TRUE)
require(doMC)
if(ncore=="all"){
ncore = multicore:::detectCores()
registerDoMC(cores = ncore)
} else{
registerDoMC(cores = ncore)
}
@ianyfchang
ianyfchang / 0_reuse_code.js
Last active August 29, 2015 14:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ianyfchang
ianyfchang / label_hmr_direction.sh
Created May 17, 2014 15:08
Labeling HMR direction
awk -F "\t" –v S=”Sample” -v OFS="\t" '{
if($12=="-" && $25=="-" && $36=="-" && $13==0 && $26==0 && $37==0) print $4,$5,$6,"-",S,$10,$12,$13,$23,$25,$26,$34,$36,$37,$NF;
else if($12=="-" && $25=="-" && $13==0 && $26==0 && $37!=0) print $4,$5,$6,"-",S,$10,$12,$13,$23,$25,$26,$34,$36,$37,$NF;
else if($12=="-" && $36=="-" && $13==0 && $26!=0 && $37==0) print $4,$5,$6,"-",S,$10,$12,$13,$23,$25,$26,$34,$36,$37,$NF;
else if($12=="-" && $13==0 && $26!=0 && $37!=0) print $4,$5,$6,"-",S,$10,$12,$13,$23,$25,$26,$34,$36,$37,$NF;
else if( $25=="-" && $36=="-" && $13!=0 && $26==0 && $37==0) print $4,$5,$6,"-",S,$10,$12,$13,$23,$25,$26,$34,$36,$37,$NF;
else if( $25=="-" && $13!=0 && $26==0 && $37!=0) print $4,$5,$6,"-",S,$10,$12,$13,$23,$25,$26,$34,$36,$37,$NF;
else if( $36=="-" && $13!=0 && $26!=0 && $37==0) print $4,$5,$6,"-",S,$10,$12,$13,$23,$25,$26,$34,$36,$37,$NF;
else print $4,$5,$6,"+",S,$10,$12,$13,$23,$25,$26,$34,$36,$37,$NF;
}' snippet.hmr.bed.5prime.3prime.cloestKnownGFeneTSS1000 > snippet.hmr.overlap.tss.cp
@ianyfchang
ianyfchang / hg19.chrlen
Created May 16, 2014 07:40
HG19 Chromosome Length File
chr1 249250621
chr1_gl000191_random 106433
chr1_gl000192_random 547496
chr2 243199373
chr3 198022430
chr4 191154276
chr4_ctg9_hap1 590426
chr4_gl000193_random 189789
chr4_gl000194_random 191469
chr5 180915260
@ianyfchang
ianyfchang / hg19.chrlen.bed
Created May 16, 2014 07:38
HG19 Chromosome length BED file
chr1 0 249250621
chr1_gl000191_random 0 106433
chr1_gl000192_random 0 547496
chr2 0 243199373
chr3 0 198022430
chr4 0 191154276
chr4_ctg9_hap1 0 590426
chr4_gl000193_random 0 189789
chr4_gl000194_random 0 191469
chr5 0 180915260
@ianyfchang
ianyfchang / generate_hmr_heatmap.sh
Last active August 29, 2015 14:01
A shell script generates R scripts to plot heat map of HMR
# 檢查 ggplot2 與 grid 套件是否安裝
echo 'list.of.packages <- c("ggplot2","grid")'
echo 'new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]'
echo 'if(length(new.packages)) install.packages(new.packages)'
# 載入 ggplot2 套件
echo 'library(ggplot2) '
# 將多張圖繪製成同一張圖的函式 (http://stackoverflow.com/questions/11721401/r-save-multiplot-to-file)
echo 'multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) { '
echo ' require(grid) '
echo ' # Make a list from the ... arguments and plotlist '
@ianyfchang
ianyfchang / Merge.java
Created May 7, 2014 07:35
Merge two files based on common chromosome position
import java.util.stream.*;
import java.util.*;
import java.nio.file.*;
import java.io.*;
import static java.lang.System.out;
class Merge {
public static void main (String... args)throws Exception{
Map<String,String> sorted = Files.lines(Paths.get(args[0]))
.map(line -> line.split("\t"))
@ianyfchang
ianyfchang / GenerateBinsForRegionsAndReverseByStrand.java
Created May 6, 2014 08:34
Splitting each chromosome position in BED-like format into bins
import java.util.zip.*;
import java.io.*;
import java.util.*;
public class GenerateBinsForRegionsAndReverseByStrand{
static LinkedHashMap<String, String> data = new LinkedHashMap<String, String>();
public static void main(String[] args) throws Exception {
if(args.length!=2){
System.err.println("java -Xmx14g GenerateBinsForRegionsAndReverseByStrand bed-like binsize");
System.exit(1);
@ianyfchang
ianyfchang / ExtractIntronExonUTRFromKnownGeneAndKgXref.java
Created May 5, 2014 13:17
Extracting TSS, Exons, Introns, 5'UTR and 3' UTR from UCSC knownGene.txt and kgXref.txt
import java.io.*;
import java.util.*;
public class ExtractIntronExonUTRFromKnownGeneAndKgXref {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(args[1]));
HashMap<String,String> xref=new HashMap<String,String>();
String tmp = "";
while ((tmp = br.readLine()) != null) {
String[] x = tmp.split("\t");