amuralle / pygr

Automatically exported from code.google.com/p/pygr
0 stars 0 forks source link

attrAlias not passed on when using sqlgraph.SQLGraph #130

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Set attrAlias when instantiating sqlgraph.SQLGraph.

What is the expected output? What do you see instead?
Should get a SQLGraph object. Instead, get error:

In [10]: attrAlias
Out[10]: {'edge_id': 'cid', 'source_id': 'ensGtp_gene', 'target_id': 'cid'}
In [11]: g = sqlgraph.SQLGraph("MOUSE_mm9_ensGene", serverInfo=server_info, 
attrAlias=attrAlias)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/home/kdaily/<ipython console> in <module>()

/home/dock/shared_libraries/lx64/pkgs/pythonsandbox/2.6.2/lib/python2.6/s
ite-packages/pygr-0.8.1-py2.6-linux-x86_64.egg/pygr/sqlgraph.py in 
__init__(self, name, *l, **kwargs)
   1477         except KeyError:
   1478             pass
-> 1479         SQLTableMultiNoCache.__init__(self, name, *l, **tableArgs)
   1480         self.sourceSQL = self._attrSQL('source_id')
   1481         self.targetSQL = self._attrSQL('target_id')

/home/dock/shared_libraries/lx64/pkgs/pythonsandbox/2.6.2/lib/python2.6/s
ite-packages/pygr-0.8.1-py2.6-linux-x86_64.egg/pygr/sqlgraph.py in 
__init__(self, *args, **kwargs)
   1170     def __init__(self, *args, **kwargs):
   1171         SQLTableBase.__init__(self, *args, **kwargs)
-> 1172         self.distinct_key = self._attrSQL(self._distinct_key)
   1173         if not self.orderBy:
   1174             self.orderBy = 'GROUP BY %s ORDER BY %s' % 
(self.distinct_key,

/home/dock/shared_libraries/lx64/pkgs/pythonsandbox/2.6.2/lib/python2.6/s
ite-packages/pygr-0.8.1-py2.6-linux-x86_64.egg/pygr/sqlgraph.py in 
_attrSQL(self, attr, sqlColumn, columnNumber)
    678         except KeyError:
    679             raise AttributeError('attribute %s not a valid column \
--> 680                                  or alias in %s' % (attr, self.name))
    681         if sqlColumn: # ENSURE THAT THIS TRULY MAPS TO A 
COLUMN NAME IN THE DB
    682             try: # CHECK IF field IS COLUMN NUMBER

AttributeError: attribute source_id not a valid column                          

or alias in MOUSE_mm9_ensGene

Please use labels and text to provide additional information.

Looks like the attrAlias isn't getting put into the right keyword arguments 
set: in SQLGraph.__init__ 

Looking at the values of the output of split_kwargs:

tableArgs = {'serverInfo': <pygr.sqlgraph.MySQLServerInfo object at 
0xf85ed0>}
graphArgs = {'attrAlias': {'source_id': 'ensGtp_gene', 'target_id': 'cid', 
'edge_id': 'cid'}}
AttrAlias = None

I changed from:

    def __init__(self, name, *l, **kwargs):
        graphArgs, tableArgs = split_kwargs(kwargs,
                                             ('attrAlias', 'defaultColumnType', 'columnAttrs',                                                                                    
                                             'sourceDB', 'targetDB', 'edgeDB', 'simpleKeys',
                                             'unpack_edge', 'edgeDictClass', 'graph'))

to:

    def __init__(self, name, *l, **kwargs):
        graphArgs, tableArgs = split_kwargs(kwargs,
                                            ('defaultColumnType', 'columnAttrs',
                                             'sourceDB', 'targetDB', 'edgeDB', 'simpleKeys',
                                             'unpack_edge', 'edgeDictClass', 'graph'))

and it worked!

Original issue reported on code.google.com by kmda...@gmail.com on 27 May 2010 at 10:17

GoogleCodeExporter commented 8 years ago
Is there something that I can do in order to fix this in the code?

Original comment by kmda...@gmail.com on 3 Mar 2011 at 10:25