【发布时间】:2021-07-20 08:31:42
【问题描述】:
我正在尝试从选项卡中获取列的唯一值。这些值是重复的,文件有 1,000 多行,我只想拥有值的名称,而不是全部,以及重复的那些。我正在处理我的代码,但是当我执行“RUN”时,它会生成值的单独和随机字母(参见下面“输出”中的示例)。我希望有人能帮我找出我的错误。请非常感谢!
代码:
# Open file
file = open('SGD_features.tab')
# Demonstrate the use of a data structure to represent all unique feature types (column 2).
# Iterate for just one iteration
for line in file:
# Get rid of new lines at the end.
line = line.strip()
# File is tab-delimited.
elems = line.split("\t")
features = elems[1]
unique_list = str(set(features))
print(unique_list)
输出:
{'O', 'F', 'R'}
{'S', 'C', 'D'}
{'O', 'F', 'R'}
{'S', 'C', 'D'}
{'S', 'A', 'R'}
{'e', 'l', 'o', 'm', 'r', 't'}
{'e', 'l', 'i', 'p', 'a', 'o', 'm', 'r', '_', 't', 'c'}
{'X', 'e', 'l', 'm', '_', 't', 'n'}
{'X', 'e', 'b', 'l', 'i', 'p', 'a', 'o', 'm', 'r', '_', 't', 'c', 'n'}
{'O', 'F', 'R'}
{'S', 'C', 'D'}
{'O', 'F', 'R'}
{'S', 'C', 'D'}
等等……
期望的输出:
ORF
CDS
ARS
telomere
telomeric_repeat
X_element
X_element_combinatorial_repeat
前。文件
S000036595 noncoding_exon snR18 1 142367 142468 W 2011-02-03 2000-05-19|2007-05-08
S000000002 ORF Verified YAL002W VPS8 CORVET complex membrane-binding subunit VPS8|VPL8|VPT8|FUN15 chromosome 1 L000003013 1 143707 147531 W 2011-02-03 2004-01-14|1996-07-31 Membrane-binding component of the CORVET complex; involved in endosomal vesicle tethering and fusion in the endosome to vacuole protein targeting pathway; interacts with Vps21p; contains RING finger motif
S000031737 CDS YAL002W 1 143707 147531 W 2011-02-03 2004-01-14|1996-07-31
S000121255 ARS ARS108 ARSI-147 chromosome 1 1 147398 147717 2014-11-18 2014-11-18|2007-03-07 Autonomously Replicating Sequence
S000000001 ORF Verified YAL001C TFC3 transcription factor TFIIIC subunit TFC3|tau 138|TSV115|FUN24 chromosome 1 L000000641|L000002287 1 151166 147594 C -1 2011-02-03 1996-07-31 Subunit of RNA polymerase III transcription initiation factor complex; part of the TauB domain of TFIIIC that binds DNA at the BoxB promoter sites of tRNA and similar genes; cooperates with Tfc6p in DNA binding; largest of six subunits of the RNA polymerase III transcription initiation factor complex (TFIIIC)
S000030735 CDS YAL001C 1 151006 147594 C 2011-02-03 1996-07-31
S000030734 CDS YAL001C 1 151166 151097 C 2011-02-03 1996-07-31
S000030736 intron YAL001C 1 151096 151007 C 2011-02-03 1996-07-31
【问题讨论】:
-
请在您的问题中添加
SGD_features.tab文件内容的简短示例以及处理it 所需的输出。 -
您好,感谢您的帮助,我更新了我的问题。
-
好——我已经发布了答案。
标签: python unique-values