我有一个包含以下数据的txt文件:
CHRI
ATGCCTTGGGCAACGGT ......(多行)
chrII
AGGTTGGCCAAGGTT ...(多行)
我想首先找到'chrI',然后遍历ATGC的多行,直到找到第x个字符。然后我想打印第x个字符,直到第y个字符。我一直在使用正则表达式,但一旦我找到包含chrI的行,我不知道如何继续迭代以找到第x个字符。
这是我的代码:
for i, line in enumerate(sacc_gff):
for match in re.finditer(chromo_val, line):
print(line)
for match in re.finditer(r"[ATGC]{%d},{%d}\Z" % (int(amino_start), int(amino_end)), line):
print(match.group())
变量意味着什么:
chromo_val
= chrI
amino_start
=(我的程序找到了一些起点)
amino_end
=(我的程序找到了一些终点)
注意:amino_start
和amino_end
需要采用变量形式。
如果我能为你澄清任何事情,请告诉我,谢谢。
答案 0 :(得分:3)
看起来你正在处理fasta数据,所以我会提供一个答案,但如果它不是你可以使用sub_sequence选择部分。
fasta_data = {} # creates an empty dictionary
with open( fasta_file, 'r' ) as fh:
for line in fh:
if line[0] == '>':
seq_id = line.rstrip()[1:] # strip newline character and remove leading '>' character
fasta_data[seq_id] = ''
else:
fasta_data[seq_id] += line.rstrip()
# return substring from chromosome 'chrI' with a first character at amino_start up to but not including amino_end
sequence_string1 = fasta_data['chrI'][amino_start:amino_end]
# return substring from chromosome 'chrII' with a first character at amino_start up to and including amino_end
sequence_string2 = fasta_data['chrII'][amino_start:amino_end+1]
fasta格式:
>chr1
ATTTATATATAT
ATGGCGCGATCG
>chr2
AATCGCTGCTGC
答案 1 :(得分:0)
由于您正在使用格式如下的fasta文件:
<receiver android:name=".GeofenceReceiver" android:exported="false">
<intent-filter>
<action android:name="com.geofence.georeceiver"/>
</intent-filter>
</receiver>
并且是生物信息学专业我猜您将经常操作序列我建议安装名为FAST的perl包。一旦安装它以获得每个序列的2-14个字符,您将执行此操作:
>Chr1
ATCGACTACAAATTT
>Chr2
ACCTGCCGTAAAAATTTCC
这是最近的publication for FAST和github,其中包含用于在命令行上操作分子序列数据的完整工具箱。