Changeset 276


Ignore:
Timestamp:
Nov 26, 2009, 2:58:01 PM (10 years ago)
Author:
jjbot
Message:

Parser improvements. Fixed type and set IDs in biomart parser. Added functions and message constants to support the getAccessions query.

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • container/proptypes.py

    r218 r276  
    4141
    4242       if(cls._active_type == itypes_py.AC_ALWAYS or
    43           cls._active_type == itypes_py.AC_FIELDS):
    44             active = True
     43                cls._active_type == itypes_py.AC_FIELDS):
     44           active = True
    4545       elif(cls._active_type == itypes_py.AC_KEEP or
    46             cls._active_type == itypes_py.AC_CHECK):
    47             active = cls._check_active(obj,prop)
     46                cls._active_type == itypes_py.AC_CHECK):
     47           active = cls._check_active(obj,prop)
    4848       else:
    4949           raise RuntimeError, "Unknown active flag in property: " + str(name)
  • parsers/biomart.py

    r275 r276  
    1717
    1818    # Prerequisites: datasets and terms needed to be able to flush this data.
    19     PRER_DS = ['Sequence Ontology', 'Relation Ontology']
     19    PRER_DS = ['Ibidas Ontology', 'Sequence Ontology', 'Relation Ontology']
    2020    PRER_TERMS = table(
    2121        [
     
    5858        locations = self.mart[:, self.LOCATION_FN]
    5959        names = locations.fields.name().tolist()
    60         print len(locations)
    6160        locations = locations.union(locations)
    6261        locations.fname(*names)
    63         print len(locations)dd
    6462        # Deal with real location
    6563
  • parsers/fasta.py

    r216 r276  
    55there are different definition files.
    66Currently supported: dbSNP and SwissProt. More to come soon.
    7 @author: Jan Bot
     7@author: Jan Bot <J.J.Bot@tudelft.nl>
    88@author: Patrick van Kouteren <H.J.W.vanKouteren@student.tudelft.nl>
    99@version: 0.1
  • web/IbidasAtomicServices2.py

    r274 r276  
    7070            item_type_ids = [int(x) for x in args['itemtypes']]
    7171            query = query[_.type_id.within(*item_type_ids)]
     72        query = query[:, IbidasSimpleMessage.ITEM_FN]
    7273        self.logger.debug("Returning query")
    7374        return query
     
    8990        #    type_ids = [int(x) for x in args['itemrelationtypes']]
    9091        #    query = query[_.type_id.within(*type_ids)]
     92        query = query[:, IbidasSimpleMessage.ITEMLINK_FN]
    9193        self.logger.debug("Returning query")
    9294        return query
     
    139141        parents = self.__addItemConstraints(parents, args)
    140142        links = links.join(parents, 'parent_id', 'item_id').up()
     143        links = links[:, msg.ITEMLINK_FN]
     144        parents = parents[:, msg.ITEM_FN]
    141145        self.logger.debug("Nr of parents found: " + str(len(parents)))
    142146       
     
    151155        self.logger.debug("getItemNeighbours")
    152156        self.logger.debug("Provided arguments: " + str(args.keys()))
    153         print args
    154157        items = args['items']
    155158        msg = IbidasSimpleMessage()
     
    158161
    159162        links = self.cd.item_child_link.join(items, 'parent_id', 'item_id').up()
     163        links = links[:, msg.ITEMLINK_FN]
    160164        msg.addItemLinks(links)
    161165        items = self.cd.item.join(links, 'item_id', 'child_id').up()
     166        items = items[:, msg.ITEM_FN]
    162167        msg.addItems(items)
    163168       
    164169        links = self.cd.item_child_link.join(items, 'child_id', 'item_id').up()
     170        links = links[:, msg.ITEMLINK_FN]
    165171        msg.addItemLinks(links)
    166172        items = self.cd.item.join(links, 'item_id', 'parent_id').up()
     
    203209        msg = IbidasSimpleMessage()
    204210        sets = self.cd.set[_.set_id.within(*ids)]
     211        sets = sets[:, msg.SET_FN]
    205212        msg.addSets(sets)
    206213        return msg.finalize()
     
    209216        msg = IbidasSimpleMessage()
    210217        sets = self.cd.set[_.name.within(*names)]
     218        sets = sets[:, msg.SET_FN]
    211219        msg.addSets(sets)
    212220        return msg.finalize()
     
    227235        items = self.cd.item[_.source_id.within(*source_ids)]
    228236        #items = self.__addItemConstraints(items, args)
     237        items = items[:, msg.ITEM_FN]
    229238        items = items[0:500] # needed for testing
    230239        msg.addItems(items)
     
    235244        l1 = l1.join(items, 'child_id', 'item_id').up()
    236245        #l1 = l1.join(items, 'parent_id', 'item_id').up()
     246        l1 = l1[:, msg.ITEMLINK_FN]
    237247        msg.addItemLinks(l1)
    238248
     
    242252        l2 = l2.join(items, 'parent_id', 'item_id').up()
    243253        #l2 = l2.join(items, 'child_id', 'item_id').up()
     254        l2 = l2[:, msg.ITEMLINK_FN]
    244255        msg.addItemLinks(l2)
    245256       
     257        return msg.finalize()
     258
     259    def getItemAccessions(self, args):
     260        """Finds all accessions belonging to a list of items."""
     261        self.logger.debug("Called getItemAccessions")
     262        assert args.has_key('items'), \
     263                "No items provided to get accessions for."
     264        msg = IbidasSimpleMessage()
     265        item_ids = [int(x) for x in args['items']]
     266        self.logger.debug("item_ids: " + str(item_ids))
     267        items = self.cd.item[_.item_id.within(*item_ids)]
     268        accessions = self.cd.item_prop_accession.join(items, 'item_id', 'item_id').up()
     269        accessions = accessions[:, msg.ITEMAC_FN]
     270        msg.addItemAccessions(accessions)
    246271        return msg.finalize()
    247272
  • web/IbidasSimpleMessage.py

    r274 r276  
    1111    return m
    1212
     13
    1314class IbidasSimpleMessage(object):
     15    """Container for all information comming from Ibidas to be send to
     16    a remote host."""
    1417   
    1518    ITEM_STR        = 'items'
    1619    ITEM_FN_STR     = 'item_fn'
    1720    ITEM_FT_STR     = 'item_ft'
     21    ITEMAC_STR      = 'itemaccessions'
     22    ITEMAC_FN_STR   = 'itemaccession_fn'
     23    ITEMAC_FT_STR     = 'itemaccession_ft'
    1824    ITEMLINK_STR    = 'itemlinks'
    1925    ITEMLINK_FN_STR = 'itemlink_fn'
     
    3339   
    3440    ITEM_FN = ('item_id', 'source_id', 'type_id', 'display_name')
     41    ITEMAC_FN = ('type_id', 'source_id', 'item_id', 'value')
    3542    ITEMLINK_FN = ('item_link_id', 'type_id', 'source_id',
    3643            'parent_id', 'child_id')
     
    4148   
    4249    def __init__(self):
    43         self.items      = None
    44         self.itemlinks  = None
    45         self.terms      = None
    46         self.termlinks  = None
    47         self.sets       = None
    48         self.setlinks   = None
     50        self.items          = None
     51        self.itemaccessions = None
     52        self.itemlinks      = None
     53        self.terms          = None
     54        self.termlinks      = None
     55        self.sets           = None
     56        self.setlinks       = None
    4957
    50         self.item_fn        = colMap(self.ITEM_FN)
    51         self.itemlink_fn    = colMap(self.ITEMLINK_FN)
    52         self.term_fn        = colMap(self.TERM_FN)
    53         self.termlink_fn    = colMap(self.TERMLINK_FN)
    54         self.set_fn         = colMap(self.SET_FN)
    55         self.setlink_fn     = colMap(self.SETLINK_FN)
     58        self.item_fn            = colMap(self.ITEM_FN)
     59        self.itemaccession_fn   = colMap(self.ITEMAC_FN)
     60        self.itemlink_fn        = colMap(self.ITEMLINK_FN)
     61        self.term_fn            = colMap(self.TERM_FN)
     62        self.termlink_fn        = colMap(self.TERMLINK_FN)
     63        self.set_fn             = colMap(self.SET_FN)
     64        self.setlink_fn         = colMap(self.SETLINK_FN)
    5665
    5766    def addItems(self, cont):
     
    6170        else:
    6271            self.items = cont
     72
     73    def addItemaccessions(self, cont):
     74        print "addItemaccessions called"
     75        if not self.itemaccessions is None:
     76            self.itemaccessions = self.itemaccessions.stack(cont)
     77        else:
     78            self.itemaccessions = cont
    6379
    6480    def addItemLinks(self, cont):
     
    112128
    113129        out = {}
     130        # FIXME: should set a constraint on the maximum number of entries that can be send
     131        # might be better to handle that in the addItem etc. functions.
    114132        if not self.items is None:
    115133            out[self.ITEM_STR] = self.items.to_python()
    116134            out[self.ITEM_FN_STR] = self.item_fn
    117135            out[self.ITEM_FT_STR] = [str(x) for x in self.items.fields.type()]
     136        if not self.itemaccessions is None:
     137            out[self.ITEMAC_STR] = self.itemaccessions.to_python()
     138            out[self.ITEMAC_FN_STR] = self.itemaccession_fn
     139            out[self.ITEMAC_FT_STR] = [str(x) for x in self.itemaccessions.fields.type()]
    118140        if not self.itemlinks is None:
    119141            out[self.ITEMLINK_STR] = self.itemlinks.to_python()
Note: See TracChangeset for help on using the changeset viewer.