我有一个以下格式的文件
OperonID GI Synonym Start End Strand Length COG_number Product
1132034 397671780 RVBD_0002 2052 3260 + 402 - DNA polymerase III subunit beta
1132034 397671781 RVBD_0003 3280 4437 + 385 - DNA replication and repair protein RecF
1132034 397671782 RVBD_0004 4434 4997 + 187 - hypothetical protein
1132035 397671783 RVBD_0005 5123 7267 + 714 - DNA gyrase subunit B
1132035 397671784 RVBD_0006 7302 9818 + 838 - DNA gyrase subunit A
1132036 397671786 RVBD_0007Ac 11421 11528 - 35 - hypothetical protein
1132036 397671787 RVBD_0007Bc 11555 11692 - 45 - hypothetical protein
1132037 397671792 RVBD_0012 14089 14877 + 262 - hypothetical protein
我知道到目前为止,我可能可以使用enumerate并拥有以下脚本
lines = open('operonmap.opr', 'r').read().splitlines()
operon_id = 1132034
start = ''
end = ''
strand = ''
for i,line in enumerate(lines):
if str(operon_id) in line:
start += line[28:33]
else:
end += line[i-1]
operonline += start
operonline += end
operonline += '\n'
然后,如果这种脚本有效,我会编辑字符串“operonline”以只包含开始-结束和串信息。不幸的是,它不起作用,但我希望你能看到我的逻辑
我希望有人能帮忙
下面是一个可能的实现
parse_file
包含以下变量:this_info
:包含与当前行相关信息的字典previous_info
:this_info
来自上一次迭代start_info
:this_info
来自新操纵子ID开头的最近一行所需的输出并不完全清楚,但调整主程序(在末尾)以以您选择的任何形式写入提取的字段
这使得:
也许试试这种逻辑?它只是有一个临时变量,跟踪您看到的最后一个操作ID,并在更改后切换开始/结束:
如果你使用熊猫,如果你想走那条路,这是很容易的
我能够将您的数据读入
pandas DataFrame
,然后删除了其他列:然后我按
OperonID
分组,并将Start
和End
和Strand
值存储为列表,并创建一个新列,其中第一个Start
和最后一个End
perOperonID
值以及唯一的Strand
值。您可以根据需要重新组织它相关问题 更多 >
编程相关推荐