Skip to content

Commit

Permalink
reformat other file
Browse files Browse the repository at this point in the history
  • Loading branch information
taoliu committed Oct 3, 2024
1 parent d032310 commit bc99387
Show file tree
Hide file tree
Showing 4 changed files with 343 additions and 356 deletions.
15 changes: 7 additions & 8 deletions MACS3/Commands/hmmratac_cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Time-stamp: <2024-10-02 17:20:22 Tao Liu>
# Time-stamp: <2024-10-02 17:41:10 Tao Liu>


"""Description: Main HMMR command
Expand Down Expand Up @@ -62,7 +62,6 @@ def run(args):
mono_bdgfile = os.path.join(options.outdir, options.name+"_digested_mono.bdg")
di_bdgfile = os.path.join(options.outdir, options.name+"_digested_di.bdg")
tri_bdgfile = os.path.join(options.outdir, options.name+"_digested_tri.bdg")

training_region_bedfile = os.path.join(options.outdir, options.name+"_training_regions.bed")
training_datafile = os.path.join(options.outdir, options.name+"_training_data.txt")
training_datalengthfile = os.path.join(options.outdir, options.name+"_training_lengths.txt")
Expand Down Expand Up @@ -158,9 +157,9 @@ def run(args):

# now we will prepare the weights for each fragment length for
# each of the four distributions based on the EM results
weight_mapping = generate_weight_mapping(fl_list, em_means, em_stddevs, min_frag_p = options.min_frag_p)
options.info(f"# Generate short, mono-, di-, and tri-nucleosomal signals")
weight_mapping = generate_weight_mapping(fl_list, em_means, em_stddevs, min_frag_p=options.min_frag_p)

options.info("# Generate short, mono-, di-, and tri-nucleosomal signals")
digested_atac_signals = generate_digested_signals(petrack, weight_mapping)

# save three types of signals if needed
Expand Down Expand Up @@ -281,7 +280,7 @@ def run(args):
options.info("#4 Load Hidden Markov Model from given model file")
hmm_model, i_open_region, i_background_region, i_nucleosomal_region, options.hmm_binsize, options.hmm_type = hmm_model_init(options.hmm_file)
else:
options.info(f"#4 Train Hidden Markov Model with Multivariate Gaussian Emission")
options.info("#4 Train Hidden Markov Model with Multivariate Gaussian Emission")

# extract signals within peak using the given binsize
options.info(f"# Extract signals in training regions with bin size of {options.hmm_binsize}")
Expand Down Expand Up @@ -348,9 +347,9 @@ def run(args):
options.info( "# {0:>10s}-> {1[0]:>10.4g} {1[1]:>10.4g} {1[2]:>10.4g}".format(assignments[0], hmm_model.transmat_[0]))
options.info( "# {0:>10s}-> {1[0]:>10.4g} {1[1]:>10.4g} {1[2]:>10.4g}".format(assignments[1], hmm_model.transmat_[1]))
options.info( "# {0:>10s}-> {1[0]:>10.4g} {1[1]:>10.4g} {1[2]:>10.4g}".format(assignments[2], hmm_model.transmat_[2]))

if options.hmm_type == 'gaussian':
options.info(f"# HMM Emissions (means): ")
options.info("# HMM Emissions (means): ")
options.info( "# {0[0]:>10s} {0[1]:>10s} {0[2]:>10s} {0[3]:>10s}".format(["short", "mono", "di", "tri"]))
options.info( "# {0:>10s}: {1[0]:>10.4g} {1[1]:>10.4g} {1[2]:>10.4g} {1[3]:>10.4g}".format(assignments[0], hmm_model.means_[0]))
options.info( "# {0:>10s}: {1[0]:>10.4g} {1[1]:>10.4g} {1[2]:>10.4g} {1[3]:>10.4g}".format(assignments[1], hmm_model.means_[1]))
Expand Down
10 changes: 6 additions & 4 deletions MACS3/Utilities/Logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
class MemoryLogger(logging.Logger):
def __init__(self, name, level=logging.NOTSET):
super().__init__(name, level)

def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False):

def _log(self, level, msg, args, exc_info=None,
extra=None, stack_info=False):
mem_usage = self.get_memory_usage()
super()._log(level, f"[{mem_usage} MB] {msg}", args, exc_info, extra, stack_info)
super()._log(level, f"[{mem_usage} MB] {msg}",
args, exc_info, extra, stack_info)

@staticmethod
def get_memory_usage():
mem_usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
if os.name == 'posix' and os.uname().sysname == 'Darwin':
# macOS
mem_usage = mem_usage / 1024 # Convert to kilobytes
return int(mem_usage / 1024) # Convert to MB
return int(mem_usage / 1024) # Convert to MB


logging.basicConfig(level=20,
Expand Down
Loading

0 comments on commit bc99387

Please sign in to comment.