Esempio n. 1
0
    const string off_targets_by_seq(const MongooseRequest& request) {
        ots_data_t result;
        string sequence;
        string species;
        string pam_right_param;
        vector<uint64_t> matches;
        bool pam_right;
        string jason_result;

        request.getVar("seq", sequence);
        request.getVar("species", species);
        request.getVar("pam_right", pam_right_param);

        pam_right = false;
        if ( pam_right_param == "true" ) {
            pam_right = true;
        }
        else if ( pam_right_param == "false" ) {
            pam_right = false;
        }
        else {
             throw runtime_error("pam_right must be the string true or false");
        }

        result = get_util(species)->off_targets_by_seq( sequence, pam_right);
        jason_result = util::to_string(result);

        return jason_result;
    }
Esempio n. 2
0
    const string id_json(const MongooseRequest& request) {
        vector<string> seqs;
        string ids_text, species;
        request.getVar("ids", ids_text);
        request.getVar("species", species);

        if ( ids_text.empty() )
            throw runtime_error("Please provide ids as a comma separated string");
        if ( species.empty() )
            throw runtime_error("Please provide a species");

        util::lc(species);
        vector<string> ids = util::split(ids_text);

        //should maybe change this to return an object of { id: sequence }
        for ( vector<string>::size_type i = 0; i < ids.size(); i++ ) {
            cerr << "Getting sequence for " << ids[i] << " (" << species << ")\n";

            unsigned long long id;
            try {
                id = stoull(ids[i]);
            }
            catch (const invalid_argument &e) {
                throw runtime_error("id " + ids[i] + " not an integer");
            }

            seqs.push_back( "'" + get_util(species)->get_crispr(id) + "'" );
        }

        return util::to_json_array(seqs);
    }
Esempio n. 3
0
    const string find_off_targets(const MongooseRequest& request) {
        string species;
        string result = "{";

        vector<uint64_t> ids_all;
        string ids_text;
        request.getVar("ids", ids_text);
        request.getVar("species", species);

        if ( ids_text.empty() )
            throw runtime_error("Please provide ids");

        if ( species.empty() )
            throw runtime_error("Please provide a species");

        util::lc(species);

        vector<string> ids = util::split(ids_text);

        for ( vector<string>::size_type i = 0; i < ids.size(); i++ ) {

            unsigned long long id;
            try {
                id = stoull(ids[i]);
            }
            catch (const invalid_argument &e) {
                throw runtime_error("id " + ids[i] + " not an integer");
            }

            ids_all.push_back(id);
        }

        vector<ots_data_t> offs = get_util(species)->find_off_targets(ids_all, true);

        for ( uint i = 0; i < offs.size(); ++i ) {
            if ( i > 0 ) result += ",";
            //we use my to_string here as its a struct we want a string of
            result += "\"" + to_string(offs[i].id) + "\":" + util::to_string(offs[i]);
        }

        result += "}";

        //result = "Got data for " + to_string(offs.size()) + " crisprs";

        return result;
    }
Esempio n. 4
0
    //wrap a json string in jsonp. return true if it was jsonp
    bool handle_jsonp(const MongooseRequest& request, string& result) {
        string callback;
        request.getVar("callback", callback);

        if ( callback.empty() ) return false;

        callback += "(";

        result.insert(0, callback);
        result += ");";

        return true;
    }
Esempio n. 5
0
    void get_matches(const MongooseRequest& request, vector<uint64_t>& matches) {
        string seq;
        string pam_right_str;
        string species;

        request.getVar("seq", seq);
        request.getVar("pam_right", pam_right_str);
        request.getVar("species", species);

        //make species lowercase
        util::lc( species );

        //default pam_right is 2, which means don't consider the pam
        if ( pam_right_str.size() == 0 ) pam_right_str = "2";

        if ( seq.empty() )
            throw runtime_error("Please provide a sequence");

        if ( seq.size() != 20 )
            throw runtime_error("Sequence must be 20 bases long");

        if ( pam_right_str.empty() )
            throw runtime_error("Please specify pam right");

        int pam_right = atoi( pam_right_str.c_str() );

        if ( ! ( pam_right == 0 || pam_right == 1 || pam_right == 2 ) )
            throw runtime_error("pam_right must be 0, 1 or 2");

        if ( species.empty() )
            throw runtime_error("Please specify a species");

        cerr << "Searching for " << seq << ", pam_right is " << pam_right << endl;

        get_util(species)->search_by_seq( seq, pam_right, matches );
    }