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

Feat/swc loaderfile Adding SWC loader to load SWC file #384

Merged
merged 46 commits into from
Jul 3, 2024

Conversation

AdityaPandeyCN
Copy link
Contributor

This pull request adds a new module for loading and parsing SWC files

@sanjayankur31 sanjayankur31 marked this pull request as draft June 5, 2024 10:32
@sanjayankur31
Copy link
Member

Converted to a draft @AdityaBITMESRA. We'll mark it as "ready for review" once the various bits have come in.

@sanjayankur31 sanjayankur31 added the T: enhancement Type: enhancement label Jun 5, 2024
@sanjayankur31
Copy link
Member

  • add docstrings
  • docstrings should contain references to information on SWC standard and so on
  • later: consider using something like networkx so that we take advantage of efficient under the hood representations: https://networkx.org/documentation/stable/#

@sanjayankur31
Copy link
Member

  • add unit tests cases for each method

Copy link

Code Coverage

Package Line Rate Health
. 53%
analysis 37%
archive 72%
channelml 55%
lems 46%
neuron 31%
neuron.analysis 0%
plot 47%
povray 0%
sbml 91%
sedml 94%
swc 8%
tellurium 0%
tune 0%
utils 62%
xppaut 0%
Summary 37% (2783 / 7609)


parts = line.split()
if len(parts) != 7:
print(f"Warning: Skipping invalid line: {line}")
Copy link
Member

Choose a reason for hiding this comment

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

I'd make this a logger.error or logger.warning perhaps, and we need to decide if this should stop the parsing of the file.

Copy link
Member

Choose a reason for hiding this comment

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

this still needs to be updated @AdityaBITMESRA

@sanjayankur31
Copy link
Member

Looking good! Notes from the meeting:

  • let's leave the optimisation (networkx etc. bits) for the moment
  • rather, let's focus on implementing the functions we'll need so that we have a "public API": get_parent, get_children, get_branch_points, and so on---a bunch of "getters"
  • lets test these out and confirm that they work correctly
  • later, we can optimise these under the hood

@AdityaPandeyCN
Copy link
Contributor Author

Hi @sanjayankur31 , can you have a look to see if I am going correctly?

@sanjayankur31
Copy link
Member

Sure, will try to do it today, otherwise it may have to wait for Friday---we have a full day conf/symposium tomorrow so wont' be able to get a lot of time at my desk

@sanjayankur31 sanjayankur31 marked this pull request as ready for review June 24, 2024 13:20
Copy link
Member

@sanjayankur31 sanjayankur31 left a comment

Choose a reason for hiding this comment

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

Looking very good @AdityaBITMESRA. It's almost there. I've left a few comments.

In general, please do remember to use type hints and add docstrings everywhere---they're very very important and we consider them compulsory in our code.

along the neuronal structure. For more information on the SWC format, see:
https://swc-specification.readthedocs.io/en/latest/swc.html

Attributes:
Copy link
Member

Choose a reason for hiding this comment

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

These aren't showing up in the docs because they're not in the format we're using. You'll have to use

:param UNDEFINED: ...
:type UNDEFINED: ...

and so on. See the other code bits. The sphinx documentation is here:

https://www.sphinx-doc.org/en/master/usage/domains/python.html#info-field-lists

This is the "default" format, which is what we use.

except (ValueError, TypeError) as e:
raise ValueError(f"Invalid data types in SWC line: {e}")

def to_string(self):
Copy link
Member

Choose a reason for hiding this comment

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

We should add a type hint for return val: def to_string(self) -> str: and so on?

pyneuroml/swc/LoadSWC.py Show resolved Hide resolved
"""
Add a node to the SWC graph.

Args:
Copy link
Member

Choose a reason for hiding this comment

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

needs to be modified to our docstring format

except (ValueError, TypeError) as e:
raise ValueError(f"Invalid data types in SWC line: {e}")

def to_string(self):
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering: what's the difference between adding a new to_string() method vs defining the __str__() method?

https://docs.python.org/3/reference/datamodel.html#object.__str__

Currently, for example, one gets this:

(ins)>>> node = SWCNode(1, 1, 0.0, 0.0, 0.0, 1.0, -1)
(ins)>>> str(node)
'<pyneuroml.swc.LoadSWC.SWCNode object at 0x7f31d89a6810>'

which isn't really informative

nodes = []
for node in self.nodes:
children = self.get_children(node.id)
if len(children) > 1 and (type_id is None or node.type == type_id):
Copy link
Member

Choose a reason for hiding this comment

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

what would happen if an invalid type id is given?

Returns:
list: A list of SWCNode objects that have the specified type ID.
"""
return [node for node in self.nodes if node.type == type_id]
Copy link
Member

Choose a reason for hiding this comment

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

what happens if an invalid type id is given?

for type_id in types:
nodes.extend(self.get_nodes_with_multiple_children(type_id))

return nodes
Copy link
Member

Choose a reason for hiding this comment

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

we probably want to return a dict with the key being the type and the value being the list of nodes of that type?

The use case here is "give me branch points in axons and dendrites" and we'll probably want to treat them differently. If not, the user can always iterate over all the values.

return nodes


def parse_header(line):
Copy link
Member

Choose a reason for hiding this comment

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

don't forget the type hints and doc string :)


parts = line.split()
if len(parts) != 7:
print(f"Warning: Skipping invalid line: {line}")
Copy link
Member

Choose a reason for hiding this comment

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

this still needs to be updated @AdityaBITMESRA

@AdityaPandeyCN
Copy link
Contributor Author

Thankyou for the comments.I will look into it

@AdityaPandeyCN
Copy link
Contributor Author

Hi @sanjayankur31. I have addressed all the comments. Please take a look when time permits

@sanjayankur31
Copy link
Member

Cool, I'll try to do that today. Could you check and fix the issue ruff is pointing out? (If you set up pre-commit, ruff should run on your system and fix things each time you commit---see the contributing.md file)

@AdityaPandeyCN
Copy link
Contributor Author

I have already setup pre-commit hooks but I think the ruff is pointing out to an error in PlotMorphologyVispy.py file(unused imports) which is not the file I was working on. So what should I do?

@sanjayankur31
Copy link
Member

Hrm, that must've been fixed in develop. Let me update your branch here on GitHub and that should fix it.

@sanjayankur31
Copy link
Member

OK, that fixes it. Do remember to pull on your local machine so you get the updates to your branch too.

@AdityaPandeyCN
Copy link
Contributor Author

sure...thankyou

@sanjayankur31
Copy link
Member

Looks good. I've made some tweaks in #400. Will merge that once the tests pass, and that should merge this one too.

sanjayankur31 added a commit that referenced this pull request Jul 3, 2024
@sanjayankur31 sanjayankur31 merged commit 7d4705d into NeuroML:development Jul 3, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement Type: enhancement
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants