【问题标题】:finding GC content of sequences in pandas dataframe在 pandas 数据框中查找序列的 GC 内容
【发布时间】:2015-04-27 18:06:23
【问题描述】:

我有一个数据框 df

oligo_name  oligo_sequence

AAAAA       attttggggctggtaa

BBBBB       attttcccgaatgtca

等等。为了计算每个序列的 GC 含量,我做了以下操作

from Bio.SeqUtils import GC

df['GC content'] = GC(df['oligo_sequence'])

但我收到以下错误:

KeyError: 'Level G must be same as name (None)'

您能否建议一种修复方法或更好的方法来计算 pandas 数据框中序列的 ​​GC 内容。谢谢

【问题讨论】:

  • 你可以试试这个:df['GC content'] = df[['oligo_sequence']].apply(lambda row: GC(row), axis=1)

标签: pandas biopython


【解决方案1】:

以下内容对我有用:

In [23]:

df['GC content'] = df['oligo_sequence'].apply(GC)
df
Out[23]:
  oligo_name    oligo_sequence  GC content
0      AAAAA  attttggggctggtaa       43.75
1      BBBBB  attttcccgaatgtca       37.50

您不能将 Series 作为参数传递给函数,除非它了解 pandas Series 或数组类型是什么,因此您可以改为调用 apply 并将函数作为参数传递,这将为每个函数调用该函数Series 中的值如上所示。

【讨论】:

    猜你喜欢
    • 2019-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-04
    • 2021-06-23
    • 1970-01-01
    • 2021-12-20
    • 2021-09-23
    相关资源
    最近更新 更多