Commit 29e32d65 authored by Mikael Salson's avatar Mikael Salson

align.cgi: Use core/json.h to create output

parent 4d29be98
......@@ -6,9 +6,47 @@
#include "../core/dynprog.h"
#include "../core/fasta.h"
#include "../core/lazy_msa.h"
#include "../core/json.h"
using namespace std;
bool check_cgi_parameters(JsonList &result) {
char * requestMethod = getenv("REQUEST_METHOD");
if(!requestMethod) {
result.add("Error", "requestMethod");
return false;
} else if(strcmp(requestMethod, "POST") != 0) {
result.add("Error", "requestMethod =/= post");
return false;
}
char * contentType = getenv("CONTENT_TYPE");
if(!contentType) {
result.add("Error", "content_type");
return false;
}
result.add("requestMethod",requestMethod);
result.add("contentType", contentType);
return true;
}
bool create_fasta_file(JsonList &result, int fd) {
char temp[1024];
FILE *f;
f = fdopen(fd,"w");
if(f == NULL){
result.add("Error", "opening tempfile");
return false;
}else{
while(cin) {
cin.getline(temp, 1024);
fputs(temp, f);
fputs("\n", f);
}
}
fclose(f);
return true;
}
int main(int argc, char* argv[])
{
......@@ -18,56 +56,25 @@ int main(int argc, char* argv[])
ostream * p;
p=&ost;
char filename[] = "VidjilAlignXXXXXX";
int fd = mkstemp(filename);
if (fd == -1) {
perror("Creation of temporary file");
exit(1);
}
JsonList result;
bool error = false;
bool cgi_mode;
if (argc <= 1){
cgi_mode=true;
cout <<"Content-type: text/html"<<endl<<endl;
cout<< "{"<<endl;
char * requestMethod = getenv("REQUEST_METHOD");
cout<<"\"requestMethod\" : \""<<requestMethod<<"\""<<endl;
if(!requestMethod) {
cout<<",\"Error\": \"requestMethod\"}"<<endl;
return 0;
}
if(strcmp(requestMethod, "POST") != 0) {
cout<<",\"Error\": \"requestMethod =/= post\"}"<<endl;
return 0;
}
char * contentType = getenv("CONTENT_TYPE");
if(!contentType) {
cout<<",\"Error\": \"content_type\"}"<<endl;
return 0;
}
cout<<",\"contentType\": \""<<contentType<<"\""<<endl;
char temp[1024];
FILE *f;
f = fdopen(fd,"w");
if(f == NULL){
cout<<",\"Error\": \"save\""<<filename<<"}"<<endl;
return 0;
}else{
while(cin) {
cin.getline(temp, 1024);
fputs(temp, f);
fputs("\n", f);
}
error = ! check_cgi_parameters(result);
if (! error) {
int fd = mkstemp(filename);
if (fd == -1) {
result.add("Error", "Temporary file");
error = true;
} else {
error = ! create_fasta_file(result, fd);
fdata = filename;
}
}
fclose(f);
fdata = filename;
}else{
cgi_mode=false;
fdata = argv[1];
......@@ -87,28 +94,33 @@ int main(int argc, char* argv[])
lm.add(seq1);
}
string *result;
result =new string[lm.sizeUsed+2];
lm.align(result);
string *align_str;
align_str =new string[lm.sizeUsed+2];
lm.align(align_str);
if (cgi_mode){
cout<<",\"seq\" : [\""<<result[0]<<"\""<<endl;
for (int i=1; i<lm.sizeUsed+2; i++){
cout<<",\""<<result[i]<<"\""<<endl;
}
cout<<"]}";
if (cgi_mode) {
if (! error) {
JsonArray alignment;
for (int i=0; i<lm.sizeUsed+2; i++){
alignment.add(align_str[i]);
}
result.add("seq", alignment);
}
remove(filename);
cout <<"Content-type: text/html"<<endl<<endl;
cout << result.toString();
}else{
int length=60;
int n=result[0].size();
int n=align_str[0].size();
int j=0;
while (n > 0){
for (int i=0; i<lm.sizeUsed+2; i++){
cout<<" > "<<result[i].substr(j*length,length)<<" < "<<fa.label(i)<<endl;
cout<<" > "<<align_str[i].substr(j*length,length)<<" < "<<fa.label(i)<<endl;
}
cout<<endl;
n=n-length;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment