Skip to content

Instantly share code, notes, and snippets.

@YulongNiu
YulongNiu / heatmap_JaYong.R
Created April 24, 2019 17:39
R heatmap for Ja Yong (zeros and positive number)
library('pheatmap')
##~~~~~~~~~~~~~~~~~~simulating data~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rn <- 100
cn <- 12
testdat <- matrix(rnorm(rn * cn), rn, cn)
testdat[1 : (rn/2), seq(1, cn, 2)] <- testdat[1 : (rn/2), seq(1, cn, 2)] + 5
testdat[(rn/2 + 1) : rn, seq(2, cn, 2)] <- testdat[(rn/2 + 1) : rn, seq(2, cn, 2)] + 7
testdat <- apply(testdat, 1:2, function(x) ifelse(x < 0, 0, x))
@YulongNiu
YulongNiu / TestSynchron.cpp
Last active October 5, 2018 13:41
Test synchronization in Rcppparallel
#include <RcppArmadillo.h>
#include <RcppParallel.h>
#include <tthread/tinythread.h>
#include <algorithm>
#include <vector>
using namespace Rcpp;
using namespace RcppParallel;
using namespace arma;
@YulongNiu
YulongNiu / testparallelvector.cpp
Created September 17, 2018 09:44
Test Rcpp parallel with vector
#include <RcppArmadillo.h>
#include <RcppParallel.h>
#include <algorithm>
#include <vector>
using namespace Rcpp;
using namespace RcppParallel;
using namespace arma;
using namespace std;
@YulongNiu
YulongNiu / testRcppparallel.R
Last active July 23, 2018 06:38
Test Rcpp parallel with R versions
library('microbenchmark')
library('Rcpp')
library('RcppParallel')
library('foreach')
library('parallel')
library('doParallel')
library('iterators')
sourceCpp('testrcpp.cpp')
@YulongNiu
YulongNiu / testrcpp.cpp
Last active July 23, 2018 06:38
Test Rcpp parallel with C++ versions
#include <RcppArmadillo.h>
#include <RcppParallel.h>
#include <algorithm>
#include <cmath>
using namespace Rcpp;
using namespace RcppParallel;
using namespace arma;
// [[Rcpp::depends(RcppArmadillo, RcppParallel)]]
@YulongNiu
YulongNiu / QAP_test.R
Created December 16, 2017 08:24
QAP test of three networks
## set working path
setwd('/home/Yulong/RESEARCH/QAPTest/')
## to symmetric matrix
SymMat <- function(mat) {
## example
## tmp1 <- matrix(c(1, '-', '-', 2, 4, '-', 3, 5, 6), ncol = 3, byrow = TRUE)
mat <- apply(mat, 1:2, as.character)
mat <- ifelse(mat == '-', 0, mat)
mat <- apply(mat, 1:2, as.numeric)
@YulongNiu
YulongNiu / testmaxintC.c
Created October 24, 2017 15:06
Test the maximum and minimum int value in C99
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main() {
int a = INT_MIN;
int b = INT_MAX;
double c = DBL_MIN;
@YulongNiu
YulongNiu / testmaxint.cpp
Created October 24, 2017 15:13
Test the maximum and minimum int value in C++11
#include <iostream>
#include <limits>
using namespace std;
int main() {
int a = numeric_limits<int>::min();
int b = numeric_limits<int>::max();
@YulongNiu
YulongNiu / summary_count.sh
Created September 12, 2017 13:30
Summary read counts at each nucleotide position for forward and reverse strands
samtools view -b Example_Condition1.sam -o Example_Condition1.bam
samtools view -b Example_Condition2.sam -o Example_Condition2.bam
## reverse
samtools view -h -f 16 Example_Condition1.bam -o Example_Condition1_rev.bam
## forward
samtools view -h -F 16 Example_Condition1.bam -o Example_Condition1_forw.bam
## reverse
samtools view -h -f 16 Example_Condition2.bam -o Example_Condition2_rev.bam
@YulongNiu
YulongNiu / prokaryo_anno_download.R
Last active October 5, 2017 14:19
Download gff/fna/ptt/rnt annotation files of a prokaryotic genome
###Download gff/fna/ptt/rnt annotation files of a prokaryotic genome ####
## Escherichia coli str. K-12 substr. MG1655 (E. coli)
## KEGG ID is 'eco' (http://www.genome.jp/kegg-bin/show_organism?org=eco)
## NCBI assembly ID is 'GCF_000005845.2' (https://www.ncbi.nlm.nih.gov/assembly/GCF_000005845.2)
library('ProGenome') ## version >= 0.06
library('magrittr')