<jupyter_start><jupyter_text>Obtain BLAST results as .xml's  Import packages<jupyter_code>import math
import os
import requests

from Bio.Blast import NCBIWWW
from Bio.Blast import NCBIXML
import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Upload ENTREZID's and Log2FC's for each of 3 organisms<jupyter_code>#Upload from .txt files in this folder
#First column is ENTREZID, second column log2FC(Earth v Space), third column is adj. p value (Earth v Space)
dna_poly001 = np.loadtxt('dna_poly001.txt', skiprows=1)
dna_poly002 = np.loadtxt('dna_poly002.txt', skiprows=1)
dna_poly004 = np.loadtxt('dna_poly004.txt', skiprows=1)<jupyter_output><empty_output><jupyter_text>Function to BLAST an EID<jupyter_code>def blast_eid_in_pdb(ENTREZID, save_file_xml):
    """
    Function: Take EID, BLAST in a the NCBI PDB
    ENTREZID: ENTREZID from 001.csv as added to bioproject_df, float
    save_file_xml: file to save to as ncbidb_index.xml, string
    eid_index: index of the ENTREZID, float
    ncbi_database: the NCBI database to be used for BLASTing, string
    """
    eid = ENTREZID
    result_handle = NCBIWWW.qblast('blastp', 'pdb', eid)
    with open(save_file_xml, 'w+') as save_to:
        save_to.write(result_handle.read())
        result_handle.close()<jupyter_output><empty_output><jupyter_text>Make file names to save results into (.xml)<jupyter_code>xml_names001 = ['dna001_1.xml', 'dna001_2.xml', 'dna001_3.xml', 'dna001_4.xml', 'dna001_5.xml', 'dna001_6.xml', 'dna001_7.xml', 'dna001_8.xml', 'dna001_9.xml', 'dna001_10.xml', 'dna001_11.xml', 'dna001_12.xml']
xml_names002 = ['dna002_1.xml', 'dna002_2.xml', 'dna002_3.xml', 'dna002_4.xml', 'dna002_5.xml', 'dna002_6.xml', 'dna002_7.xml', 'dna002_8.xml', 'dna002_9.xml', 'dna002_10.xml', 'dna002_11.xml', 'dna002_12.xml', 'dna002_13.xml', 'dna002_14.xml']
xml_names004 = ['dna004_1.xml', 'dna004_2.xml']<jupyter_output><empty_output><jupyter_text>For all of the EID's, do the BLAST.  WARNING: TAKES A LONG TIME<jupyter_code>#Iterate through EID's in dna_poly001 and use BLAST function for NCBI PDB
for i in range(len(dna_poly001)):
    ENTREZID = int(dna_poly001[i,0]) #make eid an integer
    save_file_xml = xml_names001[i] #define name to save BLAST hits to as .xml
    blast_eid_in_pdb(ENTREZID, save_file_xml)

#Iterate through EID's in dna_poly002
for i in range(len(dna_poly002)):
    ENTREZID = int(dna_poly002[i,0]) #make eid an integer
    save_file_xml = xml_names002[i] #define name to save BLAST hits to as .xml
    blast_eid_in_pdb(ENTREZID, save_file_xml)

#Iterate through EID's in dna_poly004
for i in range(len(dna_poly002)):
    ENTREZID = int(dna_poly002[i,0]) #make eid an integer
    save_file_xml = xml_names002[i] #define name to save BLAST hits to as .xml
    blast_eid_in_pdb(ENTREZID, save_file_xml)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11423550087873462, 'fraction_numerical': 0.06854130052724078, 'mean_word_length': 5.587962962962963, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 49}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '562016', 'license': 'MIT', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1147, 'n_words': 269, 'path': 'notebooks/BLAST_get_xml.ipynb', 'repo_name': 'UWInSpace/InSpace', 'size': '2845'}