<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_contigs(asm_uid, contig_uids, batchsize=10000):
 """Writes assembly contigs out to a single FASTA file in the script's designated output directory. FASTA records are returned, as GenBank and even GenBankWithParts format records don't reliably give correct sequence in all cases. The script returns two strings for each assembly, a 'class' and a 'label' string - this is for use with, e.g. pyani. """

    # Has duplicate code with get_class_label_info() - needs refactoring
    logger.info("Collecting contig data for %s", asm_uid)
    # Assembly record - get binomial and strain names
    asm_record = Entrez.read(
        entrez_retry(
            Entrez.esummary, db='assembly', id=asm_uid, rettype='text'),
        validate=False)
    asm_organism = asm_record['DocumentSummarySet']['DocumentSummary'][0][
        'SpeciesName']
    try:
        asm_strain = asm_record['DocumentSummarySet']['DocumentSummary'][0][
            'Biosource']['InfraspeciesList'][0]['Sub_value']
    except KeyError:
        asm_strain = ""
    # Assembly UID (long form) for the output filename
    outfilename = "%s.fasta" % os.path.join(args.outdirname, asm_record[
        'DocumentSummarySet']['DocumentSummary'][0]['AssemblyAccession'])

    # Create label and class strings
    genus, species = asm_organism.split(' ', 1)

    # Get FASTA records for contigs
    logger.info("Downloading FASTA records for assembly %s (%s)", asm_uid,
                ' '.join([genus[0] + '.', species, asm_strain]))
    # We're doing an explicit outer retry loop here because we want to confirm
    # we have the correct data, as well as test for Entrez connection errors,
    # which is all the entrez_retry function does.
    tries, success = 0, False
    while not success and tries < args.retries:
        records = []  # Holds all return records
        # We may need to batch contigs
        query_uids = ','.join(contig_uids)
        try:
            for start in range(0, len(contig_uids), batchsize):
                logger.info("Batch: %d-%d", start, start + batchsize)
                records.extend(
                    list(
                        SeqIO.parse(
                            entrez_retry(
                                Entrez.efetch,
                                db='nucleotide',
                                id=query_uids,
                                rettype='fasta',
                                retmode='text',
                                retstart=start,
                                retmax=batchsize), 'fasta')))
            tries += 1
            # Check only that correct number of records returned.
            if len(records) == len(contig_uids):
                success = True
            else:
                logger.warning("%d contigs expected, %d contigs returned",
                               len(contig_uids), len(records))
                logger.warning("FASTA download for assembly %s failed",
                               asm_uid)
                logger.warning("try %d/20", tries)
            # Could also check expected assembly sequence length?
            logger.info("Downloaded genome size: %d",
                        sum([len(r) for r in records]))
        except:
            logger.warning("FASTA download for assembly %s failed", asm_uid)
            logger.warning(last_exception())
            logger.warning("try %d/20", tries)
    if not success:
        # Could place option on command-line to stop or continue here.
        logger.error("Failed to download records for %s (continuing)", asm_uid)

    # Write contigs to file
    retval = SeqIO.write(records, outfilename, 'fasta')
    logger.info("Wrote %d contigs to %s", retval, outfilename)