scripts/export/genomes/genome_fetch.py
def extract_assembly_accs(accession):
    """
    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

    assembly_xml = requests.get(ENA_XML_URL % 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_link = assembly.find(
            "ASSEMBLY_LINKS")

        if assembly_link is not None:
            # export url link and fetch all relevant assembly accessions
            url_link = assembly_link.find(
                "ASSEMBLY_LINK").find("URL_LINK").find("URL").text

            # need to check for GCA_REP_LABEL
            accessions = assembly_report_parser(url_link, url=True)

        else:
            # no assembly link provided - look for WGS element
            wgs = None
            wgs = assembly.find("WGS_SET")
            # get wgs accession
            wgs_acc = get_wgs_set_accession(
                wgs.find("PREFIX").text, wgs.find("VERSION").text)
            # get wgs range and return as single accession
            accessions.append(get_wgs_range(wgs_acc))

    # move this outside this function to where accessions are requested ??
    else:
        accessions.append(get_wgs_range(accession))

    return accessions

    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 extract_assembly_accs(accession):
    accessions = []
    root = None
    assembly_link = None
    assembly = None
    assembly_xml = requests.get(ENA_XML_URL % 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_link = assembly.find(
            "ASSEMBLY_LINKS")
        if assembly_link is not None:
            url_link = assembly_link.find(
                "ASSEMBLY_LINK").find("URL_LINK").find("URL").text
            accessions = assembly_report_parser(url_link, url=True)
        else:
            wgs = None
            wgs = assembly.find("WGS_SET")
            wgs_acc = get_wgs_set_accession(
                wgs.find("PREFIX").text, wgs.find("VERSION").text)
            accessions.append(get_wgs_range(wgs_acc))
    else:
        accessions.append(get_wgs_range(accession))
    return accessions
def extract_assembly_accs ( accession ) : accessions = [ ] root = None assembly_link = None assembly = None assembly_xml = requests . get ( ENA_XML_URL % 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_link = assembly . find ( "ASSEMBLY_LINKS" ) if assembly_link is not None : url_link = assembly_link . find ( "ASSEMBLY_LINK" ) . find ( "URL_LINK" ) . find ( "URL" ) . text accessions = assembly_report_parser ( url_link , url = True ) else : wgs = None wgs = assembly . find ( "WGS_SET" ) wgs_acc = get_wgs_set_accession ( wgs . find ( "PREFIX" ) . text , wgs . find ( "VERSION" ) . text ) accessions . append ( get_wgs_range ( wgs_acc ) ) else : accessions . append ( get_wgs_range ( accession ) ) return accessions
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 # need to check for GCA_REP_LABEL # no assembly link provided - look for WGS element # get wgs accession # get wgs range and return as single accession # move this outside this function to where accessions are requested ??
accession