<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def scrnaseq_concatenate_metadata(samples):
 """ Create file same dimension than mtx.colnames with metadata and sample name to help in the creation of the SC object. """

    barcodes = {}
    counts =  ""
    metadata = {}
    has_sample_barcodes = False
    for sample in dd.sample_data_iterator(samples):
        if dd.get_sample_barcodes(sample):
            has_sample_barcodes = True
            with open(dd.get_sample_barcodes(sample)) as inh:
                for line in inh:
                    cols = line.strip().split(",")
                    if len(cols) == 1:
                        # Assign sample name in case of missing in barcodes
                        cols.append("NaN")
                    barcodes[(dd.get_sample_name(sample), cols[0])] = cols[1:]
        else:
            barcodes[(dd.get_sample_name(sample), "NaN")] = [dd.get_sample_name(sample), "NaN"]

        counts = dd.get_combined_counts(sample)
        meta = map(str, list(sample["metadata"].values()))
        meta_cols = list(sample["metadata"].keys())
        meta = ["NaN" if not v else v for v in meta]
        metadata[dd.get_sample_name(sample)] = meta

    metadata_fn = counts + ".metadata"
    if file_exists(metadata_fn):
        return samples
    with file_transaction(metadata_fn) as tx_metadata_fn:
        with open(tx_metadata_fn, 'w') as outh:
            outh.write(",".join(["sample"] + meta_cols) + '\n')
            with open(counts + ".colnames") as inh:
                for line in inh:
                    sample = line.split(":")[0]
                    if has_sample_barcodes:
                        barcode = sample.split("-")[1]
                    else:
                        barcode = "NaN"
                    outh.write(",".join(barcodes[(sample, barcode)] + metadata[sample]) + '\n')
    return samples