【问题标题】:Calculating the GC content of a list of sequences individually分别计算序列列表的 GC 含量
【发布时间】:2022-12-18 03:44:52
【问题描述】:

我有一个序列列表,我正在尝试以百分比计算 GC 含量(意味着序列的百分比是字母“G”、“g”、“C”、“c”)

#series of sequences
seq0,seq1,seq2,seq3,seq4,seq5 = 'CCACGCGTCCGCCGCGACCTGCGTTTTCCTGGGGGTCCGCAACTCTGGCTTGACCCAAGGACCCGGCCAC','attgccattatataACCCGGCCACCCCCATAGGCAGATGTCAGGACAACTCGCATCTCAGCAGAGCAGCCCCTGGCCCAGG','TCXCACCCATAGGCAGATGGCCTCCGCCCCACCCCCGGGAGGATTTCTTAATGGGGTGAAAATGC','CAGTCCCCGAAGCCAGGGTTCCGGGACCCCCGGGGCCGAGCTGGGCGCGGGAAAAGAAttacggacttaGTCAGCCCCGCAGGGG','ATGGGGTGATCGTCGCTCGCGGGCTCTGTCTTCCTGTTCACCCTCCTCTGCCCCCAACTCCATCTCTGAGACCTCCTGCCCCCCCA','AAAAAAGAAGTCGCTCGCGTCGCTCGCGGGCTGGGCTCTGTCTGCGTCGCTCGCGGGCTAGAGAGCCAGGGTGA'

#sequences aggregated into a list
NTs = [seq0,seq1,seq2,seq3,seq4,seq5]

#specifying nucleotides
nucleotides = ['G','A','C','T', 'U']

#checking and removing if there are any non-nucleotide characters present
if any(x not in nucleotides for x in NTs):
     print("ERROR: non-nucleotide characters present")
[''.join(i for i in x if i.upper() in nucleotides) for x in NTs]

 #calculating GC percent of each sequence using the aggregated list
 gCountseq0 = seq0.count('G') + seq0.count('g')
 cCountseq0 = seq0.count('C') + seq0.count('c')
 gcContentseq0 = ((gCountseq0 + cCountseq0)*100) / len(seq0)
 print('The GC content of seq0 is',gcContentseq0,'%')

由此我得到了输出

ERROR: non-nucleotide characters present
The GC content of seq0 is 70.0 %

最终我试图得到看起来像下面输出的东西,但我有点卡住了,我不知道如何将 NTs 列表作为 GC% 计算的参数,这样我就可以完成所有的序列一次而不是一个一个地

ERROR: non-nucleotide characters present in seq2
The GC content of seq0 is x %
The GC content of seq1 is x %
The GC content of seq2 is x %
The GC content of seq3 is x %
The GC content of seq4 is x %
The GC content of seq5 is x %

【问题讨论】:

标签: python-3.x bioinformatics


【解决方案1】:

您只需要在循环中迭代您的序列列表 (NT) 并在每次迭代中计算 GC 争用。

这是GC计算的函数:

def GC_calc(fa_string):
    _string = fa_string.upper()
    _G = _string.count('G')
    _C = _string.count('C')
    return (_G + _C)/len(_string) * 100

这是一个循环:

for i,j in zip(names, NTs):
    print(f'The GC content of {i} is {GC_calc(j)} %')

在这里,我使用zip 函数同时遍历名称和序列。我认为这是更好的方法。这样做你应该在 zip 函数中添加 list 的序列名称。

names = ['seq_name_1', 'seq_name_2']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-15
    • 1970-01-01
    相关资源
    最近更新 更多