scripts/export/genomes/genome_fetch.py
def download_genomes(gen, dest_dir):
    """
    Downloads all chromosome files of a given assembly accession (ENA) in
    dest_dir

    gen: Single accession (string) or a list of genome accessions (GC*)
    dest_dir: The path of the destination directory to export the fasta
    files
    """

    # need to add logging
    accessions = None

    if os.path.isfile(gen):
        gen_fp = open(gen, 'r')

        for gen_acc in gen_fp:
            gen_acc = string.strip(gen_acc)

            if string.find(gen_acc, '.') != -1:
                gen_acc = gen_acc.partition('.')
                gen_acc = gen_acc[0]

            gen_dir = os.path.join(dest_dir, gen_acc)

            try:
                os.mkdir(gen_dir)

            except:
                print "Unable to generate directory for accession: ", gen

            accessions = extract_assembly_accs(gen_acc)

            if len(accessions) > 0:
                for acc in accessions:
                    fetch_ena_file(acc, "fasta", gen_dir)

            gen_acc = None
            gen_dir = None
            accessions = None

        gen_fp.close()

    else:
        if string.find(gen, '.') != -1:
            gen = gen.partition('.')
            gen = gen[0]

        gen_dir = os.path.join(dest_dir, gen)

        try:
            os.mkdir(gen_dir)
        except:
            print "Unable to generate directory for accession: ", gen

        accessions = extract_assembly_accs(gen)

        if len(accessions) > 0:
            for acc in accessions:
                fetch_ena_file(acc, "fasta", gen_dir)

        # if no accessions found, write to log file
        else:
            return None

    return True

    Downloads all chromosome files of a given assembly accession (ENA) in
    dest_dir

    gen: Single accession (string) or a list of genome accessions (GC*)
    dest_dir: The path of the destination directory to export the fasta
    files
    
Downloads all chromosome files of a given assembly accession (ENA) in
dest_dir

Single accession (string) or a list of genome accessions (GC*)
dest_dir: The path of the destination directory to export the fasta
files
Downloads all chromosome files of a given assembly accession ( ENA ) in dest_dir Single accession ( string ) or a list of genome accessions ( GC * ) dest_dir : The path of the destination directory to export the fasta files
def download_genomes(gen, dest_dir):
    accessions = None
    if os.path.isfile(gen):
        gen_fp = open(gen, 'r')
        for gen_acc in gen_fp:
            gen_acc = string.strip(gen_acc)
            if string.find(gen_acc, '.') != -1:
                gen_acc = gen_acc.partition('.')
                gen_acc = gen_acc[0]
            gen_dir = os.path.join(dest_dir, gen_acc)
            try:
                os.mkdir(gen_dir)
            except:
                print "Unable to generate directory for accession: ", gen
            accessions = extract_assembly_accs(gen_acc)
            if len(accessions) > 0:
                for acc in accessions:
                    fetch_ena_file(acc, "fasta", gen_dir)
            gen_acc = None
            gen_dir = None
            accessions = None
        gen_fp.close()
    else:
        if string.find(gen, '.') != -1:
            gen = gen.partition('.')
            gen = gen[0]
        gen_dir = os.path.join(dest_dir, gen)
        try:
            os.mkdir(gen_dir)
        except:
            print "Unable to generate directory for accession: ", gen
        accessions = extract_assembly_accs(gen)
        if len(accessions) > 0:
            for acc in accessions:
                fetch_ena_file(acc, "fasta", gen_dir)
        else:
            return None
    return True
def download_genomes ( gen , dest_dir ) : accessions = None if os . path . isfile ( gen ) : gen_fp = open ( gen , 'r' ) for gen_acc in gen_fp : gen_acc = string . strip ( gen_acc ) if string . find ( gen_acc , '.' ) != - 1 : gen_acc = gen_acc . partition ( '.' ) gen_acc = gen_acc [ 0 ] gen_dir = os . path . join ( dest_dir , gen_acc ) try : os . mkdir ( gen_dir ) except : print "Unable to generate directory for accession: " , gen accessions = extract_assembly_accs ( gen_acc ) if len ( accessions ) > 0 : for acc in accessions : fetch_ena_file ( acc , "fasta" , gen_dir ) gen_acc = None gen_dir = None accessions = None gen_fp . close ( ) else : if string . find ( gen , '.' ) != - 1 : gen = gen . partition ( '.' ) gen = gen [ 0 ] gen_dir = os . path . join ( dest_dir , gen ) try : os . mkdir ( gen_dir ) except : print "Unable to generate directory for accession: " , gen accessions = extract_assembly_accs ( gen ) if len ( accessions ) > 0 : for acc in accessions : fetch_ena_file ( acc , "fasta" , gen_dir ) else : return None return True
Downloads all chromosome files of a given assembly accession (ENA) in
dest_dir
Downloads all chromosome files of a given assembly accession ( ENA ) in dest_dir
"""
    Downloads all chromosome files of a given assembly accession (ENA) in
    dest_dir

    gen: Single accession (string) or a list of genome accessions (GC*)
    dest_dir: The path of the destination directory to export the fasta
    files
    """ # need to add logging # if no accessions found, write to log file
gen
dest_dir