将 smi 文件从锌转换为数据帧

问题描述 投票:0回答:1

我的项目是从锌和其他数据库中获取一些与特定激酶酶相关的化合物和小分子。我尝试了几种方法从锌数据库中的 zincid 或 pubchem id 下载微笑。它们都不起作用,现在我想使用 smi 文件,但我不知道如何像数据框一样打开它。

我的代码是

 with open(smiles_file_path, 'r') as f:
    smiles_list = f.readlines()

# Create a DataFrame from the list of SMILES strings
df = pd.DataFrame({'SMILES': smiles_list})

# Display the DataFrame
print(df)
but it doesn't show data frame properly!
python pandas bioinformatics chemistry cheminformatics
1个回答
0
投票

smi 文件是 csv 文件,第一列中包含 SMILES,第二列可选,以空格(空格或制表符)分隔。 Zinc 使用第二列作为 ID。

可以直接用pandas打开文件。

import pandas as pd

df = pd.read_csv('substances.smi', sep='\s+') # \s+ is the regex for whitespaces

df.columns = ['SMILES', 'ID']

print(df)

                                    SMILES                ID
0    N[C@H](CCc1ccc(N(CCCl)CCCl)cc1)C(=O)O  ZINC000016090786
1  N[C@@H](CCCc1ccc(N(CCCl)CCCl)cc1)C(=O)O  ZINC000002033385
2   N[C@H](CCCc1ccc(N(CCCl)CCCl)cc1)C(=O)O  ZINC000001763088
3    N[C@@H](Cc1ccc(N(CCCl)CCCl)cc1)C(=O)O  ZINC000000001673
4     N[C@H](Cc1ccc(N(CCCl)CCCl)cc1)C(=O)O  ZINC000000001661
5       CCN(CC)c1ccc(CC[C@@H](N)C(=O)O)cc1  ZINC001951410564
6        CCN(CC)c1ccc(CC[C@H](N)C(=O)O)cc1  ZINC001951410565
© www.soinside.com 2019 - 2024. All rights reserved.