for i in `cat file3 | awk -F " " '{print $1}' | sort | uniq`
do
fc_count=`grep ${i} file3 | wc -l `
for y in `cat file3 | awk -F " " '{print $2}' | sort | uniq`
do
sample_count=`grep ${y} file3 | wc -l `
sample_fc_count=`grep ${y} file3 | grep ${i} | wc -l `
echo ${i} ${y} ${sample_fc_count} >>count.txt
echo ${y} ${sample_count} >>count.txt
done
echo ${i} ${fc_count} >>count.txt
done
另一种写法
cat file3 | awk -F " " '{print $2}' | sort -u | uniq -c
cat file3 | sort -u | uniq -c
python脚本
#!/usr/bin/env python
#-*-coding:utf-8-*-
import os
import re
file=open("file3","r")
# FC 和 sample 各存一个字典
dictfc = {}
dictsample = {}
dictfcsam= {}
# 按照行 读文件;
fileline=file.readlines()
for line in fileline:
key = line.strip().split("\t")
# dict[key[0]]=key[1]
fc = key[0]
sample = key[1]
# fc存入字典
if fc not in dictfc:
dictfc[fc] = 1
else:
dictfc[fc] += 1
# sample存入字典
if sample not in dictsample:
dictsample[sample] = 1
else:
dictsample[sample] += 1
if line not in dictfcsam:
dictfcsam[line] = 1
else:
dictfcsam[line] += 1
print(dictfc)
print(dictsample)
print(dictfcsam)
file.close()
网友评论