<jupyter_start><jupyter_text>Downloading and parsing GenBank files from Python Installation1. Fork git repo into local machine (click on fork) and clone, or simply clone main branch with```git clone https://github.com/Robaina/GenBankpy.git```2. CD to project directory and set conda environment if not already set:```conda env create -n ncbi -f environment.yml```3. Activate environment:```conda activate ncbi```<jupyter_code># conda activate ncbi
from genbankpy.parser import GenBankFastaWriter, GBK

"""
This package requires:

pip install ncbi-acc-download
"""

# First we need to define the NCBI entry ids to download the data
entry_ids = [
    'AE001863.1',
    'AF000579.1',
    'AF242489.1', 
    'AP003593.1', 
    'NC_000911.1',
    'NC_007288.1'
]
gbkwriter = GenBankFastaWriter.fromAccessionIDs(entry_ids=entry_ids)
# gbkwriter = GenBankFastaWriter.fromGBKdirectory('gbk_data')
# Write fasta containing all peptide sequences of these two organisms
gbkwriter.writeSequencesInFasta(
    gene_keywords={'product': ['any']},
    output_fasta='results/allPeptides.faa', 
    sequence='protein',
    entry_ids=['AE001863.1', 'AP003593.1']
)

# Write fasta containing all nucleotide sequences of these two organisms
gbkwriter.writeSequencesInFasta(
    gene_keywords={'product': ['any']},
    output_fasta='results/allNucleotides.fasta', 
    sequence='nucleotide',
    entry_ids=['AE001863.1', 'AP003593.1']
)

# Write fasta containing nucleotide sequences of the two organisms corresponding to Urease alpha
gbkwriter.writeSequencesInFasta(
    gene_keywords={'product': ['urease', 'alpha']},
    output_fasta='results/ureC.fasta', 
    sequence='nucleotide'
)

# Write fasta containing peptide sequences of the two organisms corresponding to Urease alpha
gbkwriter.writeSequencesInFasta(
    gene_keywords={'product': ['urease', 'alpha']},
    output_fasta='results/ureC.faa', 
    sequence='protein',
    entry_ids=['AE001863.1', 'AP003593.1']
)

# Write fasta containing nucleotide sequences of all five corresponding to 16S
gbkwriter.writeSequencesInFasta(
    gene_keywords={'product': ['16S']},
    output_fasta='results/16s.fasta', 
    sequence='nucleotide',
    entry_ids=None
)<jupyter_output><empty_output><jupyter_text>Initializing from list of species names Checking if there are available genomes to download before actually downloading them, thus avoiding consequent error messages:<jupyter_code>from genbankpy.parser import GenBankFastaWriter, GBK
available_genomes = GenBankFastaWriter.listNCBIfilesToDownload('Marinobacter nauticus')

print(available_genomes)
sp_list = ['Marinobacter nauticus']


gbkwriter = GenBankFastaWriter.fromSpecies(species_list=sp_list,
                                           only_representatives=True,
                                           data_dir='marino_data')

gbkwriter.writeSequencesInFasta(
    gene_keywords={'product': ['any']},
    output_fasta='results/allPeptidesMarino.faa', 
    sequence='protein'
)
sp_list = ['Emiliania huxleyi']

gbkwriter = GenBankFastaWriter.fromSpecies(species_list=sp_list,
                                           only_representatives=True)

gbkwriter.writeSequencesInFasta(
    gene_keywords={'product': ['any']},
    output_fasta='results/allPeptidesEmiliania.faa', 
    sequence='protein'
)<jupyter_output>Initializing parser...pecies: Emiliania huxleyi (1 / 1)
Done!<jupyter_text>Parsing GenBank files<jupyter_code>gbk = GBK('gbk_data/AE001863.1.gbk')
gbk.cds.get_by_gene_id('DRA0303')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10798522307473714, 'fraction_numerical': 0.030122193805058255, 'mean_word_length': 4.799011532125206, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '483965', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1108, 'n_words': 243, 'path': 'README.ipynb', 'repo_name': 'Robaina/GenBankpy', 'size': '3519'}