def apply_article_metadata(article = None):
    if article:
        artObs = [article]
        num_arts = 1
    else:
    #    artObs = m.Article.objects.filter(metadata__isnull = True, articlefulltext__isnull = False).distinct()
        artObs = m.Article.objects.filter(articlefulltext__isnull = False).distinct()
    #    artObs = artObs.exclude(articlefulltext__articlefulltextstat__metadata_processed = True)


    #    artObs = m.Article.objects.filter(articlefulltext__isnull = False, articlefulltext__articlefulltextstat__methods_tag_found = True).distinct()
    #    artObs = artObs.exclude(articlefulltext__articlefulltextstat__metadata_processed = True)
    #    artObs = artObs.exclude(articlefulltext__articlefulltextstat__metadata_human_assigned = True)
        num_arts = artObs.count()
        print 'annotating %s articles for metadata...' % num_arts
    for i,art in enumerate(artObs):
        if not article:
            prog(i,num_arts)
        assign_metadata.assign_species(art)
        assign_metadata.assign_electrode_type(art)
        assign_metadata.assign_strain(art)
        assign_metadata.assign_rec_temp(art)
        assign_metadata.assign_prep_type(art)
        assign_metadata.assign_animal_age(art)
        assign_metadata.assign_jxn_potential(art)
        assign_metadata.assign_solution_concs(art)
        aft_ob = art.get_full_text()
        aftStatOb = m.ArticleFullTextStat.objects.get_or_create(article_full_text = aft_ob)[0]
        aftStatOb.metadata_processed = True
        aftStatOb.save()
Esempio n. 2
0
def loadEdges():
	with open('neurotree/data/dumpedges.php','rU') as f:
		reader = csv.reader(f)
		junk = reader.next() # Skip headers . 
		junk = reader.next() # Skip headers . 
		rows = list(reader)
		n_rows = len(rows)
		with transaction.commit_on_success():
			for i,row in enumerate(rows):
				prog(i,n_rows)
				try:
					node1 = m.Node.objects.get(id=int(row[0]))
					node2 = m.Node.objects.get(id=int(row[2]))
				except:
					print "One of these nodes not found: %d,%d" % \
							(int(row[0]),int(row[2]))
					pass 
					# Nodes probably did not exist.  
					# There are some edges in the file with node id's
					# that are not in the dumpnodes.php file.  
				else:
					edge,created = m.Edge.objects.get_or_create(
									node1=node1,
									node2=node2,
									defaults={'relationcode':row[1],
											  'relationstring':row[3],
											  'stopyear':int(row[4])})
def assign_neuroner_ids():
    """Iterate through all neuron concept maps and assign neuroner ontology ids"""

    ncms = m.NeuronConceptMap.objects.filter(times_validated__gt = 0)

    # actually update objects
    cm_expert_list_len = len(ncms)
    for i,cm in enumerate(ncms):
        prog(i,cm_expert_list_len)
        if cm.neuron_long_name:
            neuron_pref_name = cm.neuron_long_name
        else:
            neuron_pref_name = cm.neuron.name
        neuroner_ids = get_neuroner_annotations(neuron_pref_name)

        json_neuroner_ids = json.dumps(neuroner_ids)

        # if annotations are unchanged, then don't save and continue
        # TODO: fix the below, doesn't seem to work
        if set(neuroner_ids) == set(cm.get_neuroner()):
            #print 'existing neuroner ids, moving on'
            continue
        print 'adding new neuroner id to pk %s: ' % cm.pk

        cm.neuroner_ids = json_neuroner_ids

        # don't actually update the changed date
        hcm = cm.history.all()[0]
        cm._history_date = hcm.history_date
        cm.save(new_history_time = True)
Esempio n. 4
0
def graphviz_dot_plus_grandparents(author_list_full, 
								   authors, 
								   max_path_length=2):
	"""After running this, run: 
	dot -Tpdf -Gcharset=latin1 authors.dot -o authors.pdf
	on the command line."""
	f = open('authors.dot','w')
	f.write('digraph G {\r\n')
	for i,author1 in enumerate(author_list_full):
		prog(i,len(author_list_full))
		f.write('\t%s\r\n' % clean(author1.lastname))
		if author1 in authors:
			f.write('\t%s\r[fillcolor = red]\r\n' % clean(author1.lastname))
		for author2 in author_list_full:
			if author1 == author2:
				continue
			path = shortest_path(author1,
            					 author2,
            					 directions=['up'],
            					 max_path_length=max_path_length)
			if path is not None:
				#f.write('\t%s->%s\r\n' % (clean(author1.lastname),clean(author2.lastname)))
				for j in range(len(path)-1):
					f.write('\t%s->%s\r\n' % \
						(clean(path[j].lastname),clean(path[j+1].lastname)))
				print path
	f.write('}')
	f.close()    
def assign_stat_object_to_data_tables():
    """go through each data table object and add info about who curated and when"""

    dts = m.DataTable.objects.filter(datasource__ephysconceptmap__isnull=False)

    num_dts = dts.count()
    for i, dt in enumerate(dts):
        print "updating data tables with summary objects"
        prog(i, num_dts)
        update_data_table_stat(dt)
Esempio n. 6
0
def author_path_length_matrix(authors):
	import neurotree.neurotree_author_search as search
	import numpy as np
	#authors = search.get_neurotree_authors()[0]
	matrix = np.zeros((len(authors),len(authors)))
	for i in range(len(authors)):
		prog(i,len(authors))
		for j in range(len(authors)):
			path = shortest_path(authors[i],authors[j],
								 directions=['up'],max_path_length=3)
			matrix[i,j] = len(path) if path is not None else None
	return matrix
Esempio n. 7
0
def get_author_grandparents(authors):
    """
    Returns a list of neurotree nodes corresponding to academic 
    grandparents of input neurotree nodes
    """
    author_list_initial = authors
    num_authors = len(authors)
    author_list_final = []
    relationcodes = [1, 2]
    for i,a in enumerate(author_list_initial):
        prog(i,num_authors)
        a_relations = a.parents.filter(relationcode__in=relationcodes)
        parent_nodes = [x.node2 for x in a_relations]
        #print parent_nodes
        author_list_final.extend(parent_nodes)
        for p in parent_nodes:
            p_relations = p.parents.filter(relationcode__in=relationcodes)
            grand_parent_nodes = [y.node2 for y in p_relations]
            author_list_final.extend(grand_parent_nodes)
    author_list_final.extend(author_list_initial)
    return list(set(author_list_final))
Esempio n. 8
0
def loadNodes():
	with open('neurotree/data/dumpnodes.php','rU') as f:
		reader = csv.reader(f)
		junk = reader.next() # Skip leading blank line.  
		junk = reader.next() # Skip header.  
		rows = list(reader)
		n_rows = len(rows)
		with transaction.commit_on_success():
			for i,row in enumerate(rows):
				#if float(i)/n_rows < 0.6:
				#	continue
				prog(i,n_rows)
				if len(row)<7: # Probably the last line (blank).
					continue
				trees = []
				tree_names = row[6].split('+')
				for tree_name in tree_names:
					tree,created = m.Tree.objects.get_or_create(name=tree_name)
					trees.append(tree)

				firstname = row[1].decode('latin1')
				middlename = row[2].decode('latin1')
				lastname = row[3].decode('latin1')
				location = row[4].decode('latin1')
				altpubmed = row[5].decode('latin1')
				#global row_
				#row_ = row
				#print firstname,middlename,lastname,location
				node,created = m.Node.objects.get_or_create(id=row[0],
											 defaults={'firstname':firstname,
										   			   'middlename':middlename,
										   			   'lastname':lastname,
										   			   'location':location,
										   			   'altpubmed':altpubmed})
				for tree in trees: 
					node.tree.add(tree)