我有一个基因列表,我需要确定列表中的基因是否出现在“文章标题”中,如果出现,请找出基因在句子中的起始和结束位置。你知道吗
开发的代码确实能识别基因并检测基因在句子中的位置。但是,我需要帮助找到基因的起始位置和终止位置
doc = tree.getroot()
for ArticleTitle in doc.iter('ArticleTitle'):
file1 = (ET.tostring(ArticleTitle, encoding='utf8').decode('utf8'))
filename = file1[52:(len(file1))]
Article= filename.split("<")[0]
# print(Article)
# print(type(Article))
title= Article.split()
gene_list = ["ABCD1","ADA","ALDOB","APC","ARSB","ATAD3B","AXIN2","BLM","BMPR1A","BRAF","BRCA1"]
for item in title:
for item1 in gene_list:
if item == item1:
str_title= ' '.join(title)
print(str_title)
print("Gene Found: " + item)
index= title.index(item)
print("Index of the Gene :" +str(index))
result = 0
for char in str_title:
result +=1
print(result)
电流输出为:
Healthy people 2000: a call to action for ADA members.
Gene Found: ADA
Index of the Gene :8
54
预期输出为:
Healthy people 2000: a call to action for ADA members.
Gene Found: ADA
Index of the Gene :8
Gene start position: 42
Gene End postion: 45
开始和结束位置也应该计算单词之间的空格。你知道吗
我可以用正则表达式
输出
在字符串中没有实际位置的较短解可以是
我们也可以使用Flashtext
相关问题 更多 >
编程相关推荐