def cli(logfile, outdir, ressep, table): # Setup logger logging.config.dictConfig({ "version": 1, "disable_existing_loggers": False, # this fixes the problem "formatters": { "standard": { "class": "logging.Formatter", "format": "%(name)-12s %(levelname)-8s %(message)s", }, "detailed": { "class": "logging.Formatter", "format": "%(asctime)s %(name)-15s %(levelname)-8s %(message)s", "datefmt": "%m-%d-%y %H:%M", }, }, "handlers": { "console": { "class": "logging.StreamHandler", "level": "INFO", "formatter": "standard", }, "file": { "class": "logging.FileHandler", "filename": logfile, "level": "INFO", "mode": "w", "formatter": "detailed", } }, "root": { "level": "INFO", "handlers": ["console", "file"] }, }) logger = logging.getLogger(__name__) logger.info("Reading {}".format(table)) table_1 = paramtable.ParamTable(ressep=ressep) table_1.from_file(table) logger.info("{} read successfully.".format(table)) d_table = table_1.table.diff(axis=1).dropna(axis=1) d_perres = table_1.per_residue.diff(axis=1).dropna(axis=1) d_interactions = table_1.interactions.diff(axis=1).dropna(axis=1) filename = path.join(outdir, "dframe_coupling.txt") with open(filename, mode="wb") as output: logger.info("Writing frame differences to {}".format(filename)) d_table = d_table.to_csv( header=True, index=True, sep=native_str(" "), float_format=native_str("%.4f"), encoding="utf-8", ) output.write(d_table.encode()) logger.info("Table written successfully.") filename = path.join(outdir, "dframe_perres.txt") with open(filename, mode="wb") as output: logger.info( "Writing per residue frame differences to {}".format(filename)) d_perres = d_perres.to_csv( header=True, index=True, sep=native_str(" "), float_format=native_str("%.4f"), encoding="utf-8", ) output.write(d_perres.encode()) logger.info("Table written successfully.") filename = path.join(outdir, "dframe_interactions.txt") with open(filename, mode="wb") as output: logger.info( "Writing residue-residue frame differences to {}".format(filename)) d_interactions = d_interactions.to_csv( header=True, index=True, sep=native_str(" "), float_format=native_str("%.4f"), encoding="utf-8", ) output.write(d_interactions.encode()) logger.info("Table written successfully.")
def cli(data_dir, logfile, outdir, prefix, tbltype, ressep, verbose, start, end, trimmed, trimcut): pt = paramtable.ParamTable( prefix=prefix, tbltype=tbltype, ressep=ressep, datadir=data_dir, start=start, end=end, trimmed=trimmed, trimcut=trimcut ) # Setup logger logging.config.dictConfig({ "version": 1, "disable_existing_loggers": False, # this fixes the problem "formatters": { "standard": { "class": "logging.Formatter", "format": "%(name)-12s %(levelname)-8s %(message)s", }, "detailed": { "class": "logging.Formatter", "format": "%(asctime)s %(name)-15s %(levelname)-8s %(message)s", "datefmt": "%m-%d-%y %H:%M", }, }, "handlers": { "console": { "class": "logging.StreamHandler", "level": "INFO", "formatter": "standard", }, "file": { "class": "logging.FileHandler", "filename": logfile, "level": "INFO", "mode": "w", "formatter": "detailed", } }, "root": { "level": "INFO", "handlers": ["console", "file"] }, }) logger = logging.getLogger(__name__) pt.run(verbose=verbose) # Write the various tables to different files. fn = path.join(outdir, filename(tbltype.lower(), ext="txt", keep=True)) pt.write(fn) if tbltype == "Kb": fn = path.join(outdir, filename("perres", ext="txt")) with open(fn, mode="wb") as output: logger.info("Writing per-residue data to {}.".format(fn)) table = pt.per_residue.to_csv( header=True, index=True, sep=native_str(" "), float_format=native_str("%.4f"), encoding="utf-8", ) output.write(table.encode()) logger.info("Table successfully written.") fn = path.join(outdir, filename("interactions", ext="txt")) with open(fn, mode="wb") as output: logger.info("Writing interactions to {}.".format(fn)) table = pt.interactions.to_csv( header=True, index=True, sep=native_str(" "), float_format=native_str("%.4f"), encoding="utf-8", ) output.write(table.encode()) logger.info("Table successfully written.")
def cli(logfile, outdir, ressep, kb, b0): # Setup logger logging.config.dictConfig({ "version": 1, "disable_existing_loggers": False, # this fixes the problem "formatters": { "standard": { "class": "logging.Formatter", "format": "%(name)-12s %(levelname)-8s %(message)s", }, "detailed": { "class": "logging.Formatter", "format": "%(asctime)s %(name)-15s %(levelname)-8s %(message)s", "datefmt": "%m-%d-%y %H:%M", }, }, "handlers": { "console": { "class": "logging.StreamHandler", "level": "INFO", "formatter": "standard", }, "file": { "class": "logging.FileHandler", "filename": logfile, "level": "INFO", "mode": "w", "formatter": "detailed", } }, "root": { "level": "INFO", "handlers": ["console", "file"] }, }) logger = logging.getLogger(__name__) resgrp = ['segidI', 'resI'] logger.info("Loading coupling strength table.") kb_table = paramtable.ParamTable(ressep=ressep) kb_table.from_file(kb) kb_table = kb_table.table.copy(deep=True) logger.info("Table loaded successfully.") logger.info("Loading distance table.") b0_table = paramtable.ParamTable(ressep=ressep) b0_table.from_file(b0) b0_table = b0_table.table.copy(deep=True) logger.info("Table loaded successfully.") idx = (kb_table == 0.0) maxkb = np.maximum(kb_table[kb_table.columns[1:].values], kb_table[kb_table.columns[:-1]].values) maxkb[maxkb == 0.0] = np.NaN kb_table = kb_table.diff(axis=1).dropna(axis=1) / maxkb kb_table.columns = kb_table.columns.astype(np.int32) - 1 count = kb_table[kb_table.abs() > 0.].groupby(level=resgrp).count() kb_table = kb_table.groupby(level=resgrp).sum() / count kb_table.fillna(0., inplace=True) # Calculate the r.m.s.d. of equilibrium distances between sites. b0_table = b0_table.diff(axis=1).dropna(axis=1) / maxkb b0_table[idx] = 0.0 b0_table = 0.5 * b0_table.pow(2).groupby(level=resgrp).sum() b0_table = b0_table.apply(np.sqrt) filename = path.join(outdir, "normed_kb.txt") with open(filename, mode="wb") as output: logger.info("Writing normed coupling strengths to {}".format(filename)) kb_table = kb_table.to_csv( header=True, index=True, sep=native_str(" "), float_format=native_str("%.4f"), encoding="utf-8", ) output.write(kb_table.encode()) logger.info("Table written successfully.") filename = path.join(outdir, "normed_b0.txt") with open(filename, mode="wb") as output: logger.info("Writing normed distances to {}".format(filename)) b0_table = b0_table.to_csv( header=True, index=True, sep=native_str(" "), float_format=native_str("%.4f"), encoding="utf-8", ) output.write(b0_table.encode()) logger.info("Table written successfully.")