2024-09-05

今天我想用Linux重新统计一下每对通用引物能扩增出多少目科属种鸟类

首先用excel将rtfd中所有鸟类名称筛出来,列名为NAME
分别为12sspecies_list.xlsx |1cytb_list.xlsx | 2cytbspecies_list.xlsx | co1species_list.xlsx
其中用到excel中的分列及合并
合并的公式为 =A1 & “ ” & B1

import pandas as pd
from Bio import Entrez
from time import sleep

# 设置你的邮箱(NCBI要求提供邮箱地址)
Entrez.email = "maha2082@163.com"

# 从Excel读取鸟类的拉丁文名
input_file = '1cytb_list.xlsx'  # 替换Excel文件名
df = pd.read_excel(input_file, sheet_name=0)

# 创建一个新列来存储结果
df['Order'] = ''
df['Family'] = ''
df['Genus'] = ''
df['Species'] = ''

# 定义一个函数来查询NCBI数据库
def fetch_taxonomy(name):
    try:
        handle = Entrez.esearch(db="taxonomy", term=name, retmode="xml")
        record = Entrez.read(handle)
        if record['IdList']:
            taxon_id = record['IdList'][0]
            tax_handle = Entrez.efetch(db="taxonomy", id=taxon_id, retmode="xml")
            tax_record = Entrez.read(tax_handle)
            lineage = tax_record[0]['LineageEx']
            order = family = genus = species = ''
            for item in lineage:
                rank = item.get('Rank')
                name = item.get('ScientificName')
                if rank == 'order':
                    order = name
                elif rank == 'family':
                    family = name
                elif rank == 'genus':
                    genus = name
            species = tax_record[0]['ScientificName']
            return order, family, genus, species
    except Exception as e:
        print(f"Error fetching data for {name}: {e}")
    return '', '', '', ''

# 遍历每个物种进行查询
for i, row in df.iterrows():
    species_name = row['NAME']
    print(f"Fetching data for {species_name}...")
    order, family, genus, species = fetch_taxonomy(species_name)
    df.at[i, 'Order'] = order
    df.at[i, 'Family'] = family
    df.at[i, 'Genus'] = genus
    df.at[i, 'Species'] = species
    sleep(0.5)  # 为了避免被NCBI服务器封禁,添加延迟

# 保存结果到新的Excel文件
output_file = '1cytbbird_species_classification.xlsx'#修改文件名
df.to_excel(output_file, index=False)
print(f"结果已保存到 {output_file}")

#在目录中保存为classify.py,修改完文件名,直接运行即可
python3 classify.py

生成的excel文件为:

12sbird_species_classification.xlsx
1cytbbird_species_classification.xlsx
...

将excel按目科属种排序,补充空缺内容,删除重复物种
找到重复的步骤为:选中species列,格式,条件格式,新建规则,仅对唯一值或重复值设置格式,格式选择颜色,点击确定,再次点击确定。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 袋装水稻立柱式码垛机器人 山东本森智能装备 袋装水稻立柱式码垛机器人是一种专用于袋装水稻自动化码垛的设备,它能够有...
    本森码垛机阅读 53评论 0 0
  • 用惯了Seurat计算DEGs,使用Scanpy进行计算得到的格式会很不适应,可读性有点差,因此可以使用以下函数进...
    黄甫一阅读 123评论 0 0
  • 饲料码垛全自动立柱工业机械臂 山东本森智能装备 饲料码垛全自动立柱工业机械臂(以下简称“饲料码垛机械臂”)是一种专...
    本森码垛机阅读 40评论 0 0
  • 张佩佩工作日志9.4 一天中的小感动 今天又是充实的一天,上午两节课下午两节课,在充实的工作中也有一些小小的感动。...
    e1c686100e9f阅读 46评论 0 0
  • 我终于知道清醒做梦的感觉了。昨晚睡得很好,照例10点钟上床,絮絮叨叨的说着自己的感受和困扰,11点左右入睡,有药的...
    姜呈阅读 85评论 0 1