ofanoyi / pygr

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

Types of acceptable sourceDB or targetDB for sqlgraph.GraphView #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Please use labels and text to provide additional information.

Since the sqlgraph.GraphView class is also considered a graph interface,
wouldn't it be nice to make it flexible in taking any types of sourceDB or
targetDB?  Right now, it will only take a sql-table type sourceDB or
targetDB.  Error will be raised if I try to pass in an AnnotationDB-type
sourceDB or targetDB.

What steps will reproduce the problem?
>>> import pygr.Data
>>> from ensembl import adaptor
>>> from pygr import sqlgraph

# get the exon AnnotationDB from pygr.Data
>>> exonDB = pygr.Data.Bio.Annotation.Ensembl.homo_sapiens_core_47_36i.exon()
>>> conn = pygr.Data.Bio.Server.Ensembl.Ensembldb()
>>> translationTB =
sqlgraph.SQLTable('homo_sapiens_core_47_36i.translation',
itemClass=sqlgraph.TupleO, serverInfo=conn)
>>> sql_statement = 'SELECT t3.exon_id FROM
homo_sapiens_core_47_36i.translation AS tr,
homo_sapiens_core_47_36i.exon_transcript AS t1,
homo_sapiens_core_47_36i.exon_transcript AS t2,
homo_sapiens_core_47_36i.exon_transcript AS t3 WHERE tr.translation_id = %s
AND tr.transcript_id = t1.transcript_id AND t1.transcript_id =
t2.transcript_id AND t2.transcript_id = t3.transcript_id AND t1.exon_id =
tr.start_exon_id AND t2.exon_id = tr.end_exon_id AND t3.rank >= t1.rank AND
t3.rank <= t2.rank ORDER BY t3.rank'
>>> cursor = translationTB.cursor
>>> translationExons = sqlgraph.GraphView(translationTB, exonDB,
sql_statement, cursor)
>>> translation = translationTB[15121]
>>> exons = translationExons[translation]
>>> for e in exons:
...     print e.id
...
95059
95172
95081
95050
95160
95020
95101
95069
95088
95035
95110

What is the expected output? What do you see instead?

# Since the exonDB is an exon AnnotationDB, each exon from the exonDB is
expected to have a sequence attribute.  But when requested, it raises an
error instead!

>>> for e in exons:
...     print e.id, len(e.squence)
...
95059
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/qing/workspace2008/pygr/pygr/seqdb.py", line 710, in
getAnnotationAttr
    return self.db.getSliceAttr(self.db.sliceDB[self.id], attr)
  File "/home/qing/workspace2008/pygr/pygr/seqdb.py", line 834, in getSliceAttr
    return getattr(sliceInfo,attr) # GET ATTRIBUTE AS USUAL
AttributeError: 'EnsemblRow_homo_sapiens_core_47_36i.exon' object has no
attribute 'squence'

# But when the sequence attribute is requested in the most standard way, it
does return a sequence attribute!
>>> exon = exonDB[95059]
>>> len(exon.sequence)
140

Original issue reported on code.google.com by jqian....@gmail.com on 20 Dec 2008 at 7:32

GoogleCodeExporter commented 8 years ago

Original comment by jqian....@gmail.com on 20 Dec 2008 at 7:40

GoogleCodeExporter commented 8 years ago
based on the error message, it looks like you have a typo in your code 
somewhere:
your error message says "object has no attribute 'squence'".  It should be
'sequence'.  I searched the pygr code for the string 'squence' and found no
occurrences, so I'm reasonably sure this typo is not within the pygr code 
itself...

Original comment by cjlee...@gmail.com on 20 Dec 2008 at 7:38