如何读入两个制表符分隔的文件.txt并通过一个公共列将它们映射到一起。在
例如,从这两个文件创建基因到路径的映射:
第一个文件,路径.txt在
Pathway Protein
Binding and Uptake of Ligands by Scavenger Receptors P69905
Erythrocytes take up carbon dioxide and release oxygen P69905
Metabolism P69905
Amyloids P02647
Metabolism P02647
Hemostasis P68871
第二个文件,基因.txt在
^{pr2}$输出应该是
Gene Protein Pathway
Fabp3 P11404
HBA1 P69905 Binding and Uptake of Ligands by Scavenger Receptors, Erythrocytes take up carbon dioxide and release oxygen, Metabolism
APOA1 P02647 Amyloids, Metabolism
Hbb-b1 P02088
HBB P68871 Hemostasis
Hba P01942
如果没有与基于蛋白质id信息的基因基对应的通路,则留空。在
更新:
import pandas as pd
file1= pd.read_csv("gene.csv")
file2= pd.read_csv("pathway.csv")
output = pd.concat([file1,file2]).fillna(" ")
output= output[["Gene","Protein"]+list(output.columns[1:-1])]
output.to_csv("mapping of gene to pathway.csv", index=False)
所以这只给了我一个合并的文件,这不是我所期望的。在
相关问题 更多 >
编程相关推荐