Пример #1
0
def parseInteractors(dom, network):
	ems = dom.getElementsByTagName("interactor")
	
	interactors = []
	#print "interactor tags %d " %len(ems)
	for em in ems:
		interactor = Entity()
		tmp = em.getElementsByTagName("shortLabel")
		slabel = tmp[0].firstChild.nodeValue.strip()
		slabel = slabel.split('_')[0]
		
		interactor.symbol = slabel		
		interactor.refs = {}		
		
		interactor.name =  getText(em, 'fullName')
		setPrimaryRef(em, interactor)
		if 'uniprotkb' in interactor.refs:
			interactor._id = "enti_up_%s" %(interactor.refs['uniprotkb'])
		else:
			interactor._id = idtool.generate("entity")	
		interactor.refs['intact'] = em.getAttribute('id')
		interactor.group = getText( em.getElementsByTagName("interactorType")[0], 'shortLabel')
		interactors.append(interactor)

	network.entities =  interactors
Пример #2
0
def parseInteractors(dom, network):
    ems = dom.getElementsByTagName("interactor")

    interactors = []
    #print "interactor tags %d " %len(ems)
    for em in ems:
        interactor = Entity()
        tmp = em.getElementsByTagName("shortLabel")
        slabel = tmp[0].firstChild.nodeValue.strip()
        slabel = slabel.split('_')[0]

        interactor.symbol = slabel
        interactor.refs = {}

        interactor.name = getText(em, 'fullName')
        setPrimaryRef(em, interactor)
        if 'uniprotkb' in interactor.refs:
            interactor._id = "enti_up_%s" % (interactor.refs['uniprotkb'])
        else:
            interactor._id = idtool.generate("entity")
        interactor.refs['intact'] = em.getAttribute('id')
        interactor.group = getText(
            em.getElementsByTagName("interactorType")[0], 'shortLabel')
        interactors.append(interactor)

    network.entities = interactors
Пример #3
0
 def __init__(self, data=None):
     if(data):
         if(isinstance(data, dict)):
             for d in data: self.__setattr__(d, data[d])
         else:
             raise Exception("Invalid initialization data: %s" %data)
         #self.update(data)
     else:
         self.create_tm = getTime()
         self.tm = time.time()
     #self.id = self._id if self._id else None
     if not self._id: self._id= idtool.generate(self._col)
Пример #4
0
 def __init__(self, data=None):
     if (data):
         if (isinstance(data, dict)):
             for d in data:
                 self.__setattr__(d, data[d])
         else:
             raise Exception("Invalid initialization data: %s" % data)
         #self.update(data)
     else:
         self.create_tm = getTime()
         self.tm = time.time()
     #self.id = self._id if self._id else None
     if not self._id: self._id = idtool.generate(self._col)
Пример #5
0
def activate(req, post_id=None):
    """
    This handles the case when seller accepts invitation and clicks the link
    """
    post_id = post_id or _getPostId(req)
    post = _getPost(req, post_id)    
    item = Item.collection.find_one({'post_id': post._id})
    
    if(not item):
        item = Item({'hello':1})
        item._id = idtool.generate("item")
        item.post_id = post._id
        item.save()
        #post.sellervisits = post.sellervisits+1 if ('sellervisits' in post) else 1
        #post.mongo_update()
    item.id = item._id
    post.update(item)
    _fillContext(post)
    ctx = getContext()
    ctx.template = 'adedit.html'
    ctx.item = item
    return renderResponse()
Пример #6
0
def load_pubmeds(ids=None):
    ids = ids.split(",") if ids else demo_pubmeds
        
    url = "http://togows.dbcls.jp/entry/pubmed/$ID?format=xml"

    """
    pub={    '_id':'',
            'name':'',
            'refs':{ 'pubmed': '' },
            'abstract':'', 
            'local': 0,  
            'url':'',  
            'published': 1, 
            'authors':[]
            }
    """
    pc = mongo.getCollection('people')
    try:
        pc.create_index([("last", 1), ("middle",1), ("first",1)], unique=True)
    except:
        pass
    
    pubs = []
    peoples = []
    for pid in pubmeds:
        try:
            uri = url.replace('$ID', pid)
            print "Loading %s" %uri
            doc = XML2Dict().fromurl(uri)
            #print doc
            article = doc['PubmedArticleSet']['PubmedArticle']['MedlineCitation']['Article']
            article = doc.PubmedArticleSet.PubmedArticle.MedlineCitation.Article
            
            pub = Publication()
            pub._id = "publ_pubmed%s" % (pid)
            pub.refs= {'pubmed': pid}
            pub.name= article['ArticleTitle']['value'] if article.ArticleTitle else ''
            pub.abstract = ''
            if article.Abstract and article.Abstract.AbstractText:
                texts = [ article.Abstract.AbstractText ] if not isinstance(article.Abstract.AbstractText, list) else article.Abstract.AbstractText
                pub.abstract= "\n\n".join([ text['value'] for text in texts ]) 
                                
            pub.language=article['Language']['value'] if article.Language else ''
            pubs.append(pub) 
            
            pub.authors=[]
            authors = article['AuthorList']['Author']
            for author in authors:
                people = {'first': author.ForeName.value if author.ForeName and author.ForeName.value else '',
                          'last': author.LastName.value if author.LastName and author.LastName.value else '',
                          'middle': author.Initials.value if author.Initials and author.Initials.value else '' }
                if not people['last']: continue             
                people['namekey'] = "%s.%s.%s" %(people['first'].lower(), people['middle'].lower(), people['last'].lower())                
                
                people['_id'] = idtool.generate('peop')
                try:
                    pc.insert(people, safe=True)
                    print "Inserted %s" %people
                except:
                    del people['_id']
                    people = pc.find_one(people)
                if people:
                    pc.update({'_id':people['_id']}, {'$addToSet': {'publications':pub._id}}, safe=True)
                    pub.authors.append(people)                            
            #print authors            
        except:
            print "ERROR: %s" %traceback.format_exc()    
                
            
    pubc = mongo.getCollection('publication')
    for pub in pubs:
        try:
            pubc.insert(pub)
            print "Inserted pub: %s" %pub
        except:
            print "ERROR %s"  %traceback.format_exc()

    log("Done")
    
    return pubs
Пример #7
0
def load_pubmeds(ids=None):
    ids = ids.split(",") if ids else demo_pubmeds

    url = "http://togows.dbcls.jp/entry/pubmed/$ID?format=xml"
    """
    pub={    '_id':'',
            'name':'',
            'refs':{ 'pubmed': '' },
            'abstract':'', 
            'local': 0,  
            'url':'',  
            'published': 1, 
            'authors':[]
            }
    """
    pc = mongo.getCollection('people')
    try:
        pc.create_index([("last", 1), ("middle", 1), ("first", 1)],
                        unique=True)
    except:
        pass

    pubs = []
    peoples = []
    for pid in pubmeds:
        try:
            uri = url.replace('$ID', pid)
            print "Loading %s" % uri
            doc = XML2Dict().fromurl(uri)
            #print doc
            article = doc['PubmedArticleSet']['PubmedArticle'][
                'MedlineCitation']['Article']
            article = doc.PubmedArticleSet.PubmedArticle.MedlineCitation.Article

            pub = Publication()
            pub._id = "publ_pubmed%s" % (pid)
            pub.refs = {'pubmed': pid}
            pub.name = article['ArticleTitle'][
                'value'] if article.ArticleTitle else ''
            pub.abstract = ''
            if article.Abstract and article.Abstract.AbstractText:
                texts = [
                    article.Abstract.AbstractText
                ] if not isinstance(article.Abstract.AbstractText,
                                    list) else article.Abstract.AbstractText
                pub.abstract = "\n\n".join([text['value'] for text in texts])

            pub.language = article['Language'][
                'value'] if article.Language else ''
            pubs.append(pub)

            pub.authors = []
            authors = article['AuthorList']['Author']
            for author in authors:
                people = {
                    'first':
                    author.ForeName.value
                    if author.ForeName and author.ForeName.value else '',
                    'last':
                    author.LastName.value
                    if author.LastName and author.LastName.value else '',
                    'middle':
                    author.Initials.value
                    if author.Initials and author.Initials.value else ''
                }
                if not people['last']: continue
                people['namekey'] = "%s.%s.%s" % (people['first'].lower(),
                                                  people['middle'].lower(),
                                                  people['last'].lower())

                people['_id'] = idtool.generate('peop')
                try:
                    pc.insert(people, safe=True)
                    print "Inserted %s" % people
                except:
                    del people['_id']
                    people = pc.find_one(people)
                if people:
                    pc.update({'_id': people['_id']},
                              {'$addToSet': {
                                  'publications': pub._id
                              }},
                              safe=True)
                    pub.authors.append(people)
            #print authors
        except:
            print "ERROR: %s" % traceback.format_exc()

    pubc = mongo.getCollection('publication')
    for pub in pubs:
        try:
            pubc.insert(pub)
            print "Inserted pub: %s" % pub
        except:
            print "ERROR %s" % traceback.format_exc()

    log("Done")

    return pubs