Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
vidjil
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1,712
Issues
1,712
List
Boards
Labels
Service Desk
Milestones
Merge Requests
87
Merge Requests
87
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vidjil
vidjil
Commits
29e32d65
Commit
29e32d65
authored
Nov 04, 2014
by
Mikaël Salson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
align.cgi: Use core/json.h to create output
parent
4d29be98
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
55 deletions
+67
-55
algo/cgi/align.cpp
algo/cgi/align.cpp
+67
-55
No files found.
algo/cgi/align.cpp
View file @
29e32d65
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment