Commit baa8debd authored by Nijveen, Harm's avatar Nijveen, Harm
Browse files

added functionality to search on marker position

parent d81bffa6
Pipeline #2082 skipped
import os
import re
from django.shortcuts import render_to_response, HttpResponse
from django.conf import settings
from main.models import Experiment, GeneInfo, Species, Marker
from main import utils
# Create your views here.
......@@ -13,7 +14,9 @@ class GeneInfoMarker:
description = ""
gene_name = ""
LOD = 0
chr = 0
start = 0
end = 0
def selectMarker(request):
'''
......@@ -27,7 +30,7 @@ def selectMarker(request):
if request.method == 'GET':
if request.GET.get('experiment_name') and request.GET.get('marker'):
exp_name = request.GET.get('experiment_name')
marker_name = request.GET.get('marker')
query = request.GET.get('marker')
lodthld = Experiment.objects.get(experiment_name=exp_name).lodthld
if request.GET.get('thld'):
......@@ -36,14 +39,42 @@ def selectMarker(request):
except ValueError:
return HttpResponse('<h1> invalid LOD threshold </h1>')
lodscores = getLodScoresForMarker(exp_name, marker_name)
if len(lodscores) == 0:
return HttpResponse('<h1> No information for marker %s</h1>' % marker_name)
marker_name = None
if Marker.objects.filter(name=query, experiment__experiment_name=exp_name):
marker_name = Marker.objects.filter(name=query)[0].name
elif Marker.objects.filter(name__iexact=query, experiment__experiment_name=exp_name):
markers = Marker.objects.filter(name__iexact=query)
marker_name = markers[0].name
elif Marker.objects.filter(name__iexact=query):
markers = Marker.objects.filter(name__iexact=query)
marker = markers[0]
chromosome = marker.chromosome.name
position = marker.start
closestMarker = utils.getClosestMarker(exp_name, chromosome, position)
if closestMarker:
marker_name = closestMarker.name
elif re.match("(chr)?(\d+):(\d+)$", query):
genomicLocation = re.match("(chr)?(\d+):(\d+)$", query)
chromosome = genomicLocation.group(2)
position = genomicLocation.group(3)
closestMarker = utils.getClosestMarker(exp_name, chromosome, position)
if closestMarker:
marker_name = closestMarker.name
elif GeneInfo.objects.filter(gene_id = query):
geneInfo = GeneInfo.objects.get(gene_id = query)
chromosome = geneInfo.chr
position = geneInfo.start
closestMarker = utils.getClosestMarker(exp_name, chromosome, position)
if closestMarker:
marker_name = closestMarker.name
if marker_name == None:
return HttpResponse('<h1> No information for marker %s</h1>' % query)
lodscores = getLodScoresForMarker(exp_name, marker_name)
genes = {g: l for (g, l) in lodscores.items() if l >= lodthld}
# genelist = GeneInfo.objects.filter(gene_id__in = genes.keys())
genelist = list()
for gene in genes:
g = GeneInfoMarker()
......@@ -53,6 +84,9 @@ def selectMarker(request):
if gi:
g.description = gi[0].description
g.gene_name = gi[0].gene_name
g.chr = gi[0].chr
g.start = gi[0].start
g.end = gi[0].end
genelist.append(g)
marker = Marker.objects.get(name = marker_name, experiment__experiment_name=exp_name)
......@@ -69,6 +103,7 @@ def selectMarker(request):
return render_to_response('peakmarker.html', {'experiments': experiments})
def getLodScoresForMarker(experiment, marker):
lod_path = Experiment.objects.get(experiment_name=experiment).lod_file
lod_file_path = os.path.join(settings.MEDIA_ROOT, lod_path)
......
......@@ -131,6 +131,17 @@ genes.push({ "gene": "{{ gene.gene_id }}",
$('form#top_form').submit();
});
$('input#query').keypress(function(e) {
if(e.which == 13) {
$('form#top_form').submit();
}
});
$('input#corrthld').keypress(function(e) {
if(e.which == 13) {
$('form#top_form').submit();
}
});
</script>
{% endblock %}
......
......@@ -140,7 +140,7 @@
textAreaDefaultText = "Input a TAIR ID to find correlating genes";
{% endif %}
{% if mode == 'coregulation' %}
textAreaDefaultText = "Input a marker to find genes that peak";
textAreaDefaultText = "Input marker name or genomic coordinate";
{% endif %}
$('#queryArea').val(textAreaDefaultText);
......
......@@ -35,7 +35,20 @@ def loadGO_OBO(filename):
pass
def getChrMarkers(experiment_name, chromosome):
return Marker.objects.filter(experiment__experiment_name = experiment_name, chr = chromosome)
return Marker.objects.filter(experiment__experiment_name = experiment_name, chromosome__name = chromosome)
def getClosestMarker(experiment_name, chromosome, pos):
pos = int(pos)
markers = getChrMarkers(experiment_name, chromosome)
minDist = -1
closestMarker = None
for marker in markers:
dist = abs(pos - marker.start)
if minDist == -1 or dist < minDist:
minDist = dist
closestMarker = marker
return closestMarker
def getMarkerObjects(experiment_name):
return Marker.objects.filter(experiment__experiment_name = experiment_name)
......
......@@ -18,8 +18,11 @@ def multiplot(request):
species_short_name = Species.objects.get(species_name=species_name).short_name
if request.method == 'GET':
if request.GET.get('experiment_name') and request.GET.get('query'):
exp_name = request.GET.get('experiment_name')
if request.GET.get('query'):
if request.GET.get('experiment_name'):
exp_name = request.GET.get('experiment_name')
else:
exp_name = "all"
query = request.GET.get('query')
query = urllib2.unquote(query).strip()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment