jmschrei / bpnet-lite

This repository hosts a minimal version of a Python API for BPNet.
MIT License
32 stars 14 forks source link

Error in printing model loaded from chrombpnet package #4

Closed adamklie closed 5 months ago

adamklie commented 6 months ago

Hey Jacob,

I have a ChromBPNet model that I trained up using the main chrombpnet repo and I'm trying to load it into bpnet-lite using:

model = ChromBPNet.from_chrombpnet(
    bias_model="bias_model_scaled.h5",
    accessibility_model="chrombpnet_nobias.h5",
    name="mo_EndoC-bH1_ATAC-seq_fold_0"
)

This runs without error, but when I try to simply print out the string representation of the model I get an error in lib/python3.9/site-packages/torch/nn/modules/conv.py:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File ~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:711, in PlainTextFormatter.__call__(self, obj)
    [704](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:704) stream = StringIO()
    [705](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:705) printer = pretty.RepresentationPrinter(stream, self.verbose,
    [706](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:706)     self.max_width, self.newline,
    [707](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:707)     max_seq_length=self.max_seq_length,
    [708](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:708)     singleton_pprinters=self.singleton_printers,
    [709](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:709)     type_pprinters=self.type_printers,
    [710](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:710)     deferred_pprinters=self.deferred_printers)
--> [711](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:711) printer.pretty(obj)
    [712](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:712) printer.flush()
    [713](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/core/formatters.py:713) return stream.getvalue()

File ~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:411, in RepresentationPrinter.pretty(self, obj)
    [408](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:408)                         return meth(obj, self, cycle)
    [409](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:409)                 if cls is not object \
    [410](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:410)                         and callable(cls.__dict__.get('__repr__')):
--> [411](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:411)                     return _repr_pprint(obj, self, cycle)
    [413](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:413)     return _default_pprint(obj, self, cycle)
    [414](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:414) finally:

File ~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:779, in _repr_pprint(obj, p, cycle)
    [777](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:777) """A pprint that just redirects to the normal repr function."""
    [778](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:778) # Find newlines and replace them with p.break_()
--> [779](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:779) output = repr(obj)
    [780](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:780) lines = output.splitlines()
    [781](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/IPython/lib/pretty.py:781) with p.group():

File ~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2384, in Module.__repr__(self)
   [2382](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2382) child_lines = []
   [2383](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2383) for key, module in self._modules.items():
-> [2384](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2384)     mod_str = repr(module)
   [2385](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2385)     mod_str = _addindent(mod_str, 2)
   [2386](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2386)     child_lines.append('(' + key + '): ' + mod_str)

File ~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2378, in Module.__repr__(self)
   [2375](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2375) def __repr__(self):
   [2376](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2376)     # We treat the extra repr like the sub-module, one item per line
   [2377](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2377)     extra_lines = []
-> [2378](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2378)     extra_repr = self.extra_repr()
   [2379](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2379)     # empty string will be split into list ['']
   [2380](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/module.py:2380)     if extra_repr:

File ~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/conv.py:160, in _ConvNd.extra_repr(self)
    [157](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/conv.py:157) def extra_repr(self):
    [158](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/conv.py:158)     s = ('{in_channels}, {out_channels}, kernel_size={kernel_size}'
    [159](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/conv.py:159)          ', stride={stride}')
--> [160](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/conv.py:160)     if self.padding != (0,) * len(self.padding):
    [161](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/conv.py:161)         s += ', padding={padding}'
    [162](https://vscode-remote+ssh-002dremote-002bnrnb-002dlogin-002eucsd-002eedu.vscode-resource.vscode-cdn.net/cellar/users/aklie/data/datasets/mo_EndoC-bH1_ATAC-seq/bin/bpnet-lite/~/opt/miniconda3/envs/ml4g-lite/lib/python3.11/site-packages/torch/nn/modules/conv.py:162)     if self.dilation != (1,) * len(self.dilation):

TypeError: object of type 'int' has no len()

Looks like the padding for the conv instantiation is expecting a tuple. I updated the from_chrombpnet code and will make a pull request that I'll link to this. Tested prediction using tangermeme and seems to be working for that but haven't extensively tested.

bias model: https://drive.google.com/file/d/1EVdxrQeD7jH_QhxLqdm03N4csSknTH8v/view?usp=sharing accessibility model: https://drive.google.com/file/d/1p8UJ6AGWIjgWmi0ekdD5hhV5RNANAvYW/view?usp=sharing

Python version: 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:36:13) [GCC 12.3.0] PyTorch version: 2.0.0+cu118 bpnetlite version: 0.7.3