单细胞数据分析计算每个细胞MT-比例
作者:互联网
1、awk + >>追加实现
for i in $(seq 2 $(head -n 1 a.txt | awk '{print NF}')); do cut -f 1,$i a.txt | awk 'BEGIN{sum =0 } {if(NR != 1) sum += $2} {if($1 ~ /^MT-/ && NR != 1) {sum1 += $2}} END {print 100 * sum1/sum}' >> result.txt; done
2、awk + shell数组实现
sed 1d a.txt | awk '{for(i = 2; i <= NF; i++) {array1[i] += $i; if($1 ~ /^MT-/) {array2[i] += $i}}} END {for(i = 2; i <= NF; i++) {print 100 * array2[i]/array1[i]}}' > result.txt
3、R实现
001、
dir() dat <- read.table("a.txt", header = T) dim(dat) mt <- dat[grep("^MT-", rownames(dat)),] dim(mt) result <- apply(mt, 2, sum)/apply(dat, 2, sum) * 100 head(result) tail(result)
标签:数据分析,sum,sum1,MT,awk,单细胞,print,NR,txt 来源: https://www.cnblogs.com/liujiaxin2018/p/16425921.html