Skip to content

Commit

Permalink
Updated for new Django versions and Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreybarrick committed Mar 20, 2022
1 parent 88c5d03 commit 7d77c38
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
10 changes: 5 additions & 5 deletions efm_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run_mummer(fasta_file, org):
output = subprocess.check_output(['repeat-match', '-n', '16', '-f', fasta_file])
except:
raise
print "MUMmer command 'repeat-match' failed."
print("MUMmer command 'repeat-match' failed.")
output_lines = output.splitlines()
# Loop through mummer output and skip the first 2 lines which only contain header information
for line in output_lines[2:]:
Expand Down Expand Up @@ -71,7 +71,7 @@ def run_mummer(fasta_file, org):
# Initialize list of dictionaries and reformat for tabular output
output_list = []
seen = []
for repeat_length, location_list in long_repeats.iteritems():
for repeat_length, location_list in long_repeats.items():
for locations in location_list:
rate_per_repeat = float(0)
if len(locations) > 2:
Expand Down Expand Up @@ -109,7 +109,7 @@ def run_mummer(fasta_file, org):
output = subprocess.check_output(['show-coords', '-T', '-I 100', '-H', '-d', coords_file.name])
except:
raise
print "MUMmer command 'nucmer' and 'show-coords' failed."
print("MUMmer command 'nucmer' and 'show-coords' failed.")
finally:
# Remove the '.delta' file because we're finished with it
os.remove(coords_file.name)
Expand Down Expand Up @@ -196,7 +196,7 @@ def get_repeats_in_window(n, sequence, min_count, org):

# Reformat for tabular output
output_list = []
for index, contents in repeats.iteritems():
for index, contents in repeats.items():
mut_rate = get_mut_rate(contents[1], n, org)
entry = {'location': [index],
'sequence': str(contents[0]),
Expand Down Expand Up @@ -438,4 +438,4 @@ def process_efm(form):
'title': form.cleaned_data['title'],
'check_features': form.cleaned_data['check_features'],
'organism': org,
'version': EFM_VERSION}
'version': EFM_VERSION}
6 changes: 3 additions & 3 deletions templates/efm/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% if GOOGLE_ANALYTICS_PROPERTY_ID %}
{% include "efm/ga.html" %}
{% endif %}
{% load staticfiles %}
{% load static %}
<link href="{% static 'efm/styles.css' %}" rel="stylesheet" type="text/css" media="all" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
Expand All @@ -29,7 +29,7 @@ <h1 id="banner"></h1>
<h3>Please select a file to upload or enter a sequence into the textbox.</h3>
<p>FASTA, GenBank, or BioBrick XML format files are supported. BioBrick XML files are available from the <a href="http://parts.igem.org/Registry_API" target="_blank">iGEM Registry</a>.</p>
{{ form.non_field_errors }}
<form action="{% url 'efm:index' %}" method="post" enctype="multipart/form-data">
<form action="{% url 'index' %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
<p><input type="button" id="example" value="Click here for an example sequence" /></p>
<p>
Expand Down Expand Up @@ -61,4 +61,4 @@ <h3>Citing the EFM Calculator</h3>
<p>Web view powered by Django and SCRIBL.</p>
</div>
</body>
</html>
</html>
6 changes: 3 additions & 3 deletions templates/efm/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% if GOOGLE_ANALYTICS_PROPERTY_ID %}
{% include "efm/ga.html" %}
{% endif %}
{% load staticfiles %}
{% load static %}
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html">
<title>EFM Calculator</title>
Expand Down Expand Up @@ -173,7 +173,7 @@ <h1 id="banner">Results: {{ title }}</h1>
<h2>RIP score: {{ rate.rip|floatformat }}*</h2>
<p class="note">*(Lower is more stable.)</p>
<div id="csv-button">
<div><a href="{% url 'efm:index' %}">&larr; New Sequence</a></div>
<div><a href="{% url 'index' %}">&larr; New Sequence</a></div>
<div><a href="#" class="export">Download CSV</a></div>
<div><a href="https://github.com/barricklab/efm-calculator/wiki" target="_blank">Help</a></div>
</div>
Expand All @@ -198,7 +198,7 @@ <h2>RIP score: {{ rate.rip|floatformat }}*</h2>
<td>{{ entry.length.0 }}</td>
<td>{{ entry.sequence|default:'&mdash;' }}</td>
<td>{{ entry.count }}</td>
<td>{% if entry.type = 'rmd' %}Repeat mediated deletion{% else %}Simple sequence repeat{% endif %}</td>
<td>{% if entry.type == 'rmd' %}Repeat mediated deletion{% else %}Simple sequence repeat{% endif %}</td>
<td>{{ entry.raw_rate|stringformat:'.2E' }}</td>
</tr>
{% endfor %}
Expand Down
6 changes: 3 additions & 3 deletions urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf.urls import patterns, url
from django.conf.urls import url

from efm import views

urlpatterns = patterns('',
urlpatterns = [
url(r'^$', views.get_sequence, name='index'),
)
]
10 changes: 6 additions & 4 deletions views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from Bio.SeqRecord import SeqRecord
from tempfile import NamedTemporaryFile
import os
from efm_helper import *
#from efm_helper import *

from efm.efm_helper import *

# Create your views here.
class SeqForm(forms.Form):
Expand All @@ -27,7 +29,7 @@ class SeqForm(forms.Form):
check_features = forms.BooleanField(label='Annotated Regions Only', required=False)
check_features.help_text = 'Only assign rates for hypermutable sites that overlap ' \
'with annotated regions. Sequence must be annotated.'

def clean(self):
'''
This is where we detect what type of sequence has been uploaded or placed in in the textbox.
Expand All @@ -51,7 +53,7 @@ def clean(self):
raise forms.ValidationError('File size is too large.')
elif sequence:
with NamedTemporaryFile(delete=False) as data_file:
data_file.write(sequence.strip())
data_file.write(sequence.strip().encode(encoding='UTF-8'))

del cleaned_data['sequence']
del cleaned_data['sequence_file']
Expand Down Expand Up @@ -153,4 +155,4 @@ def get_sequence(request):
else:
form = SeqForm()

return render(request, 'efm/form.html', {'form': form, 'version': EFM_VERSION})
return render(request, 'efm/form.html', {'form': form, 'version': EFM_VERSION})

0 comments on commit 7d77c38

Please sign in to comment.