<commit_before>#! /usr/bin/env python

# 2014-2015 <NAME>-<NAME>

from __future__ import print_function, division
import click
from flask import Flask, render_template, request
from tempfile import NamedTemporaryFile
import os
import gzip
import json
from readfq import readfq
import maze

app = Flask(__name__)
cfg = {}

@app.route('/')
def index():
    return render_template('index.html')

def opener(fn):
    if fn.endswith('.gz'):
        return gzip.open
    return open

@app.route('/matches')
def data():
    length = request.args.get('length', type=int)
    matches = request.args.get('matches')
    d = []
    with opener(cfg['reference'])(cfg['reference']) as f:
        rname, rseq, _ = next(readfq(f))
        with NamedTemporaryFile(delete=False) as f_ref:
            fn_ref = f_ref.name
            print('>{}'.format(rname), file=f_ref)
            print(rseq, file=f_ref)
    with opener(cfg['query'])(cfg['query']) as f:
        for qname, qseq, _ in readfq(f):
            with NamedTemporaryFile(delete=False) as f_query:
                fn_query = f_query.name
                print('>{}'.format(qname), file=f_query)
                print(qseq, file=f_query)
            matches = maze.mummer_matches(fn_ref,
                                          fn_query,
                                          length,
                                          matches,
                                          cfg['debug'])
            d.append({
                'rname': rname,
                'rseq': rseq,
                'qname': qname,
                'qseq': qseq,
                'matches': matches
            })
            os.remove(fn_query)
    os.remove(fn_ref)
    # FIXME just testing spinner...<commit_msg>Fix bug that occurs with multiple queries<commit_after>#! /usr/bin/env python

# 2014-2015 <NAME>-<NAME>

from __future__ import print_function, division
import click
from flask import Flask, render_template, request
from tempfile import NamedTemporaryFile
import os
import gzip
import json
from readfq import readfq
import maze

app = Flask(__name__)
cfg = {}

@app.route('/')
def index():
    return render_template('index.html')

def opener(fn):
    if fn.endswith('.gz'):
        return gzip.open
    return open

@app.route('/matches')
def data():
    length = request.args.get('length', type=int)
    match_type = request.args.get('matches')
    d = []
    with opener(cfg['reference'])(cfg['reference']) as f:
        rname, rseq, _ = next(readfq(f))
        with NamedTemporaryFile(delete=False) as f_ref:
            fn_ref = f_ref.name
            print('>{}'.format(rname), file=f_ref)
            print(rseq, file=f_ref)
    with opener(cfg['query'])(cfg['query']) as f:
        for qname, qseq, _ in readfq(f):
            with NamedTemporaryFile(delete=False) as f_query:
                fn_query = f_query.name
                print('>{}'.format(qname), file=f_query)
                print(qseq, file=f_query)
            matches = maze.mummer_matches(fn_ref,
                                          fn_query,
                                          length,
                                          match_type,
                                          cfg['debug'])
            d.append({
                'rname': rname,
                'rseq': rseq,
                'qname': qname,
                'qseq': qseq,
                'matches': matches
            })
            os.remove(fn_query)
    os.remove(fn_ref)
    # FIXME just testing spinner...
{'fraction_non_alphanumeric': 0.11788154897494305, 'fraction_numerical': 0.004555808656036446, 'mean_word_length': 1.7683215130023642, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2231012', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1010, 'n_words': 241}