簡體   English   中英

如何在 excel 文件中將三字母氨基酸轉換為單字母

[英]How do i convert a three-letter amino acids to single letter in an excel file

我想將 excel 中的一列三個字母的氨基酸轉換為一個字母,並將一個字母的氨基酸打印到 excel 文件中的每個相應行。 我知道我可以為此使用 biopython。

我試過的:

import Bio
from Bio.SeqUtils import seq1
seq1("MetAlaIleValMetGlyArgTrpLysGlyAlaArgTer")
'MAIVMGRWKGAR*'

但我希望人們理解,我不能為 python 放置一個字符串來進行轉換。 我需要閱讀 excel 中的一整列,並使用轉換后的 1 字母序列打印一個新列。 供參考的圖片:

示例:在此處輸入圖像描述

也許你可以試試下面的腳本。 您需要為所有可能的三個字母組合擴展它。 希望這對你有用。

# open file 
import pandas as pd
df = pd.read_excel (r'file')
df.columns=['three letter code']

codes = []
for i in df['code']:
  if i == 'uuu':
    codes.append('U')
  if i == 'cuu':
    codes.append('C')    
  if i == 'uaa':
    codes.append('A')
print (codes)
df['new_code']= codes
df

output 是:

        code    new_code
0       uuu     U
1       cuu     C
2       uaa     A

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM