-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4e24ce
commit deabae9
Showing
15 changed files
with
309 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ | |
'stats', | ||
'view_genes', | ||
'genbank_fasta', | ||
'gene_table', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters