Last active
August 29, 2015 14:06
-
-
Save coronin/a397a85db9388eb7d2e6 to your computer and use it in GitHub Desktop.
patch to htgt/CRISPR-Analyser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/crisprutil.cpp b/src/crisprutil.cpp | |
index 91d9b4c..0480e27 100644 | |
--- a/src/crisprutil.cpp | |
+++ b/src/crisprutil.cpp | |
@@ -44,6 +44,10 @@ void CrisprUtil::_populate_cmap() { | |
string CrisprUtil::get_crispr(uint64_t id) { | |
return util::bits_to_string( get_crispr_int(id), crispr_data.seq_length ); | |
} | |
+// 2014-9-9 : id with offset need to be correct | |
+string CrisprUtil::get_offset_crispr(uint64_t id) { | |
+ return util::bits_to_string( get_crispr_int(id - crispr_data.offset), crispr_data.seq_length ); | |
+} | |
uint64_t CrisprUtil::get_crispr_int(uint64_t id) { | |
//make sure load_binary has been called | |
diff --git a/src/crisprutil.h b/src/crisprutil.h | |
index aaf1498..939c99e 100644 | |
--- a/src/crisprutil.h | |
+++ b/src/crisprutil.h | |
@@ -55,6 +55,7 @@ class CrisprUtil { | |
uint8_t cmap[256]; | |
void load_binary(const std::string & outfile); | |
std::string get_crispr(uint64_t id); | |
+ std::string get_offset_crispr(uint64_t id); | |
uint64_t get_crispr_int(uint64_t id); | |
uint64_t num_seqs(); | |
uint64_t seq_length(); | |
diff --git a/src/ots_server.cpp b/src/ots_server.cpp | |
index 12f6d93..6a194e4 100644 | |
--- a/src/ots_server.cpp | |
+++ b/src/ots_server.cpp | |
@@ -146,6 +146,10 @@ protected: | |
result = search_json(request); | |
res = true; | |
} | |
+ else if ( uri == string("/api/id") ) { | |
+ result = id_json(request); | |
+ res = true; | |
+ } | |
else if ( uri == string("/api/off_targets") ) { | |
result = find_off_targets(request); | |
res = true; | |
@@ -193,6 +197,8 @@ protected: | |
response.setConnectionAlive(false); | |
response.setCacheDisabled(); | |
response.setContentType(content_type); | |
+ response.setHeaderValue("Access-Control-Allow-Origin", "*"); | |
+ response.setHeaderValue("Cache-Control", "no-cache, must-revalidate"); | |
response.addContent(result); | |
response.write(); | |
} | |
@@ -260,6 +266,28 @@ protected: | |
return util::to_json_array(matches); | |
} | |
+ const string id_json(const MongooseRequest& request) { | |
+ vector<string> seqs; | |
+ string ids_text; | |
+ request.getVar("ids", ids_text); | |
+ string species; | |
+ 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 ( uint64_t i = 0; i < ids.size(); i++ ) { | |
+ seqs.push_back( "'" + get_util(species)->get_offset_crispr( stoull(ids[i]) ) + "'" ); | |
+ } | |
+ | |
+ return util::to_json_array(seqs); | |
+ } | |
+ | |
const string find_off_targets(const MongooseRequest& request) { | |
string species; | |
string result = "{"; | |
@@ -320,7 +348,7 @@ protected: | |
int usage() { | |
fprintf(stderr, "\n"); | |
fprintf(stderr, "Program: ots_server\n"); | |
- fprintf(stderr, "Contact: Alex Hodgkins <ah19@sanger.ac.uk>\n"); | |
+ fprintf(stderr, "Contact: Alex Hodgkins <ah19@sanger.ac.uk>, Liang Cai\n"); | |
fprintf(stderr, "Description: A server version of the crispr_analyser that responds to JSON requests\n"); | |
fprintf(stderr, "\n"); | |
fprintf(stderr, "Usage: ots_server [options]\n"); | |
@@ -329,7 +357,8 @@ int usage() { | |
fprintf(stderr, " -p INT The port to run the server on\n"); | |
fprintf(stderr, " -l FILE The file containing the human CRISPR index\n"); | |
fprintf(stderr, " -m FILE The file containing the mouse CRISPR index\n"); | |
- fprintf(stderr, " -s Load the default mouse/crispr indexes (sanger only)\n"); | |
+ fprintf(stderr, " -g FILE The file containing the dog CRISPR index\n"); | |
+ fprintf(stderr, " -s Load the default mouse/crispr indexes (fb.actin only)\n"); | |
fprintf(stderr, " -d Daemon mode\n"); | |
fprintf(stderr, "\n"); | |
@@ -342,14 +371,15 @@ int main(int argc, char * argv[]) { | |
bool default_opts = false; | |
bool daemon = false; | |
- string human_index, mouse_index; | |
+ string human_index, mouse_index, dog_index; | |
int c = -1; | |
- while ( (c = getopt(argc, argv, "t:p:l:m:sd")) != -1 ) { | |
+ while ( (c = getopt(argc, argv, "t:p:l:m:g:sd")) != -1 ) { | |
switch ( c ) { | |
case 't': num_threads = optarg; break; | |
case 'p': port = optarg; break; | |
case 'l': human_index = optarg; break; | |
case 'm': mouse_index = optarg; break; | |
+ case 'g': dog_index = optarg; break; | |
case 's': default_opts = true; break; | |
case 'd': daemon = true; break; | |
case '?': return usage(); | |
@@ -357,12 +387,13 @@ int main(int argc, char * argv[]) { | |
} | |
if ( default_opts ) { | |
- human_index = "/lustre/scratch109/sanger/team87/crispr_indexes/GRCh37_index.bin"; | |
- mouse_index = "/lustre/scratch109/sanger/team87/crispr_indexes/GRCm38_index.bin"; | |
+ human_index = "/home/liang/crisprs_human.bin"; | |
+ mouse_index = "/home/liang/crisprs_mouse.bin"; | |
+ dog_index = "/home/liang/crisprs_cf3.bin"; | |
} | |
else { | |
- if ( human_index.empty() && mouse_index.empty() ) { | |
- cerr << "You must specify at least 1 index to load, or use -s to use the default indexes in /lustre" << endl; | |
+ if ( human_index.empty() && mouse_index.empty() && dog_index.empty() ) { | |
+ cerr << "You must specify at least 1 index to load, or use -s to use the default indexes" << endl; | |
return usage(); | |
} | |
} | |
@@ -397,6 +428,7 @@ int main(int argc, char * argv[]) { | |
if ( ! human_index.empty() ) server.load_index("human", human_index); | |
if ( ! mouse_index.empty() ) server.load_index("mouse", mouse_index); | |
+ if ( ! dog_index.empty() ) server.load_index("dog", dog_index); | |
server.setOption("document_root", "html"); | |
server.setOption("listening_ports", port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ots_server has jsonp support
the following is not required
Access-Control-Allow-Origin "*"