如何用特定百分比的所需字符分隔字符串的各个部分?
How to separate parts of the string with a specific percent of the needed characters?
我正在尝试编写用于查找 siRNA 的代码。现在,我编写了一个代码,用于查找所有可能的 siRNA 组合。我还需要找到最好的,必须包含 30% 到 50% 的 GC 或 CG 核苷酸。
本程序正在寻找CG或GC含量在30%到50%之间的21个核苷酸长度的序列。目前,我的程序只是在一个字符串中生成所有长度为 21 的可能的 siRNA,但我需要将它们与所需的 GC 或 CG 量分开。
我的程序如何使用 K = 2 的示例,这意味着来自 mRNA 的 iRNA 序列的长度:
- 输入DNA:ATGC
- 它通过用 U 替换 T 转化为 mRNA,所以我们得到:AUGC
- 根据Chargaff法则做互补链,A到U,U到A,g到C,C到G,得到:UACG
- 现在我们有了一个大的 iRNA,现在我们以所有可能的方式分裂它以获得 siRNA,所以:
所有 iRNA 组合 ['UA'、'AC'、'CG']
最后我想从中选择 C+G 核苷酸含量在 30-50% 范围内的那些。
好吧,我们只有 100 的 CG,但让我们将 K 更改为 4,并让我们使用 ATGCCGTA 作为输入。
ATCGCGTA
所有 iRNA 组合 ['UAGC'、'AGCG'、'GCGC'、'CGCA'、'GCAU']
所以,在这里,正确的是 - UAGC 和 GCAU
import re
def converttostr(input_seq, seperator):
# Join all the strings in list
final_str = seperator.join(input_seq)
return final_str
DNA_seq = input("")
RNA_seq = DNA_seq.replace("T", "U")
N = RNA_seq
iRNA = (N.translate(str.maketrans({"A": "U", "G": "C", "U": "A", "C": "G"})))
iRNA_str = iRNA
K = 21
iRNA_comb = [iRNA[i: j] for i in range(len(iRNA_str)) for j in range(i + 1, len(iRNA_str) + 1) if len(iRNA_str[i:j]) == K]
print("All iRNA combinations", iRNA_comb)
seperator = ', '
LtS = converttostr(iRNA_comb, seperator)
print("List converted to string: ", LtS)
CG = re.split(" CG |[^a-zA-Z ]+",LtS)
print("siRNA with CG founded",CG)
我试图弄清楚这段代码的作用,但我做不到)) 你以前用另一种语言写过吗?只需指定您要接收的输入数据和输出。
Returns true 如果符合条件 (30%-50%)。然后你可以将它添加到列表或其他任何地方。
def foo(seq: str) -> bool:
"""searching for the 21 nucleotides length sequences with content of CG or GC from 30 to 50%
"""
return 30 < (seq.count("GC") * 2) / len(h) * 100 < 50
此代码查找字符串中 GC
或 CG
的组合数量,并将值在 30-50% 之间的组合过滤到输出数组。
我也打印了不同测试用例计算的百分比,供大家参考。
代码:
import regex as re
siRNAs=['GUUUCCCTTTG', 'GCTTTUGCTUT', 'GCTUGCUTGCU', 'CGTUCGUTCGU', 'GCTUCGUTCGU', 'CGCGTUUTCGU', 'GCGCTUUTGCU',
'GCGCGCGCTUUTGCU', 'GCGCGCGCCGCGCGTUUTGCU' ]
def get_count(mstring, sub1, sub2):
idxs1 = [(m.start(), m.end()) for m in re.finditer(sub1, mstring)]
idxs2 = [(m.start(), m.end()) for m in re.finditer(sub2, mstring)]
count = len(idxs1)
for i2 in idxs2:
if any([i1[0] <= i2[0] < i1[1] for i1 in idxs1]):
continue
count+=1
return count
for x in siRNAs:
print('siRNA: ', x, ' percentage: ',((get_count(x, "GC", "CG")) * 2) / len(x) * 100, '%')
output = [x for x in siRNAs if 30 <= ((get_count(x, "GC", "CG")) * 2) / len(x) * 100 <=50]
print('output: ', output)
输入:
['GUUUCCCTTTG', 'GCTTTUGCTUT', 'GCTUGCUTGCU', 'CGTUCGUTCGU', 'GCTUCGUTCGU', 'CGCGTUUTCGU', 'GCGCTUUTGCU', 'GCGCGCGCTUUTGCU', 'GCGCGCGCCGCGCGTUUTGCU']
输出:
siRNA: GUUUCCCTTTG percentage: 0.0 %
siRNA: GCTTTUGCTUT percentage: 36.36363636363637 %
siRNA: GCTUGCUTGCU percentage: 54.54545454545454 %
siRNA: CGTUCGUTCGU percentage: 54.54545454545454 %
siRNA: GCTUCGUTCGU percentage: 54.54545454545454 %
siRNA: CGCGTUUTCGU percentage: 54.54545454545454 %
siRNA: GCGCTUUTGCU percentage: 54.54545454545454 %
siRNA: GCGCGCGCTUUTGCU percentage: 66.66666666666666 %
siRNA: GCGCGCGCCGCGCGTUUTGCU percentage: 76.19047619047619 %
output: ['GCTTTUGCTUT']
DNA_seq = input("")
RNA_seq = DNA_seq.replace("T", "U")
N = RNA_seq
iRNA = (N.translate(str.maketrans({"A": "U", "G": "C", "U": "A", "C": "G"})))
iRNA_str = iRNA
K = 4
iRNA_comb = [iRNA[i: j] for i in range(len(iRNA_str)) for j in range(i + 1, len(iRNA_str) + 1) if len(iRNA_str[i:j]) == K]
print("All iRNA combinations", iRNA_comb)
siRNAs = iRNA_comb
for x in siRNAs:
print('siRNA: ', x, ' percentage: ',((x.count("C") + x.count("G"))) / len(x) * 100, '%')
output = [x for x in siRNAs if 30 <= ((x.count("C") + x.count("G"))) / len(x) * 100 <=50]
print('output: ', output)
我正在尝试编写用于查找 siRNA 的代码。现在,我编写了一个代码,用于查找所有可能的 siRNA 组合。我还需要找到最好的,必须包含 30% 到 50% 的 GC 或 CG 核苷酸。
本程序正在寻找CG或GC含量在30%到50%之间的21个核苷酸长度的序列。目前,我的程序只是在一个字符串中生成所有长度为 21 的可能的 siRNA,但我需要将它们与所需的 GC 或 CG 量分开。
我的程序如何使用 K = 2 的示例,这意味着来自 mRNA 的 iRNA 序列的长度:
- 输入DNA:ATGC
- 它通过用 U 替换 T 转化为 mRNA,所以我们得到:AUGC
- 根据Chargaff法则做互补链,A到U,U到A,g到C,C到G,得到:UACG
- 现在我们有了一个大的 iRNA,现在我们以所有可能的方式分裂它以获得 siRNA,所以: 所有 iRNA 组合 ['UA'、'AC'、'CG']
最后我想从中选择 C+G 核苷酸含量在 30-50% 范围内的那些。
好吧,我们只有 100 的 CG,但让我们将 K 更改为 4,并让我们使用 ATGCCGTA 作为输入。
ATCGCGTA 所有 iRNA 组合 ['UAGC'、'AGCG'、'GCGC'、'CGCA'、'GCAU']
所以,在这里,正确的是 - UAGC 和 GCAU
import re
def converttostr(input_seq, seperator):
# Join all the strings in list
final_str = seperator.join(input_seq)
return final_str
DNA_seq = input("")
RNA_seq = DNA_seq.replace("T", "U")
N = RNA_seq
iRNA = (N.translate(str.maketrans({"A": "U", "G": "C", "U": "A", "C": "G"})))
iRNA_str = iRNA
K = 21
iRNA_comb = [iRNA[i: j] for i in range(len(iRNA_str)) for j in range(i + 1, len(iRNA_str) + 1) if len(iRNA_str[i:j]) == K]
print("All iRNA combinations", iRNA_comb)
seperator = ', '
LtS = converttostr(iRNA_comb, seperator)
print("List converted to string: ", LtS)
CG = re.split(" CG |[^a-zA-Z ]+",LtS)
print("siRNA with CG founded",CG)
我试图弄清楚这段代码的作用,但我做不到)) 你以前用另一种语言写过吗?只需指定您要接收的输入数据和输出。
Returns true 如果符合条件 (30%-50%)。然后你可以将它添加到列表或其他任何地方。
def foo(seq: str) -> bool:
"""searching for the 21 nucleotides length sequences with content of CG or GC from 30 to 50%
"""
return 30 < (seq.count("GC") * 2) / len(h) * 100 < 50
此代码查找字符串中 GC
或 CG
的组合数量,并将值在 30-50% 之间的组合过滤到输出数组。
我也打印了不同测试用例计算的百分比,供大家参考。
代码:
import regex as re
siRNAs=['GUUUCCCTTTG', 'GCTTTUGCTUT', 'GCTUGCUTGCU', 'CGTUCGUTCGU', 'GCTUCGUTCGU', 'CGCGTUUTCGU', 'GCGCTUUTGCU',
'GCGCGCGCTUUTGCU', 'GCGCGCGCCGCGCGTUUTGCU' ]
def get_count(mstring, sub1, sub2):
idxs1 = [(m.start(), m.end()) for m in re.finditer(sub1, mstring)]
idxs2 = [(m.start(), m.end()) for m in re.finditer(sub2, mstring)]
count = len(idxs1)
for i2 in idxs2:
if any([i1[0] <= i2[0] < i1[1] for i1 in idxs1]):
continue
count+=1
return count
for x in siRNAs:
print('siRNA: ', x, ' percentage: ',((get_count(x, "GC", "CG")) * 2) / len(x) * 100, '%')
output = [x for x in siRNAs if 30 <= ((get_count(x, "GC", "CG")) * 2) / len(x) * 100 <=50]
print('output: ', output)
输入:
['GUUUCCCTTTG', 'GCTTTUGCTUT', 'GCTUGCUTGCU', 'CGTUCGUTCGU', 'GCTUCGUTCGU', 'CGCGTUUTCGU', 'GCGCTUUTGCU', 'GCGCGCGCTUUTGCU', 'GCGCGCGCCGCGCGTUUTGCU']
输出:
siRNA: GUUUCCCTTTG percentage: 0.0 %
siRNA: GCTTTUGCTUT percentage: 36.36363636363637 %
siRNA: GCTUGCUTGCU percentage: 54.54545454545454 %
siRNA: CGTUCGUTCGU percentage: 54.54545454545454 %
siRNA: GCTUCGUTCGU percentage: 54.54545454545454 %
siRNA: CGCGTUUTCGU percentage: 54.54545454545454 %
siRNA: GCGCTUUTGCU percentage: 54.54545454545454 %
siRNA: GCGCGCGCTUUTGCU percentage: 66.66666666666666 %
siRNA: GCGCGCGCCGCGCGTUUTGCU percentage: 76.19047619047619 %
output: ['GCTTTUGCTUT']
DNA_seq = input("")
RNA_seq = DNA_seq.replace("T", "U")
N = RNA_seq
iRNA = (N.translate(str.maketrans({"A": "U", "G": "C", "U": "A", "C": "G"})))
iRNA_str = iRNA
K = 4
iRNA_comb = [iRNA[i: j] for i in range(len(iRNA_str)) for j in range(i + 1, len(iRNA_str) + 1) if len(iRNA_str[i:j]) == K]
print("All iRNA combinations", iRNA_comb)
siRNAs = iRNA_comb
for x in siRNAs:
print('siRNA: ', x, ' percentage: ',((x.count("C") + x.count("G"))) / len(x) * 100, '%')
output = [x for x in siRNAs if 30 <= ((x.count("C") + x.count("G"))) / len(x) * 100 <=50]
print('output: ', output)