一个非常简陋的otu表转化水平工具 需要前期处理
程序员文章站
2022-03-11 18:40:41
...
标题
转化各水平OTU标
import xlrd
import xlsxwriter
i=0
j=1
p=0
k=0
numi=0
numj=0
workbook= xlrd.open_workbook('/media/sf_Myshared/t1d_mejialeon.otu_table.100.denovo.xlsx')
worksheets = workbook.sheet_names()
table = workbook.sheet_by_name('t1d_mejialeon.otu_table.100.den')
sheet_names= workbook.sheet_names()
book= xlsxwriter.Workbook('/media/sf_Myshared/PM_otu_final/t1d_mejialeon.otu_table.100.denovo.xlsx')
sheet1=book.add_worksheet("sheet1")
nrows = table.nrows
ncols = table.ncols
name1=table.cell_value(0,0)
for sheet_name in sheet_names:
sheet2 = workbook.sheet_by_name(sheet_name)
print (sheet_name)
cols = sheet2.col_values(0)
b = list(set(cols))
b.sort(key=cols.index)
for x in b:
sheet1.write(numj,0,x)
numj+=1
for each_b in b:
count = 0
for each_a in cols:
if each_b == each_a:
count += 1
#print(count)
k=k+count
numi=0
for j in range(1,ncols):
sum=0
numi+=1
for i in range(k-count,k):
cellva=table.cell_value(i,j)
sum=sum+cellva
sheet1.write(p,numi,sum)
#print (sum)
p+=1
#print (k-count)
#print (b)
book.close()
上一篇: Mysql模糊查询多个条件regexp