![](/img/trans.png)
[英]How do i convert a three-letter amino acids to single letter in an excel file
[英]How do I convert a column of 3-letter amino acids to 1- letter amino acids in excel w/ biopython?
對於舊的 xls 文件,我在下面管理代碼,與您的示例一起使用新列保存文件的副本。 我了解 pandas 庫可以更好地管理 xlx 和更新版本。 讓我知道它對你有用
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat May 1 15:24:42 2021
@author: Pietro
https://stackoverflow.com/questions/67271713/how-do-i-convert-a-column-of-3-letter-amino-acids-to-1-letter-amino-acids-in-ex#comment119033760_67271713
"""
#import Bio #not needed
from Bio.SeqUtils import seq1
# Reading an excel file using Python
import xlrd #read xls library
from xlutils.copy import copy #copies xls library
## from xlwt import Workbook # writes xls library ##not necessary
loc = ("inputz.xls") # input xlx same directory of python script
wb = xlrd.open_workbook(loc) #open xls file
wb_copy = copy(wb) #copy of your xls file
sheet = wb.sheet_by_index(0) #select sheet of input file
sheet_copy = wb_copy.get_sheet(0) #select sheet of copy file
lenght_rows = sheet.nrows #number of rows in input file
print(sheet.cell_value(0, 0)) # prints sheet 0 cell 0,0 of input file
print(lenght_rows) #prints number of rows of input file
# loops over row (0,1 to 0, number of rows) of input file
#
# and use biopython to convert 3 letter into 1 letter
# writes 3 and 1 letters to copy xls file
for i in range(1,lenght_rows):
print(sheet.cell_value(i, 0), ' : ' , seq1(sheet.cell_value(i, 0)))
sheet_copy.write(i,0,sheet.cell_value(i, 0))
sheet_copy.write(i,1,seq1(sheet.cell_value(i, 0)))
wb_copy.save('output.xls') #saves xls output file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.