ggonnella / gfapy

Gfapy: a flexible and extensible software library for handling sequence graphs in Python
Other
65 stars 7 forks source link

linear_path error #15

Closed egoltsman closed 4 years ago

egoltsman commented 4 years ago

Dear Giorgio,

I am trying to implement a sub-graph traversal functon using some of the methods in the GraphOperations class. I couldn't find much on this in the online documentation, so I'm trying this the hard way :) The linear_path() method, if I understand it correctly, expects a segment from the graph, but since this is not a method of the Gfa class, I can't call it on the graph object itself. I'm assuming that internally, the recursive _traverse() function somehow follows references to go from one segment to the next without having to access the gfa object itself. But the way I'm calling the method must be wrong as it fails to accept the segment argument. Here's how I'm calling it.

[ ... after loading a GFA1 file into a Gfa object: ] from gfapy.graph_operations import GraphOperations path=graphOperations.linear_path(gfaOne.segments[5], None)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-73-15bd5f07fa1b> in <module>
----> 1 GraphOperations.linear_path(gfaOne.segments[5], None)

~/.conda/envs/panG/lib/python3.8/site-packages/gfapy/graph_operations/linear_paths.py in linear_path(self, segment, exclude)
     14     else:
     15       segment_name = segment
---> 16       segment = self.segment(segment_name)
     17     cs = segment._connectivity()
     18     if exclude is None:

~/.conda/envs/panG/lib/python3.8/site-packages/gfapy/line/common/dynamic_fields.py in __getattribute__(self, name)
     23         return attr.get(self)
     24     except AttributeError as err:
---> 25       return self._get_dynamic_field(name, err)
     26 
     27   def __setattr__(self, name, value):

~/.conda/envs/panG/lib/python3.8/site-packages/gfapy/line/common/dynamic_fields.py in _get_dynamic_field(self, name, err)
     53           "No value defined for tag {}".format(name))
     54     else:
---> 55       raise err
     56 
     57   def _set_dynamic_field(self, name, value):

~/.conda/envs/panG/lib/python3.8/site-packages/gfapy/line/common/dynamic_fields.py in __getattribute__(self, name)
     17   def __getattribute__(self, name):
     18     try:
---> 19       attr = super().__getattribute__(name)
     20       if not isinstance(attr, DynamicField):
     21         return attr

AttributeError: 'GFA1' object has no attribute 'segment'

What is the correct way of using this method?

Thanks!

ggonnella commented 4 years ago

Hi Eugene, I have a look as soon as possible, later today very probably. Sorry for the delay.

On 22 July 2020 05:42:18 EEST, Eugene Goltsman notifications@github.com wrote:

Dear Giorgio,

I am trying to implement a sub-graph traversal functon using some of the methods in the GraphOperations class. I couldn't find much on this in the online documentation, so I'm trying this the hard way :)
The linear_path() method, if I understand it correctly, expects a segment from the graph, but since this is not a method of the Gfa class, I can't call it on the graph object itself. I'm assuming that internally, the recursive _traverse() function somehow follows references to go from one segment to the next without having to access the gfa object itself. But the way I'm calling the method must be wrong as it fails to accept the segment argument. Here's how I'm calling it.

[ ... after loading a GFA1 file into a Gfa object: ] from gfapy.graph_operations import GraphOperations path=graphOperations.linear_path(gfaOne.segments[5], None)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call
last)
<ipython-input-73-15bd5f07fa1b> in <module>
----> 1 GraphOperations.linear_path(gfaOne.segments[5], None)

~/.conda/envs/panG/lib/python3.8/site-packages/gfapy/graph_operations/linear_paths.py
in linear_path(self, segment, exclude)
    14     else:
    15       segment_name = segment
---> 16       segment = self.segment(segment_name)
    17     cs = segment._connectivity()
    18     if exclude is None:

~/.conda/envs/panG/lib/python3.8/site-packages/gfapy/line/common/dynamic_fields.py
in __getattribute__(self, name)
    23         return attr.get(self)
    24     except AttributeError as err:
---> 25       return self._get_dynamic_field(name, err)
    26 
    27   def __setattr__(self, name, value):

~/.conda/envs/panG/lib/python3.8/site-packages/gfapy/line/common/dynamic_fields.py
in _get_dynamic_field(self, name, err)
    53           "No value defined for tag {}".format(name))
    54     else:
---> 55       raise err
    56 
    57   def _set_dynamic_field(self, name, value):

~/.conda/envs/panG/lib/python3.8/site-packages/gfapy/line/common/dynamic_fields.py
in __getattribute__(self, name)
    17   def __getattribute__(self, name):
    18     try:
---> 19       attr = super().__getattribute__(name)
    20       if not isinstance(attr, DynamicField):
    21         return attr

AttributeError: 'GFA1' object has no attribute 'segment'

What is the correct way of using this method?

Thanks!

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/ggonnella/gfapy/issues/15

-- Dr. Giorgio Gonnella

ggonnella commented 4 years ago

HI Eugene, the method should be called on a Gfa object. The first parameter is either a segment name or a segment. So in your case it should be gfaOne.linear_path(gfaOne.segments[5]).

egoltsman commented 4 years ago

Thank you, I can't believe I didn't try this.