【发布时间】:2021-04-29 01:23:07
【问题描述】:
代码/程序:
# 1. Represent all unique feature types (column 2).
lines = f.read().split('\n')
# Set features
unique_features = set((i.split('\t')[1]) for i in lines)
unique_features = sorted(unique_features)
qty_features = [str(i.split('\t')[1]) for i in lines]
for feature in unique_features:
print(feature, qty_features.count(feature))
# 2. For every feature type (column 2) it stores all feature names (column 4) that had that type.
# Create a list of types and names
types = list(unique_features)
names = list([str(i.split('\t')[3]) for i in lines])
data = dict()
for i in range(len(types)):
data[types[i]] = names[i]
print(data)
评论后的代码有问题:
"# 2. Demonstrate the use of a data structure that associates the feature names to feature types".
我正在尝试获取与第 2 列关联的文件的第 4 列中的数据。
期望的输出:
对于每个功能类型(第 2 列),我想获取与功能类型相关联的所有功能名称(第 4 列)。
{'ORF': ['YAL069W', 'YAL068W-A', 'YAL068C', 'YAL067W-A' ... ] }
{'CDS': ['YAL068W-A', 'YAL068C', 'YAL067W-A', 'YAL067C' ... ] }
还有第 2 列中的所有唯一值:
(ARS
ARS_consensus_sequence
CDS
LTR_retrotransposon
ORF
W_region
X_element
X_element_combinatorial_repeat
X_region
Y_prime_element
Y_region
Z1_region
...
etc etc)
属于它们的第 4 列的每个值都存储在它们中,就像对它们进行分类一样...
我得到的代码是
{'ARS': 'YAL069W', 'ARS_consensus_sequence': '', 'CDS': 'YAL068W-A', 'LTR_retrotransposon': '', 'ORF': 'ARS102', 'W_region': 'TEL01L', 'X_element': '', 'X_element_combinatorial_repeat': '', 'X_region': '', 'Y_prime_element': 'YAL068C', 'Y_region': '', 'Z1_region': 'YAL067W-A', 'Z2_region': '', 'blocked_reading_frame': 'ARS103', 'centromere': 'YAL067C', 'centromere_DNA_Element_I': '', 'centromere_DNA_Element_II': 'YAL066W', 'centromere_DNA_Element_III': '', 'external_transcribed_spacer_region': 'YAL065C', 'five_prime_UTR_intron': '', 'gene_group': 'YAL064W-B', 'intein_encoding_region': '', 'internal_transcribed_spacer_region': 'YAL064C-A', 'intron': '', 'long_terminal_repeat': 'YAL064W', 'mating_type_region': '', 'matrix_attachment_site': 'YALWdelta1', 'ncRNA_gene': 'YAL063C-A', 'non_transcribed_region': '', 'noncoding_exon': 'YAL063C', 'not in systematic sequence of S288C': '', 'not physically mapped': 'ARS104', 'origin_of_replication': '', 'plus_1_translational_frameshift': 'YAL062W', 'pseudogene': '', 'rRNA_gene': 'YAL061W', 'silent_mating_type_cassette_array': '', 'snRNA_gene': 'YAL060W', 'snoRNA_gene': '', 'tRNA_gene': 'YAL059W', 'telomerase_RNA_gene': '', 'telomere': 'YAL059C-A', 'telomeric_repeat': '', 'transposable_element_gene': 'YAL058W'}
在该输出中,它打印的是已经设置的 'unique_features',但特征名称与它不对应,它甚至没有打印它们。
EG。文件:
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
【问题讨论】:
标签: python list dictionary multiple-columns