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

add methods to export results in tabular format #280

Open
wants to merge 34 commits into
base: dev
Choose a base branch
from

Conversation

liannette
Copy link
Contributor

  • add method to nplinker class for exporting links, as well as genomic and metabolomic data
  • add test for generating the tabular data for the links

@CunliangGeng
Copy link
Member

CunliangGeng commented Oct 17, 2024

Please assign me to review it when it's ready ;-) If you're still working on that, it's better to change it to a draft PR

@liannette
Copy link
Contributor Author

I thought I was finished, but I realized that it still needs a bit of work. I will assign you as soon as I'm happy with it!

@liannette liannette marked this pull request as draft October 17, 2024 13:29
@liannette liannette marked this pull request as ready for review October 18, 2024 15:43
@liannette
Copy link
Contributor Author

@CunliangGeng It's ready for review :) I just can not request a review explicitly, because I have only read permission for the repository.

@CunliangGeng CunliangGeng self-requested a review October 22, 2024 07:28
Copy link
Member

@CunliangGeng CunliangGeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check the code step by step, and first thing to check is about code format and style:

  1. Please check the errors in the static typing, and correct the incorrect typings. You could use mypy to check them locally before committing.
  2. It is not explicitly mentioned, but we do follow some rules for the order of methods/functions in a class/file. The order of methods/functions are:
  • __init__ method
  • other magic methods, e.g. __str__
  • property methods (using @property)
  • regular methods, class methods (using @classmethod), static methods (using @staticmethod)
  • private methods (_func )
  • deprecated methods (using @deprecated)

For the same level of methods, e.g. regular methods, it's recommended to order them in alphabetical order.

Please check the new methods/functions you added and put them in the right place.

Copy link
Contributor Author

@liannette liannette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I integrated the requested changes, except the ones in the unresolved conversations. Can you take a look at my replies there?

@liannette
Copy link
Contributor Author

Is there anything more needed before merging?

@CunliangGeng
Copy link
Member

Is there anything more needed before merging?

I'll take a closer look today.

Copy link
Member

@CunliangGeng CunliangGeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! A few more minor comments to resolve.

src/nplinker/genomics/bgc.py Outdated Show resolved Hide resolved
src/nplinker/genomics/bgc.py Outdated Show resolved Hide resolved
src/nplinker/genomics/bgc.py Show resolved Hide resolved
src/nplinker/genomics/bgc.py Outdated Show resolved Hide resolved
src/nplinker/genomics/bgc.py Show resolved Hide resolved
src/nplinker/scoring/link_graph.py Show resolved Hide resolved
src/nplinker/scoring/link_graph.py Outdated Show resolved Hide resolved
src/nplinker/scoring/link_graph.py Outdated Show resolved Hide resolved
src/nplinker/scoring/link_graph.py Show resolved Hide resolved
src/nplinker/scoring/link_graph.py Outdated Show resolved Hide resolved
liannette and others added 4 commits November 19, 2024 19:37
Apply suggestions from code review

Co-authored-by: Cunliang Geng <[email protected]>
Apply suggestions from code review

Co-authored-by: Cunliang Geng <[email protected]>
@liannette
Copy link
Contributor Author

Done! I've integrated your suggestions or explained my reasoning for any differences. I hope we're good to merge now.

Copy link
Member

@CunliangGeng CunliangGeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more comment ;-)

src/nplinker/genomics/bgc.py Show resolved Hide resolved
src/nplinker/nplinker.py Outdated Show resolved Hide resolved
@liannette
Copy link
Contributor Author

Okay, it's implemented!

Copy link
Member

@CunliangGeng CunliangGeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments, almost there!

src/nplinker/genomics/bgc.py Outdated Show resolved Hide resolved
src/nplinker/genomics/bgc.py Outdated Show resolved Hide resolved
# Convert dict to comma-separated string
elif isinstance(value, dict):
value = ", ".join([f"{k}:{v}" for k, v in value.items()])
# Convert anything else to string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really want to covert None to ""? Does it make sense to the BGC attributes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value is None, the corresponding field in the tabular output file should be left empty. This ensures that when the file is opened in Excel, numeric fields are correctly recognized as numbers rather than text, allowing the columns to be sorted properly. For text fields, leaving them empty is also preferable to displaying None, as it is cleaner and more intuitive.

src/nplinker/genomics/bgc.py Outdated Show resolved Hide resolved
src/nplinker/metabolomics/spectrum.py Outdated Show resolved Hide resolved
src/nplinker/nplinker.py Outdated Show resolved Hide resolved
@liannette
Copy link
Contributor Author

Alright, I really hope that we can merge this now 👀

Copy link
Member

@CunliangGeng CunliangGeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also hope we can merge it now :shipit: However, we must adhere to some important quality requirements, such as making docstrings and comments accurate and clear; and adding unit tests for all public unit tests. These quality requirements will benefit everyone over time, rather than accumulating more and more technical debt

You could choose what to do next:
1 🍎 Continue this PR and resolve the remaining comments
2 🍐 Merge this PR and open some new and small PRs to resolve the remaining comments

Let me know which one you prefer.

@@ -225,13 +225,16 @@ def to_string(value: Any) -> str:
value = str(value) if value else ""
return value

def to_tabular(self) -> list:
def to_tabular(self) -> dict[str, Any]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def to_tabular(self) -> dict[str, Any]:
def to_tabular(self) -> dict[str, str]:

"""Convert various types of values to a string.

Args:
value: The value to be converted to a string.
Can be a list, tuple, set, dict, or any other type.
Can be a list, dict, or any other type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Can be a list, dict, or any other type.
Can be a list, dict, or other JSON-compatible types.

"""Convert various types of values to a string.

Args:
value: The value to be converted to a string.
Can be a list, tuple, set, dict, or any other type.
Can be a list, dict, or any other type.

Returns:
A string representation of the input value.
"""
# Convert list, tuple, set to comma-separated string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Convert list, tuple, set to comma-separated string
# Convert list to comma-separated string

"""Convert the BGC object to a tabular format.

Returns:
list: A list of strings representing the BGC object in tabular format.
dict: A dictionary representing the BGC object in tabular format.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dict: A dictionary representing the BGC object in tabular format.
dict: A dictionary representing the BGC object in tabular format.
The keys can be treated as headers and values are strings in which tabs are removed.
This dict can be exported as a TSV file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required to test public methods to_tabluar and optional to test private method _to_string. So please add unit tests for the public methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required to test public methods to_tabluar and optional to test private method _to_string. So please add unit tests for to_tabluar method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the docstrings and comments based on my comments in bgc.py

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit tests for public method to_tsv.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit tests for the new public methods objects_to_tsv and to_tsv in test_nplinker_local.py.

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

Successfully merging this pull request may close these issues.

2 participants