Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cryoDRGN_analyze_landscape Jupyter notebook in v3.3.3 has a parse_mrc bug #413

Closed
cbeck22 opened this issue Oct 11, 2024 · 1 comment
Closed

Comments

@cbeck22
Copy link

cbeck22 commented Oct 11, 2024

Hi!

I'm running cryoDRGN v3.3.3, and while I realize that this bug has probably been fixed in the recent v3.4 versions, v.3.3.3 is currently the most recent version available through SBGrid.

Bug description
Running cell 5 in the cryoDRGN_analyze_landscape Jupyter notebook generated by analyze_landscape_full returns this error:

mask = mrc.parse_mrc(f'{landscape_dir}/mask.mrc')
mask = mask[0].astype(bool)
print(f'{mask.sum()} out of {np.prod(mask.shape)} voxels included in mask')

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[12], line 1
----> 1 mask = mrc.parse_mrc(f'{landscape_dir}/mask.mrc')
      2 mask = mask[0].astype(bool)
      3 print(f'{mask.sum()} out of {np.prod(mask.shape)} voxels included in mask')

AttributeError: module 'cryodrgn.mrc' has no attribute 'parse_mrc'

Possible fix
Going through the release notes for v3.4, I noticed the following:

MRCFile, which consisted solely of static parse and write methods, has been replaced by the old names of these methods (parse_mrc and write_mrc)

mrc module is now named mrcfile for better verbosity and to match starfile module which is its parallel for processing input files

I think that the notebook in v3.3.3 is trying to reference the updated parse_mrc, which only seems to be available in v3.4. The following fix to cell 5 appears to have fixed the issue:

mask = mrc.MRCFile.parse(f'{landscape_dir}/mask.mrc')
mask = mask[0].astype(bool)
print(f'{mask.sum()} out of {np.prod(mask.shape)} voxels included in mask')

144091 out of 2097152 voxels included in mask

Cheers,
cbeck

@michal-g
Copy link
Collaborator

Hey Curtis, thanks for the catch, unfortunately the code in this notebook is generally a little outdated, as we are in the middle of considering some reorganization, refactoring, and refreshing of the code used for describing and plotting the output of our landscape analyses. This is of course related to #410 — I hope to have some updates to post to that thread in the upcoming few weeks!

In the meantime, I have included some changes to the notebook produced by analyze_landscape_full to address this issue and some other problems in the latest release on our beta channel for those who have access to more recent cryoDRGN versions:

pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ 'cryodrgn<=3.4.2' --pre

These changes for v3.4.x are necessitated by the fact that the code in the v3.3.3 of the notebook is actually trying to reference a previous — not subsequent — implementation of the cryodrgn.mrc functions (now cryodrgn.mrcfile as you noted) from v2.3.0:

cryodrgn/cryodrgn/mrc.py

Lines 267 to 273 in f58267f

def parse_mrc(fname: str, lazy: bool = False) -> Tuple[types.ImageArray, MRCHeader]: # type: ignore
# parse the header
header = MRCHeader.parse(fname)
# get the number of bytes in extended header
extbytes = header.fields["next"]
start = 1024 + extbytes # start of image data

But your fix is of course still valid for those stuck working with v3.3.3!

Let us know if you find any other problems,
Mike

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants