Changeset 944


Ignore:
Timestamp:
06/05/20 17:27:32 (4 years ago)
Author:
Maciej Komosinski
Message:

Loads genotypes properly using Framsticks SDK methods instead of ad-hoc js parsing

Location:
js
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • js/human_3d_alignment/src/utils/genotypes.js

    r911 r944  
    3030        rawFile.onload = (e) => {
    3131            if (rawFile.readyState === 4) {
    32                 if (rawFile.status === 200) {
    33                     this.readGenotypesFromText(rawFile.responseText);
     32                if (rawFile.status === 200 || rawFile.status === 0) {
     33                      this.readGenotypesFromGenotypeLoader(rawFile.responseText);
    3434                } else {
    3535                    console.error(rawFile.statusText);
     
    4444
    4545    /**
    46      * Read genotypes from text read from genotypes.gen. TODO mk> This function should be removed; use SDK functionality instead for reliable parsing.
     46     * Read genotypes from text read from genotypes.gen.
    4747     * @param {string} text
    4848     */
    49     readGenotypesFromText(text) {
    50         let textTable = text.split('org:\n');
    51         let i = 1;
    52         while (i < textTable.length) {
    53             let lines = textTable[i].split('\n');
    54             if (lines[0].includes('name:')) {
    55                 let j = 0;
    56                 let gen = '';
    57                 let name = '';
    58                 let id = '';
    59                 while (j < lines.length) {
    60                     if (lines[j].includes('name:')) {
    61                         name += lines[j].split(':')[1];
    62                     } else if (lines[j].includes('genotype:')) {
    63                         gen += lines[j].replace('genotype:', '');
    64                         let k = j + 1;
    65                         while (!lines[k].includes('info_timestamp:')) {
    66                             if (lines[k] != '\n') {
    67                                 gen += ' ' + lines[k];
    68                             } else {
    69                                 gen += ' '
    70                             }
    71                             k++;
    72                         }
    73                         gen = gen.split('~').join('');
    74                     } else if (lines[j].includes('num:')) {
    75                         id += lines[j].split(':')[1];
    76                     }
    77                     j++;
    78                 }
    79                 if (!gen.includes('//0')) {
    80                     this.name.push(name);
    81                     this.genotype.push(gen);
    82                     this.id.push(id);
    83                 }
    84             }
     49    readGenotypesFromGenotypeLoader(text) {
     50        let textStringFile = new Module.StringFILE2(text, 0);
     51        let genotypeLoader = new Module.GenotypeMiniLoader(textStringFile);
     52        let loaded = genotypeLoader.loadNextGenotype();
     53        let i = 0;
     54        while (loaded.genotype.c_str()!="")
     55        {
     56            this.name.push(loaded.name.c_str());
     57            this.genotype.push(loaded.genotype.c_str());
     58            this.id.push(i);
     59            i++;
    8560
    86             i++;
     61            loaded = genotypeLoader.loadNextGenotype();
    8762        }
    8863        this.loaded = true;
    8964        this.parent.start();
    9065    }
    91 
    9266}
    9367
  • js/sdk/js_interface/js_interface.cpp

    r919 r944  
    1717#include <common/loggers/loggers.h>
    1818#include <common/loggers/loggertostdout.h>
     19#include <common/virtfile/stringfile.h>
    1920#include <frams/param/param.h>
    2021#include <frams/param/paramtree.h>
    2122#include <frams/param/mutableparam.h>
    2223#include <frams/_demos/genotypemini.h>
     24#include <frams/_demos/genotypeloader.h>
    2325#include "js_types.h"
    2426#include "js_interface_impl.cpp"
  • js/sdk/js_interface/js_interface.idl

    r918 r944  
    170170        "NeuroClass::EffectorClass",
    171171        "NeuroClass::ReceptorClass",
    172         "NeuroClass::V1BendMuscle",
    173         "NeuroClass::V1RotMuscle",
    174         "NeuroClass::LinearMuscle"
     172        "NeuroClass::IsV1BendMuscle",
     173        "NeuroClass::IsV1RotMuscle",
     174        "NeuroClass::IsLinearMuscle",
     175        "NeuroClass::IsSolidMuscle"
    175176};
    176177
     
    343344};
    344345
    345 interface GenotypeMiniLoader {
    346         void GenotypeMiniLoader([Const] DOMString filename);
     346interface MultiParamLoader {
     347};
     348
     349interface GenotypeMiniLoader : MultiParamLoader {
     350    void GenotypeMiniLoader(VirtFILE f);
    347351        GenotypeMini loadNextGenotype();
    348352};
     
    391395
    392396interface VirtFILE {
     397};
     398
     399interface StringFILE2 : VirtFILE {
     400    void StringFILE2([Const] DOMString s, optional long _pos = 0);
    393401};
    394402
Note: See TracChangeset for help on using the changeset viewer.