2024-09-05

今天我想用Linux重新統(tǒng)計(jì)一下每對(duì)通用引物能擴(kuò)增出多少目科屬種鳥類

首先用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

# 設(shè)置你的郵箱(NCBI要求提供郵箱地址)
Entrez.email = "maha2082@163.com"

# 從Excel讀取鳥類的拉丁文名
input_file = '1cytb_list.xlsx'  # 替換Excel文件名
df = pd.read_excel(input_file, sheet_name=0)

# 創(chuàng)建一個(gè)新列來存儲(chǔ)結(jié)果
df['Order'] = ''
df['Family'] = ''
df['Genus'] = ''
df['Species'] = ''

# 定義一個(gè)函數(shù)來查詢NCBI數(shù)據(jù)庫(kù)
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 '', '', '', ''

# 遍歷每個(gè)物種進(jìn)行查詢
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服務(wù)器封禁,添加延遲

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

#在目錄中保存為classify.py,修改完文件名,直接運(yùn)行即可
python3 classify.py

生成的excel文件為:

12sbird_species_classification.xlsx
1cytbbird_species_classification.xlsx
...

將excel按目科屬種排序,補(bǔ)充空缺內(nèi)容,刪除重復(fù)物種
找到重復(fù)的步驟為:選中species列,格式,條件格式,新建規(guī)則,僅對(duì)唯一值或重復(fù)值設(shè)置格式,格式選擇顏色,點(diǎn)擊確定,再次點(diǎn)擊確定。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 用慣了Seurat計(jì)算DEGs,使用Scanpy進(jìn)行計(jì)算得到的格式會(huì)很不適應(yīng),可讀性有點(diǎn)差,因此可以使用以下函數(shù)進(jìn)...
    黃甫一閱讀 355評(píng)論 0 0
  • 張佩佩工作日志9.4 一天中的小感動(dòng) 今天又是充實(shí)的一天,上午兩節(jié)課下午兩節(jié)課,在充實(shí)的工作中也有一些小小的感動(dòng)。...
    e1c686100e9f閱讀 67評(píng)論 0 0
  • 我終于知道清醒做夢(mèng)的感覺了。昨晚睡得很好,照例10點(diǎn)鐘上床,絮絮叨叨的說著自己的感受和困擾,11點(diǎn)左右入睡,有藥的...
    姜呈閱讀 130評(píng)論 0 1
  • 2024.9.4今日感悟:每個(gè)時(shí)間段都要努力做應(yīng)該做的事情,這些事情可能是非常的簡(jiǎn)單,但是每天都要重復(fù)。這個(gè)時(shí)候,...
    我命由我不由天CYZ閱讀 122評(píng)論 0 0
  • 閱讀麥家的《人生海海》,于我,最開始是有點(diǎn)不夠吸引我的,但因?yàn)楹芏嗟耐扑],我堅(jiān)持讀了下去,越讀,內(nèi)心的思緒不斷飛起...
    忙得慢兒閱讀 105評(píng)論 0 0

友情鏈接更多精彩內(nèi)容