Source code for lmpy.tools.convert_lmm_to_csv

"""Convert a lmpy Matrix to a (.csv) file."""
import argparse

from lmpy import Matrix


DESCRIPTION = 'Convert a lmpy Matrix to a CSV file with numerical values.'


# .....................................................................................
[docs]def convert_lmm_to_csv(mtx, csv_filename): """Convert a lmpy Matrix to a csv file. Args: mtx (Matrix): A lmpy matrix to convert to csv. csv_filename (str): The file location of the csv to convert. """ with open(csv_filename, mode='wt') as csv_out: mtx.write_csv(csv_out)
# .....................................................................................
[docs]def cli(): """Provide a command-line tool for converting lmms to csvs.""" parser = argparse.ArgumentParser(description=DESCRIPTION) parser.add_argument( 'in_lmm_filename', type=str, help='Lmpy LMM filename to convert to CSV.' ) parser.add_argument( 'out_csv_filename', type=str, help='Location to write the converted matrix CSV.' ) args = parser.parse_args() mtx = Matrix.load(args.in_lmm_filename) convert_lmm_to_csv(mtx, args.out_csv_filename)
# ..................................................................................... __all__ = ['cli', 'convert_lmm_to_csv'] # ..................................................................................... if __name__ == '__main__': # pragma: no cover cli()