【发布时间】:2014-05-24 14:35:51
【问题描述】:
我有一个名为:
FirstSequenceToSplit
它包含一个项目,即 DNA 序列:
'ATTTTACGTA'
我可以很容易地返回这个项目的长度,所以用户知道它是 10 个字符长,然后我想做的是让用户说他们想要提取索引的字符说 [0:6 ],然后在新列表中生成两个项目。第一项具有用户定义索引的字符,后跟一个问号替换未提取的其他字符,第二项具有相反的字符。
所以为了说明我想要什么,如果用户说他们想要 [0:5],你会得到一个包含以下项目的新列表:
['ATTTT?????','?????ACGTA']
这是一个更大问题的一部分,我有一组 FASTA 格式的 DNA 序列('>Sequence1/nATTTTACGTA'、'>Sequence2/nATTGCACGTA' 等),我希望用户能够选择一个序列基于其 ID,并且该序列基于预定义的输入进行拆分,并被称为 Sequence2a 和 Sequence2b ('>Sequence1a/n?????ACGTA', '>Sequence1b/nATTTT?????'' >Sequence2/nATTGCACGTA' 等)。我目前已经通过打印序列的名称解决了这个问题,让用户选择一个来拼接,只提取序列(没有 ID),然后一旦我解决了上面显示的问题,我将创建一个包含新项目的新列表。
由于我是初学者(我确信现在很明显!)我将不胜感激任何给出的代码解释。非常感谢您提供任何可能的帮助
到目前为止我的代码是:
import sys
import re
#Creating format so more user friendly
class color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[94m'
UNDERLINE = '\033[4m'
END = '\033[0m'
fileName = raw_input("Give the name of the Fasta file you wish to divide up ")
# i.e TopTenFasta
#Reading in the sequences splitting them by the > symbol
in_file = open(fileName,"r")
sequences = in_file.read().split('>')[1:]
in_file.close()
#Putting all these sequences into a list
allSequences = []
for item in sequences:
allSequences.append(item)
#Letting you know how many sequences there are in total
NumberOfSequences = len(allSequences)
print color.BOLD + "The Number of Sequences in this list is: " +color.END, NumberOfSequences
#Returning the names of the IDs to allow you to decide which ones to split
SequenceIds = []
for x in allSequences:
SequenceIds.append(x[0:10])
print color.BOLD + "With the following names: " + color.END, "\n", "\n".join(SequenceIds)
#-----------------------Starting the Splice ------------------------------------
#-----------------------------------------------------------------------------
#------------------------------------------------------------------------------
#Choosing the sequence you wish to splice
FirstSequenceToSplitID = raw_input(color.BOLD + "Which sequence would you like to splice " + color.END)
#Seeing whether that item is in the list
for x in SequenceIds:
if FirstSequenceToSplitID == x:
print "valid input"
FirstSequenceToSplit = []
#making a new list (FirstSequenceToSplit) and putting into it just the sequence (no ID)
for listItem in allSequences:
if listItem[0:10]==FirstSequenceToSplitID:
FirstSequenceToSplit.append(listItem[11:])
#Printing the Length of the sequence to splice
for element in FirstSequenceToSplit:
print color.BOLD + "The Length of this sequence is" + color.END, len(element)
【问题讨论】:
-
嗨,我没有包含我的代码,因为我想专注于我的帖子的主要问题,但我已经编辑了它以显示我到目前为止所做的事情,它可能很长,因为我最近才开始编码,非常抱歉!
标签: python list splice fasta dna-sequence