Skip to content

Commit

Permalink
new app gene_table
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosp420 committed May 15, 2015
1 parent c4e24ce commit deabae9
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 2 deletions.
3 changes: 2 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
amas==0.2
biopython==1.65
Django==1.8.1
pyprind==2.9.1
Expand All @@ -8,4 +9,4 @@ dataset==0.5.6
pytz==2015.2
django-debug-toolbar==1.3.0
django-suit==0.2.13
git+https://github.com/django-haystack/django-haystack.git@bd60745ce82318b1819768c9a31db0579228654d
git+https://github.com/django-haystack/django-haystack.git@bd60745ce82318b1819768c9a31db0579228654d
Empty file added voseq/gene_table/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions voseq/gene_table/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions voseq/gene_table/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from core.forms import BaseDatasetForm


class GeneTableForm(BaseDatasetForm):
pass
Empty file.
3 changes: 3 additions & 0 deletions voseq/gene_table/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
71 changes: 71 additions & 0 deletions voseq/gene_table/templates/gene_table/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{% extends 'public_interface/base.html' %}


{% block additional_css %}
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'css/tooltipster.css' %}" />
{% endblock additional_css %}


{% block content %}
<div class="explorer-container">
<div class="container">
<h3>Create gene table:</h3>

<div class="alert alert-info" role="alert">
<b>Select sequences you want for a dataset by entering the voucher codes and gene codes.</b>
</div>

{% if form.non_field_errors %}
<div class="alert alert-warning" role="alert">
{% for i in form.non_field_errors %}
<b>{{ i }}</b>
{% endfor %}
</div>
{% endif %}


<div class="container">
<div class="row">

<div class="col-xs-12 col-sm-12 col-md-11 col-lg-11 ">

<form action="/create_gene_table/results/" method="post">
<div class="panel panel-primary" style="min-width: 790px;">
<div class="panel-heading">
<h3 class="panel-title"><b>Enter the required info to make yourself a table in MS Excel format</b></h3>
</div>


{% csrf_token %}

<table class="table table-bordered"><!-- big -->
<tr>
<td>

{% include "core/form_taxonset.html" %}

</td>

<td>
{% include 'core/form_geneset.html' %}
</td>

</tr>
</table><!-- big -->

</div><!-- panel -->


</form>


</div><!-- col -->

</div><!-- row -->
</div><!-- container -->


</div>
</div>
{% endblock content %}
94 changes: 94 additions & 0 deletions voseq/gene_table/templates/gene_table/results.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{% extends 'public_interface/base.html' %}


{% block content %}
<div class="explorer-container">
<div class="container">
<h3>Results:</h3>


<div class="container">
<div class="row">

<div class="col-xs-12 col-sm-12 col-md-11 col-lg-11 col-lg-offset-1">


{% if warnings|length > 0 %}
<div class="panel panel-warning" style="min-width: 790px;">
<div class="panel-heading">
<h3 class="panel-title"><b>During the processing of you dataset some issues were raised
<span class="badge"><b>{{ warnings|length }}</b></span>
</b></h3>
</div>

<ul class="list-group">
{% for i in warnings %}
<li class="list-group-item">{{ i }}</li>
{% endfor %}
</ul>
</div><!-- panel -->
{% endif %}


{% if errors|length > 0 %}
<div class="panel panel-danger" style="min-width: 790px;">
<div class="panel-heading">
<h3 class="panel-title"><b>During the processing of you dataset some errors were found
<span class="badge"><b>{{ errors|length }}</b></span>
</b></h3>
</div>

<ul class="list-group">
{% for i in errors %}
<li class="list-group-item">{{ i }}</li>
{% endfor %}
</ul>
</div><!-- panel -->
{% endif %}


<div class="panel panel-primary" style="min-width: 790px;">
<div class="panel-heading">
<h3 class="panel-title"><b>Your dataset file:</b></h3>
</div>

<table class="table table-bordered">
<tr>
<td>
<textarea readonly style="height: 450px;" wrap="off" class="form-control dataset">{{ dataset }}</textarea>
</td>
</tr>
</table>

</div><!-- panel -->

<a href="/create_dataset/results/{{ dataset_file }}">
<button class="btn btn-info">
<i class="fa fa-download"></i>
Download dataset file
</button></a>


<br />
<br />

{% if charset_block %}
<table class="table table-bordered">
<tr>
<td>
<textarea readonly style="height: 150px;" class="form-control" wrap="soft">{{ charset_block }}</textarea>
</td>
</tr>
</table>
{% endif %}


</div><!-- col -->

</div><!-- row -->
</div><!-- container -->


</div>
</div>
{% endblock content %}
3 changes: 3 additions & 0 deletions voseq/gene_table/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
11 changes: 11 additions & 0 deletions voseq/gene_table/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.conf.urls import patterns
from django.conf.urls import url

from . import views


urlpatterns = patterns(
'',
url(r'^/$', views.index, name='index'),
url(r'^/results/$', views.results, name='results'),
)
112 changes: 112 additions & 0 deletions voseq/gene_table/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from collections import OrderedDict
import os
import uuid

from django.shortcuts import render
from amas import AMAS

from .forms import GeneTableForm
from core.utils import get_version_stats
from core.utils import get_voucher_codes
from core.utils import get_gene_codes
from create_dataset.utils import CreateDataset


def index(request):
form = GeneTableForm()

return render(request, 'gene_table/index.html',
{
'form': form,
},
)


def results(request):
version, stats = get_version_stats()
if request.method == 'POST':
form = GeneTableForm(request.POST)
if form.is_valid():
print(">>>>", form.cleaned_data)
table = GeneTable(form.cleaned_data)
print(table.stats)
return render(request, 'gene_table/results.html',
{
'version': version,
'stats': stats,
},
)


class GeneTable(object):
def __init__(self, cleaned_data):
self.cleaned_data = self.populate_cleaned_data_form(cleaned_data)
self.voucher_codes = get_voucher_codes(cleaned_data)
self.gene_codes = get_gene_codes(cleaned_data)
self.fasta_dataset = self.get_fasta_dataset()
self.fasta_partitions = self.split_in_partitions()
self.stats = self.get_stats_from_partitions()

def populate_cleaned_data_form(self, cleaned_data):
cleaned_data['number_genes'] = None
cleaned_data['aminoacids'] = False
cleaned_data['positions'] = ['ALL']
cleaned_data['file_format'] = 'FASTA'
cleaned_data['partition_by_positions'] = 'ONE'
cleaned_data['taxon_names'] = ['CODE', 'GENUS', 'SPECIES']
cleaned_data['outgroup'] = ''
return cleaned_data

def get_fasta_dataset(self):
fasta = CreateDataset(self.cleaned_data)
return fasta.dataset_str

def split_in_partitions(self):
partitions = OrderedDict()

lines = self.fasta_dataset.split('\n')
for line in lines:
this_line = line.replace('>', '')
if this_line in self.gene_codes:
this_gene = this_line
partitions[this_gene] = ''
elif this_line.startswith('---------------'):
continue
else:
partitions[this_gene] += line + '\n'

return partitions

def get_stats_from_partitions(self):
"""These are the stats headers of AMAS v0.2
dna_header = [
"Alignment_name",
"No_of_taxa",
"Alignment_length",
"Total_matrix_cells",
"Undetermined_characters",
"Missing_percent",
"No_variable_sites",
"Proportion_variable_sites",
"Parsimony_informative_sites",
"Proportion_parsimony_informative",
]
"""
in_file = self.make_guid() + '.fas'

for code, partition in self.fasta_partitions.items():
with open(in_file, 'w') as handle:
handle.write(partition)

aln = AMAS.DNAAlignment(in_file, 'fasta', 'dna')
print(aln.summarize_alignment())
print(code, partition)

try:
os.remove(in_file)
except OSError:
pass

def make_guid(self):
return uuid.uuid4().hex
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<li><a href="/blast_new/">Blast new sequence</a></li>
<li><a href="/genes/">View genes</a></li>
<li><a href="/create_dataset/">Create new dataset</a></li>
<li><a href="/create_gene_table/">Create Gene table</a></li>
<li><a href="/genbank_fasta/">Create GenBank FASTA file</a></li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ <h2>Tools:</h2>
<li><a href="/blast_new/">Blast new sequence</a></li>
<li><a href="/genes/">View genes</a></li>
<li><a href="/create_dataset/">Create new dataset</a></li>
<li><a href="/create_gene_table/">Create Gene table</a></li>
<li><a href="/genbank_fasta/">Create Genbank FASTA file</a></li>
</ul>
1 change: 1 addition & 0 deletions voseq/voseq/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'stats',
'view_genes',
'genbank_fasta',
'gene_table',
)

MIDDLEWARE_CLASSES = (
Expand Down
3 changes: 2 additions & 1 deletion voseq/voseq/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

urlpatterns = patterns(
'',
url(r'^create_gene_table', include('gene_table.urls', namespace='gene_table')),
url(r'^create_dataset', include('create_dataset.urls', namespace='create_dataset')),
url(r'^genbank_fasta', include('genbank_fasta.urls', namespace='genbank_fasta')),
url(r'^blast_local', include('blast_local.urls', namespace='blast_local')),
Expand All @@ -11,6 +12,6 @@
url(r'^blast_new', include('blast_new.urls', namespace='blast_new')),
url(r'^genes', include('view_genes.urls', namespace='view_genes')),
url(r'^', include('public_interface.urls', namespace='public_interace')),

url(r'^admin/', include(admin.site.urls)),
)

0 comments on commit deabae9

Please sign in to comment.