Exemplo n.º 1
0
def check_form_validity_and_convert_to_tasks(data):
    tasks = []
    for key in data.keys(): 
        if key.endswith('_cb'):
            task_key = key[:-3]
            genes_key = task_key + '_genes'
            comment_key = task_key + '_comment'
            
            task_type = get_task_type_by_key(task_key[task_key.find('_')+1:]) 

            if genes_key in data:
                genes = data[genes_key]
                gene_names = genes.replace(',',' ').replace('|',' ').replace(';',' ').replace(':',' ').split()
                
                #Certain tasks must have genes.
                if task_type_is_gene_specific(task_type) and len(gene_names) == 0:
                    raise NoGeneNamesException(task_key)
            else:
                gene_names = [] 
                
            if comment_key in data:
                comment = data[comment_key]
            else:
                comment = '';
                                
            task = Task(task_type, gene_names, comment)   
            tasks.append(task)
            
    log_it('Basic', 'SUCCESS')
    
    #Each gene should be associated with only one topics.
    gene_topic = {}
    genes_with_multiple_topics = []
    for task in tasks:
        for gene in task.gene_names:
            if gene in gene_topic and gene_topic[gene] != task.topic:
                genes_with_multiple_topics.append(gene)
            gene_topic[gene] = task.topic
            
    if len(genes_with_multiple_topics) > 0:
        raise GenesWithMultipleTopicsException(genes_with_multiple_topics)
    log_it('Only one topic', 'SUCCESS')
                  
    
    #If Review is checked without genes, the gene specific tasks should not be checked.
    gene_specific_checked = False
    review_checked_without_genes = False
    for task in tasks:
        if task.type == TaskType.REVIEWS and len(task.gene_names) == 0:
            review_checked_without_genes = True
        if task_type_is_gene_specific(task.type):
            gene_specific_checked = True
    if review_checked_without_genes and gene_specific_checked:
        raise ReviewCheckedWithoutGenesException()
    log_it('Review check', 'SUCCESS')
    
    return tasks
Exemplo n.º 2
0
    def f(session):
        reftemp = get_first(RefTemp, session, pubmed_id=pubmed_id)
        log_it('got_reftemp', 'SUCCESS')
        if reftemp is None:
            raise RefDoesNotExistException(pubmed_id)
        ref = Reference(session, pubmed_id=pubmed_id)
        log_it('created reference', 'SUCCESS')
            
        session.add(ref)
        session.delete(reftemp)
        log_it('adjusted session', 'SUCCESS')

        return True
Exemplo n.º 3
0
def link_ref(pmid):
    log_it_info('link_ref', 'BEGIN', str(pmid))
    response = ""
    try:
        check_for_other_users(current_user.name)
        log_it('check_for_other_users', 'SUCCESS')
        
        #if request.method == "POST":
        tasks = check_form_validity_and_convert_to_tasks(request.form) 
        log_it('check_form_validity_and_convert_to_tasks', 'SUCCESS', str(tasks))

        model.execute(link_paper(pmid, tasks), current_user.name, commit=True)   
        log_it('link_paper', 'SUCCESS')
            
        #Link successful
        summary = model.execute(get_ref_summary(pmid), current_user.name)  
        response = summary
        log_it_info('link_ref', 'SUCCESS')
    except Exception as e: 
        response = "Error:<br>" + e.message;
        log_it_info('link_ref', 'FAILURE')
    return response
Exemplo n.º 4
0
    def f(session):
        log_it('validate_genes', 'BEGIN')
        all_gene_names = set()
        for task in tasks:
            all_gene_names.update([gene_name.upper() for gene_name in task.gene_names])
    
        genes = validate_genes(all_gene_names, session)
        log_it('validate_genes', 'SUCCESS')
    
        log_it('move_reftemp_to_ref', 'BEGIN')
        #If some of the gene names are aliases or are just not gene names, throw an exception.
        if len(genes['aliases']) > 0 or len(genes['not_genes']) > 0:
            raise GeneNamesNotFountException(genes['alias_message'], genes['not_genes_message'])
    
        #Move reftemp to ref table. Raise an exception if something goes wrong.
        moved = move_reftemp_to_ref(pmid, session)
        if not moved:
            raise ReferenceNotMovedException(pmid)    
        log_it('move_reftemp_to_ref', 'SUCCESS')

        log_it('associate', 'BEGIN')
        #Associate reference with LitGuide and RefCuration objects. Raise an exception if something goes wrong.
        associated = associate(pmid, genes['features'], tasks, session)
        if not associated:
            raise AssociateException(pmid)
        return True
        log_it('associate', 'SUCCESS')
Exemplo n.º 5
0
 def __init__(self, session, pubmed_id):
     self.pubmed_id = pubmed_id
     self.pdf_status='N'
     self.source='Curator Triage'
     self.created_by = session.user
     self.date_created = datetime.datetime.now()
     
     pubmed = get_medline_data(pubmed_id)
     log_it('Got medline data', 'SUCCESS')
         
     #Set basic information for the reference.
     self.status = pubmed.publish_status
     self.citation = pubmed.citation
     self.year = pubmed.year
     self.pdf_status = pubmed.pdf_status
     self.page = pubmed.pages
     self.volume = pubmed.volume
     self.title = pubmed.title
     self.issue = pubmed.issue
     self.date_published = pubmed.date_published
     self.date_revised = pubmed.last_revised
     log_it('Basic info', 'SUCCESS')
                     
     #Add the journal.
     self.journal = Journal.as_unique(session, abbreviation=pubmed.journal_abbrev)
     log_it('Got journal', 'SUCCESS')
     
     #Add the abstract.
     if pubmed.abstract_txt is not None and not pubmed.abstract_txt == "": 
         self.abst = Abstract.as_unique(session, reference_id = self.id, text = pubmed.abstract_txt)
     log_it('Add abstract', 'SUCCESS')
            
     #Add the authors.
     order = 0
     for author_name in pubmed.authors:
         order += 1
         self.authors[order] = Author.as_unique(session, name=author_name)
     log_it('Add authors', 'SUCCESS')
             
     #Add the ref_type
     for name in pubmed.pub_types:
         self.refTypes.append(RefType.as_unique(session, name=name))
     log_it('Add reftype', 'SUCCESS')
Exemplo n.º 6
0
    def f(session):
        if gene_names is not None and len(gene_names) > 0:
            upper_gene_names = [x.upper() for x in gene_names]
            fs_by_name = set(session.query(Feature).filter(func.upper(Feature.name).in_(upper_gene_names)).filter(Feature.type != 'chromosome').all())
            fs_by_gene_name = set(session.query(Feature).filter(func.upper(Feature.gene_name).in_(upper_gene_names)).filter(Feature.type != 'chromosome').all())
            
            log_it('DB_query', 'SUCCESS')
            all_names_left = set(upper_gene_names)
      
            #Create table mapping name -> Feature        
            name_to_feature = {}
            for f in fs_by_name:
                name_to_feature[f.name.upper()] = f
            for f in fs_by_gene_name:
                name_to_feature[f.gene_name.upper()] = f
    
            all_names_left.difference_update(name_to_feature.keys())
            
            if len(all_names_left) > 0:
                aliases = session.query(Alias).filter(func.upper(Alias.name).in_(all_names_left)).all()
            else:
                aliases = []
            log_it('Create table mapping feature', 'SUCCESS')

            #Create table mapping name -> Alias
            name_to_alias = {}
            for a in aliases:
                features = [f for f in a.features if f.type != 'chromosome']
                if len(features) > 0:
                    if a.name in name_to_alias:
                        name_to_alias[a.name.upper()].update(features)
                    else:
                        name_to_alias[a.name.upper()] = set(features)
            log_it('Create table mapping alias', 'SUCCESS')
                        
            #This may be a gene name with p appended
            p_endings = [word[:-1] for word in all_names_left if word.endswith('P')]
            p_ending_fs_by_name = set()
            p_ending_fs_by_gene_name = set()
            if len(p_endings) > 0:
                p_ending_fs_by_name.update(session.query(Feature).filter(func.upper(Feature.name).in_(p_endings)).filter(Feature.type != 'chromosome').all())
                p_ending_fs_by_gene_name.update(session.query(Feature).filter(func.upper(Feature.gene_name).in_(p_endings)).filter(Feature.type != 'chromosome').all())
            
            all_names_left.difference_update(name_to_alias.keys())
            log_it('p appended', 'SUCCESS')
             
            #Add to Alias table all p-ending gene names
            for p_ending in p_ending_fs_by_name:
                word = p_ending.name + 'P'
                if word in name_to_alias:
                    name_to_alias[word.upper()].add(p_ending)
                else:
                    name_to_alias[word.upper()] = set([p_ending])
                    
            for p_ending in p_ending_fs_by_gene_name:
                word = p_ending.gene_name + 'P'
                if word in name_to_alias:
                    name_to_alias[word.upper()].add(p_ending)
                else:
                    name_to_alias[word.upper()] = set([p_ending])
            log_it('Add to alias table', 'SUCCESS')
                               
            alias_message = create_alias_message(name_to_alias)
            feature_message = create_feature_message(name_to_feature)
            not_genes_message = create_not_genes_message(all_names_left)
            log_it('Create messages', 'SUCCESS')
               
            return {'features':name_to_feature, 'aliases':name_to_alias, 'not_genes':all_names_left, 'alias_message':alias_message, 'feature_message':feature_message, 'not_genes_message':not_genes_message}
        else:
            return {'features':{}, 'aliases':{}, 'not_genes':set(), 'alias_message':'', 'feature_message':'', 'not_genes_message':''}