eggnog.db是一个sqlite数据库

它含有这么些表格:

- event
- og
- version
- prots

可以用这个代码看看表格的前几行

import sqlite3

conn = sqlite3.connect('eggnog.db')
cursor = conn.cursor()

# 要查看的表名
table_name = "og"  # 替换为你感兴趣的表名

print(f"\n表 {table_name} 的样本数据:")

# 获取列名
cursor.execute(f"PRAGMA table_info({table_name});")
columns = [column[1] for column in cursor.fetchall()]
print(" | ".join(columns))
print("-" * 100)

# 查询前几行
cursor.execute(f"SELECT * FROM {table_name} LIMIT 5;")
rows = cursor.fetchall()

# 打印数据
for row in rows:
    print(" | ".join([str(cell)[:50] for cell in row]))  # 限制每个字段最大长度为50

conn.close()

event表含有这些列

导出prots表格的文件

import sqlite3

# 连接数据库
conn = sqlite3.connect('eggnog.db')
cursor = conn.cursor()

# 查询 prots 表的所有数据
cursor.execute("SELECT * FROM prots;")
rows = cursor.fetchall()

# 获取表的列名
cursor.execute("PRAGMA table_info(prots);")
columns = cursor.fetchall()
column_names = [col[1] for col in columns]  # 提取列名

# 将数据写入 annotation.TSV 文件
with open('annotation.tsv', 'w', encoding='utf-8') as tsv_file:
    # 写入表头
    tsv_file.write('\t'.join(column_names) + '\n')
    # 写入表数据
    for row in rows:
        tsv_file.write('\t'.join(map(str, row)) + '\n')

# 关闭数据库连接
conn.close()

print("数据已成功导出到 annotation.tsv")

导出的表长这样,大小大概有11.3G

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐