Error pops up while trying to download fasta files using the Biopython module

Viewed 26

I have been working on a project that requires analysis of chromosomes of a large number of animals. I have written code in python that does the following tasks:

  1. Download the genomic table into a csv/.xlsx file using BeautifulSoup class, fromhttps://www.ncbi.nlm.nih.gov/genome/?term=gorilla+gorilla+gorilla

  2. Iterate through each NCBI id and download the chromosomal DNA sequence using Biopython. Each chromosome amounts to ~200MB in size.

The problem I face is that, after downloading the first couple of sequences in .fasta format, the following error pops up: This picture shows the error that pops up

I have attached the entire python code at:https://github.com/Vijithkumar2020/Entry_Form/blob/master/NCBI_Whole_Genome_downloadfile

#The code snippet that specifically downloads the fasta files is here:

path_fasta_final=os.path.join(path_, name)
     
for chrm, ids in dict2.items():


    if os.path.exists(path_fasta_final):

        """dict2 contains chromosome ids as keys and ncbi ids as values"""
        """register ncbi with email ids"""
        Entrez.email="vijithkumar7@gmail.com"



        """use efetch function of the Entrez class to download the fasta file"""

        fasta_file=Entrez.efetch(db='nucleotide', id=ids, retmode='text', rettype='fasta')

        filename=chrm+".fasta"
        print(filename)
        print(path_fasta_final)

        file_path_fasta=os.path.join(path_fasta_final, filename)

        if os.path.isfile(file_path_fasta):

            pass

        else:
        

            fasta_write=open(file_path_fasta, 'w')

            fasta_write.write(fasta_file.read())

            fasta_write.close()
            fasta_file.close()

    else:

        os.makedirs(path_fasta_final)

        

        """dict2 contains chromosome ids as keys and ncbi ids as values"""
        """register ncbi with email ids"""
        Entrez.email="vijithkumar7@gmail.com"



        """use efetch function of the Entrez class to download the fasta file"""

        fasta_file=Entrez.efetch(db='nucleotide', id=ids, retmode='text', rettype='fasta')

        filename=chrm+".fasta"
        print(filename)
        print(path_fasta_final)

        file_path_fasta=os.path.join(path_fasta_final, filename)

        if os.path.isfile(file_path_fasta):

            pass

        else:
        

            fasta_write=open(file_path_fasta, 'w')

            fasta_write.write(fasta_file.read())

            fasta_write.close()
            fasta_file.close()
0 Answers
Related