scripts/export/genomes/genome_fetch.py
def download_gca_report_file_from_url(gca_accession, dest_dir):
    """
    Loads an xml tree from a file or a string (usually an http response),
    and returns a list with the genome assembly's chromosomes

    accession: A valid ENA GCA accession (without the assembly version)
    """

    accessions = []
    root = None
    assembly_link = None
    assembly = None
    url_links = []

    assembly_xml = requests.get(ENA_XML_URL % gca_accession).content

    if os.path.isfile(assembly_xml):
        # parse xml tree and return root node
        root = ET.parse(assembly_xml).getroot()
    else:
        # fromstring returns the xml root directly
        root = ET.fromstring(assembly_xml)

    assembly = root.find("ASSEMBLY")

    if assembly is not None:
        # either parse the assembly report file or get the WGS range
        assembly_links = assembly.find("ASSEMBLY_LINKS")

        if assembly_links is not None:
            # export url link and fetch all relevant assembly accessions
            assembly_link_nodes = assembly_links.findall(
                "ASSEMBLY_LINK")

            for node in assembly_link_nodes:
                assembly_link = node.find("URL_LINK").find("URL").text
                url_links.append(assembly_link.replace("ftp:", "http:"))

            for url in url_links:
                filename = url.split('/')[-1]
                urllib.urlretrieve(url, os.path.join(dest_dir, filename))

            return True

    return False

    Loads an xml tree from a file or a string (usually an http response),
    and returns a list with the genome assembly's chromosomes

    accession: A valid ENA GCA accession (without the assembly version)
    
Loads an xml tree from a file or a string (usually an http response),
and returns a list with the genome assembly's chromosomes

A valid ENA GCA accession (without the assembly version)
Loads an xml tree from a file or a string ( usually an http response ) and returns a list with the genome assembly ' s chromosomes A valid ENA GCA accession ( without the assembly version )
def download_gca_report_file_from_url(gca_accession, dest_dir):
    accessions = []
    root = None
    assembly_link = None
    assembly = None
    url_links = []
    assembly_xml = requests.get(ENA_XML_URL % gca_accession).content
    if os.path.isfile(assembly_xml):
        root = ET.parse(assembly_xml).getroot()
    else:
        root = ET.fromstring(assembly_xml)
    assembly = root.find("ASSEMBLY")
    if assembly is not None:
        assembly_links = assembly.find("ASSEMBLY_LINKS")
        if assembly_links is not None:
            assembly_link_nodes = assembly_links.findall(
                "ASSEMBLY_LINK")
            for node in assembly_link_nodes:
                assembly_link = node.find("URL_LINK").find("URL").text
                url_links.append(assembly_link.replace("ftp:", "http:"))
            for url in url_links:
                filename = url.split('/')[-1]
                urllib.urlretrieve(url, os.path.join(dest_dir, filename))
            return True
    return False
def download_gca_report_file_from_url ( gca_accession , dest_dir ) : accessions = [ ] root = None assembly_link = None assembly = None url_links = [ ] assembly_xml = requests . get ( ENA_XML_URL % gca_accession ) . content if os . path . isfile ( assembly_xml ) : root = ET . parse ( assembly_xml ) . getroot ( ) else : root = ET . fromstring ( assembly_xml ) assembly = root . find ( "ASSEMBLY" ) if assembly is not None : assembly_links = assembly . find ( "ASSEMBLY_LINKS" ) if assembly_links is not None : assembly_link_nodes = assembly_links . findall ( "ASSEMBLY_LINK" ) for node in assembly_link_nodes : assembly_link = node . find ( "URL_LINK" ) . find ( "URL" ) . text url_links . append ( assembly_link . replace ( "ftp:" , "http:" ) ) for url in url_links : filename = url . split ( '/' ) [ - 1 ] urllib . urlretrieve ( url , os . path . join ( dest_dir , filename ) ) return True return False
Loads an xml tree from a file or a string (usually an http response),
and returns a list with the genome assembly's chromosomes
Loads an xml tree from a file or a string ( usually an http response ) and returns a list with the genome assembly ' s chromosomes
"""
    Loads an xml tree from a file or a string (usually an http response),
    and returns a list with the genome assembly's chromosomes

    accession: A valid ENA GCA accession (without the assembly version)
    """ # parse xml tree and return root node # fromstring returns the xml root directly # either parse the assembly report file or get the WGS range # export url link and fetch all relevant assembly accessions
gca_accession
dest_dir