Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python进行DNA测序_Python_Substring_Longest Substring - Fatal编程技术网

使用python进行DNA测序

使用python进行DNA测序,python,substring,longest-substring,Python,Substring,Longest Substring,使用循环,我如何用python编写一个函数,对最长的蛋白质链进行排序,而不考虑顺序。当ties与其他元素混合时,函数返回仅由字符“a”、“C”、“G”和“T”组成的子字符串:例如,在序列“accgxxcxgtactgggcxttgt”中,它返回“gtactgggc”如果数据作为字符串提供,您可以简单地将其按字符“X”拆分,从而获得一个列表 startstring = 'ACCGXXCXXGTTACTGGGCXTTGT' array = startstring.split('X') 然后在检查元

使用循环,我如何用python编写一个函数,对最长的蛋白质链进行排序,而不考虑顺序。当ties与其他元素混合时,函数返回仅由字符“a”、“C”、“G”和“T”组成的子字符串:例如,在序列“accgxxcxgtactgggcxttgt”中,它返回“gtactgggc”

如果数据作为字符串提供,您可以简单地将其按字符“X”拆分,从而获得一个列表

startstring = 'ACCGXXCXXGTTACTGGGCXTTGT'
array = startstring.split('X')
然后在检查元素长度的同时在列表上循环,将得到正确的结果:

# Initialize placeholders for comparison
temp_max_string = ''
temp_max_length = 0

#Loop over each string in the list
for i in array:
    # Check if the current substring is longer than the longest found so far
    if len(i) > temp_max_length:
        # Replace the placeholders if it is longer
        temp_max_length = len(i)
        temp_max_string = i

print(temp_max_string) # or 'print temp_max_string' if you are using python2.
您还可以使用python内置程序以更高效的方式获得结果:

按降序长度排序(
list.sort()
) 仅获取最长的子字符串(
max()
):
只是拼写更正。澄清概念:通常a、C、T、G被称为碱基或核苷酸,而不是蛋白质。一些DNA序列转化为氨基酸链;这些是蛋白质。DNA测序是找出一个DNA序列由哪一串核苷酸组成的过程。在这一点上,这些分子没有被讨论,因为我正在试图找出一个能够对它们进行排序的代码。
startstring = 'ACCGXXCXXGTTACTGGGCXTTGT'
array = startstring.split('X')
array.sort(key=len, reverse=True)
print(array[0]) #print the longest since we sorted for descending lengths
print(len(array[0])) # Would give you the length of the longest substring
startstring = 'ACCGXXCXXGTTACTGGGCXTTGT'
array = startstring.split('X')
longest = max(array, key=len)
print(longest) # gives the longest substring
print(len(longest)) # gives you the length of the longest substring