에서 파이썬 목록 항목 :분할 나는라는 목록이 사용자 정의 인덱스
FirstSequenceToSplit
을하고 DNA 서열이 하나 개의 항목을 포함하고 말 :
'ATTTTACGTA'
이 항목의 길이를 쉽게 반환 할 수 있으므로 사용자는 길이가 10 자임을 알고 있으므로 사용자가 원하는 인덱스의 문자 [0 : 6]을 추출하려고합니다. , 그런 다음 새 목록에 두 개의 항목을 생성합니다. 첫 번째 항목은 사용자 정의 색인의 문자 다음에 추출되지 않은 다른 문자를 대체하는 물음표 뒤에 있고 두 번째 항목은 역수를 갖습니다. [: 5 0] 다음 항목과 당신이 얻을하는 새로운 목록 :
그래서 사용자가 그들이 원하는 것을하면 내가 원하는 것을 설명하기
[ 'ATTTT ?????', '을? [ACGTA ']
이것은 내가 FASTA 형식 ('> Sequence1/nATTTTACGTA ','> Sequence2/nATTGCACGTA '등)의 DNA 서열 세트를 가지고있는 훨씬 더 큰 문제의 일부입니다. 사용자는 그 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)
코드가 있습니까? – najjarammar
안녕하세요, 내 게시물의 주요 질문에 집중하고 싶었지만 지금까지 한 일을 보여주기 위해 편집했습니다. 최근 사과를 코딩하기 시작한 이래로 매우 오랜 바람을 피웠습니다. ! – PaulBarr