Beispiel #1
0
def chemspectra_predict_by_peaks_form():
    layout = request.form.get('layout', default=None)
    peaks = request.form.get('peaks', default='{}')
    peaks = json.loads(peaks)
    shift = request.form.get('shift', default='{}')
    shift = json.loads(shift)
    molfile = FileContainer(request.files['molfile'])
    mm = MoleculeModel(molfile, layout, decorate=True)

    if not peaks:
        spectrum = FileContainer(request.files['spectrum'])
        if spectrum and layout == '13C':
            cv = TraModel(spectrum, molfile=molfile, params={'ext': 'jdx'}).to_converter()
            peaks = parse_array_to_dict_xys(cv.edit_peaks)

    if (not peaks) or (not molfile):
        abort(400)

    outcome = InferModel.predict_nmr(
        mm=mm,
        layout=layout,
        peaks=peaks,
        shift=shift
    )
    if outcome:
        return jsonify(outcome)
    abort(400)
Beispiel #2
0
def __generated_jcamp_temp(path, params=False):
    with open(path, 'rb') as f:
        file = FileContainer(FileStorage(f))
        molfile = FileContainer(FileStorage(None))
        nicv, nicp = TraModel(file, molfile, params).jcamp2cvp()
        jcamp = nicp.tf_jcamp()
    return nicv, nicp, jcamp
Beispiel #3
0
def jcamp():
    file = FileContainer(request.files['file'])
    molfile = FileContainer(request.files.get('molfile'))
    params = extract_params(request)
    if file:  # and allowed_file(file):
        tf_jcamp = TraModel(file, molfile=molfile, params=params).convert2jcamp()
        return send_file(
            tf_jcamp,
            attachment_filename='spectrum.jdx',
            as_attachment=True
        )
def __generated_peaks_meta(orig_filename, params=False):
    with open(target_dir + source_dir + orig_filename, 'rb') as f:
        file = FileContainer(FileStorage(f))
        molfile = FileContainer(FileStorage(None))
        _, nicp = TraModel(file, molfile, params).jcamp2cvp()

    parts = ''.join(nicp.meta).split(separator)
    assert len(parts) == 2

    meta_content = parts[1]
    return meta_content
Beispiel #5
0
def image():
    file = FileContainer(request.files['file'])
    molfile = FileContainer(request.files.get('molfile'))
    params = extract_params(request)
    if file:  # and allowed_file(file):
        tf_img = TraModel(file, molfile=molfile, params=params).convert2img()
        return send_file(
            tf_img,
            attachment_filename='spectrum.png',
            as_attachment=True,
            mimetype='image/png'
        )
Beispiel #6
0
def zip_image():
    file = FileContainer(request.files['file'])
    molfile = FileContainer(request.files.get('molfile'))
    params = extract_params(request)
    if file:  # and allowed_file(file):
        tf_img = TraModel(file, molfile=molfile, params=params).convert2img()
        memory = to_zip_response([tf_img])
        return send_file(
            memory,
            attachment_filename='spectrum.zip',
            as_attachment=True
        )
Beispiel #7
0
def chemspectra_file_convert():
    file = FileContainer(request.files['file'])
    molfile = FileContainer(request.files.get('molfile'))
    params = extract_params(request)
    if file:
        tf_jcamp, tf_img = TraModel(file, molfile=molfile,
                                    params=params).convert2jcamp_img()
        if not tf_jcamp:
            abort(400)
        jcamp = base64.b64encode(tf_jcamp.read()).decode("utf-8")
        img = base64.b64encode(tf_img.read()).decode("utf-8")
        return jsonify(status=True, jcamp=jcamp, img=img)
Beispiel #8
0
def chemspectra_predict_infrared():
    layout = request.form.get('layout', default=None)
    spectrum = FileContainer(request.files['spectrum'])
    molfile = FileContainer(request.files['molfile'])
    mm = MoleculeModel(molfile, layout)

    outcome = InferModel.predict_ir(
        mm=mm,
        spectrum=spectrum
    )
    if outcome:
        return jsonify(outcome)
    abort(400)
Beispiel #9
0
def chemspectra_predict_ms():
    layout = request.form.get('layout', default=None)
    spectrum = FileContainer(request.files['spectrum'])
    molfile = FileContainer(request.files['molfile'])
    mm = MoleculeModel(molfile, layout)
    tm = TraModel(spectrum, molfile=None, params={'ext': 'jdx'}).to_composer()

    outcome = InferModel.predict_ms(
        mm=mm,
        tm=tm
    )
    if outcome:
        return jsonify(outcome)
    abort(400)
Beispiel #10
0
def chemspectra_file_refresh():
    # src = FileContainer(request.files['src'])
    dst = FileContainer(request.files['dst'])
    molfile = FileContainer(request.files.get('molfile'))
    # filename = request.form.get('filename', default=None)
    params = extract_params(request)
    if dst:  # and allowed_file(file):
        tm = TraModel(dst, molfile=molfile, params=params)
        tf_jcamp, tf_img = tm.convert2jcamp_img()
        if not tf_jcamp:
            abort(400)
        jcamp = base64.b64encode(tf_jcamp.read()).decode("utf-8")
        img = base64.b64encode(tf_img.read()).decode("utf-8")
        return jsonify(status=True, jcamp=jcamp, img=img)
Beispiel #11
0
def test_molfile2chem():
    with open(target_dir + source_dir + '/molfile/svs813f1_B.mol', 'rb') as f:
        molfile = FileContainer(FileStorage(f))
        mm = MoleculeModel(molfile)

    assert mm.smi == 'CCC1CCC(=O)C(C)C12SCCS2'
    assert mm.mass == 230.079907196
def zip_jcamp_n_img():
    file = FileContainer(request.files['file'])
    molfile = FileContainer(request.files.get('molfile'))
    params = extract_params(request)
    if file:  # and allowed_file(file):
        cmpsr = TraModel(file, molfile=molfile, params=params).to_composer()
        tf_jcamp, tf_img = cmpsr.tf_jcamp(), cmpsr.tf_img()
        spc_type = cmpsr.core.ncl if cmpsr.core.typ == 'NMR' else cmpsr.core.typ
        memory = to_zip_response([tf_jcamp, tf_img])
        rsp = make_response(
            send_file(
                memory,
                attachment_filename='spectrum.zip',
                as_attachment=True
            )
        )
        rsp.headers['X-Extra-Info-JSON'] = json.dumps({'spc_type': spc_type})
        return rsp
Beispiel #13
0
def chemspectra_molfile_convert():
    molfile = FileContainer(request.files.get('molfile'))
    mm = MoleculeModel(molfile)
    return jsonify(
        status=True,
        smi=mm.smi,
        mass=mm.mass,
        svg=mm.svg,
    )
Beispiel #14
0
def chemspectra_file_save():
    src = FileContainer(request.files['src'])
    dst = FileContainer(request.files['dst'])
    molfile = FileContainer(request.files.get('molfile'))
    filename = request.form.get('filename', default=None)
    params = extract_params(request)
    if dst:  # and allowed_file(file):
        tm = TraModel(dst, molfile=molfile, params=params)
        tf_jcamp, tf_img = tm.convert2jcamp_img()
        tf_arr = [
            src.temp_file(),
            tf_jcamp,
            tf_img,
            tm.tf_predict(),
        ]
        memory = to_zip_response(tf_arr, filename, src_idx=0)
        return send_file(memory,
                         attachment_filename='spectrum.zip',
                         as_attachment=True)
Beispiel #15
0
def chemspectra_predict_by_peaks_json():
    payload = request.json
    layout = payload.get('layout')
    peaks = payload.get('peaks')
    shift = payload.get('shift')
    molfile = FileContainer().from_str(payload.get('molfile'))
    mm = MoleculeModel(molfile, layout, decorate=True)

    outcome = InferModel.predict_nmr(
        mm=mm,
        layout=layout,
        peaks=peaks,
        shift=shift
    )
    if outcome:
        return jsonify(outcome)
    abort(400)
Beispiel #16
0
def test_ms_mzml_converter_composer():
    params = {'mass': 230.079907196}

    with open(target_dir + source_dir + '/ms/svs813f1.mzML', 'rb') as f:
        file = FileStorage(f)
        file = FileContainer(file)
        mscv = MSConverter(file, params)
        mscp = MSComposer(mscv)

    lines = mscp.tf_jcamp().read()[:800] \
                .decode('utf-8', errors='ignore').split('\n')

    assert '##$CSSCANAUTOTARGET=3' in lines
    assert '##$CSSCANEDITTARGET=3' in lines
    assert '##$CSSCANCOUNT=24' in lines
    assert '##$CSTHRESHOLD=0.05' in lines
    assert '51.012176513671875, 34359.0' in lines