<reponame>DiDigsDNA/cpo-pipeline
# -*- coding: utf-8 -*-
"""cpo-pipeline.plasmids.parsers

This module provides functions for parsing result files generated by tools
during the QC & Assembly phase of the cpo-pipeline.
"""

import csv

def custom_plasmid_db_dat_parser(path_to_dat_file):
    fieldnames = {
        'accession': lambda x: x,
        'date': lambda x: x,
        'circularity': lambda x: x,
        'organism': lambda x: x,
        'plasmid_name': lambda x: x,
        'plasmid_length': lambda x: int(x),
        'allele': lambda x: x,
        'incompatibility_group': lambda x: x,
        'geographic_region': lambda x: x,
    }

    parsed_dat_file = []
    with open(path_to_dat_file) as dat_file:
        reader = csv.DictReader(dat_file, delimiter='\t', fieldnames=list(fieldnames))
        for row in reader:
            dat_record = {}
            for fieldname, parse in fieldnames.items():
                dat_record[fieldname] = parse(row[fieldname])
            parsed_dat_file.append(dat_record)

    return parsed_dat_file


# -*- coding: utf-8 -*-
"""cpo-pipeline.plasmids.parsers

This module provides functions for parsing result files generated by tools
during the QC & Assembly phase of the cpo-pipeline.
"""

import csv

def custom_plasmid_db_dat_parser(path_to_dat_file):
    fieldnames = {
        'accession': lambda x: x,
        'date': lambda x: x,
        'circularity': lambda x: x,
        'organism': lambda x: x,
        'plasmid_name': lambda x: x,
        'plasmid_length': lambda x: int(x),
        'allele': lambda x: x,
        'incompatibility_group': lambda x: x,
        'geographic_region': lambda x: x,
    }

    parsed_dat_file = []
    with open(path_to_dat_file) as dat_file:
        reader = csv.DictReader(dat_file, delimiter='\t', fieldnames=list(fieldnames))
        for row in reader:
            dat_record = {}
            for fieldname, parse in fieldnames.items():
                dat_record[fieldname] = parse(row[fieldname])
            parsed_dat_file.append(dat_record)

    return parsed_dat_file
# -*- coding: utf-8 -*- cpo-pipeline.plasmids.parsers  This module provides functions for parsing result files generated by tools during the QC & Assembly phase of the cpo-pipeline.