Skip to content

Commit

Permalink
Now using scalar, changed spec to include all desired functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Koeng101 committed Dec 26, 2023
1 parent e75db30 commit c51aff9
Show file tree
Hide file tree
Showing 10 changed files with 2,749 additions and 709 deletions.
523 changes: 468 additions & 55 deletions api/api/api.go

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions api/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ ORIGIN
}

func TestFix(t *testing.T) {
req := httptest.NewRequest("POST", "/api/design/cds/fix", strings.NewReader(`{"organism":"Escherichia coli","sequence":"ATGGGTCTCTAA","removeSequences":["GGTCTC"]}`))
req := httptest.NewRequest("POST", "/api/cds/fix", strings.NewReader(`{"organism":"Escherichia coli","sequence":"ATGCGTCTCTAA","removeSequences":["CGTCTC"]}`))
resp := httptest.NewRecorder()
app.Router.ServeHTTP(resp, req)

r := `{"changes":[{"From":"CTC","Position":2,"Reason":"Common TypeIIS restriction enzymes - BsaI, BbsI, PaqCI","Step":0,"To":"CTG"}],"sequence":"ATGGGTCTGTAA"}`
r := `{"changes":[{"From":"CTC","Position":2,"Reason":"User requested sequence removal","Step":0,"To":"CTG"}],"sequence":"ATGCGTCTGTAA"}`
if strings.TrimSpace(resp.Body.String()) != r {
t.Errorf("Unexpected response. Expected: " + r + "\nGot: " + resp.Body.String())
}
}

func TestOptimize(t *testing.T) {
gfp := "MASKGEELFTGVVPILVELDGDVNGHKFSVSGEGEGDATYGKLTLKFICTTGKLPVPWPTLVTTFSYGVQCFSRYPDHMKRHDFFKSAMPEGYVQERTISFKDDGNYKTRAEVKFEGDTLVNRIELKGIDFKEDGNILGHKLEYNYNSHNVYITADKQKNGIKANFKIRHNIEDGSVQLADHYQQNTPIGDGPVLLPDNHYLSTQSALSKDPNEKRDHMVLLEFVTAAGITHGMDELYK"
req := httptest.NewRequest("POST", "/api/design/cds/optimize", strings.NewReader(fmt.Sprintf(`{"organism":"Escherichia coli","sequence":"%s"}`, gfp)))
req := httptest.NewRequest("POST", "/api/cds/optimize", strings.NewReader(fmt.Sprintf(`{"organism":"Escherichia coli","sequence":"%s"}`, gfp)))
resp := httptest.NewRecorder()
app.Router.ServeHTTP(resp, req)

Expand All @@ -118,7 +118,7 @@ func TestOptimize(t *testing.T) {

func TestTranslate(t *testing.T) {
gfp := "ATGGCATCCAAGGGCGAGGAGTTGTTCACCGGTGTTGTGCCGATCCTGGTGGAGCTGGACGGTGACGTGAACGGTCACAAATTTAGCGTGTCCGGTGAGGGTGAGGGTGATGCTACCTATGGCAAGCTGACCCTGAAATTCATTTGTACCACGGGTAAACTGCCGGTCCCGTGGCCGACGCTGGTGACCACCTTCAGCTATGGTGTGCAGTGTTTCAGCCGCTACCCGGACCACATGAAGCGCCACGACTTTTTCAAGAGCGCGATGCCGGAGGGTTATGTGCAAGAACGTACCATCAGCTTTAAAGATGATGGTAACTATAAGACCCGCGCGGAAGTCAAGTTTGAGGGTGACACGCTGGTGAATCGTATTGAGTTGAAGGGTATTGACTTTAAGGAGGATGGTAATATTTTGGGCCACAAACTGGAGTACAATTACAATAGCCACAATGTTTACATCACGGCAGATAAACAGAAGAACGGTATCAAGGCGAACTTCAAAATTCGTCACAACATTGAGGACGGTTCTGTTCAACTGGCGGACCATTACCAACAGAATACCCCGATCGGTGACGGCCCGGTTCTGCTGCCGGACAACCATTATTTGAGCACCCAGTCCGCCCTGAGCAAGGACCCGAATGAGAAGCGTGATCATATGGTTCTGCTGGAGTTTGTGACCGCGGCGGGCATCACCCACGGCATGGACGAGCTGTACAAG"
req := httptest.NewRequest("POST", "/api/design/cds/translate", strings.NewReader(fmt.Sprintf(`{"translation_table":11,"sequence":"%s"}`, gfp)))
req := httptest.NewRequest("POST", "/api/cds/translate", strings.NewReader(fmt.Sprintf(`{"translation_table":11,"sequence":"%s"}`, gfp)))
resp := httptest.NewRecorder()
app.Router.ServeHTTP(resp, req)

Expand All @@ -141,15 +141,14 @@ func TestFragment(t *testing.T) {
if err != nil {
t.Errorf("Failed to marshal: %s", err)
}
req := httptest.NewRequest("POST", "/api/simulate/fragment", bytes.NewBuffer(b))
req := httptest.NewRequest("POST", "/api/synthesis/fragment", bytes.NewBuffer(b))
resp := httptest.NewRecorder()
app.Router.ServeHTTP(resp, req)

r := `{"efficiency":1,"fragments":["ATGACCATGATTACGCCAAGCTTGCATGCCTGCAGGTCGACTCTAGAGGATCCCCGGGTACCGAGCTCGAATTCACTGGCCGTCGTTTTACAACGTCGTGACTGG","CTGGGAAAACCCTGGCGTTACCCAACTTAATCGCCTTGCAGCACATCCCCCTTTCGCCAGCTGGCGTAATAGCGAAGAGGCCCGCACCGATCGCCCTTCCCAAC","CAACAGTTGCGCAGCCTGAATGGCGAATGGCGCCTGATGCGGTATTTTCTCCTTACGCATCTGTGC","GTGCGGTATTTCACACCGCATATGGTGCACTCTCAGTACAATCTGCTCTGATGCCGCATAG"]}`
if strings.TrimSpace(resp.Body.String()) != r {
t.Errorf("Unexpected response. Expected: " + r + "\nGot: " + resp.Body.String())
}

}

func TestPCR(t *testing.T) {
Expand All @@ -158,25 +157,25 @@ func TestPCR(t *testing.T) {
revPrimer := "TATATGGTCTCTTCATTTAAGAAAGCGCATTTTCCAGC"
primers := []string{fwdPrimer, revPrimer}
circular := false
complexReq := &gen.PostSimulateComplexPcrJSONBody{Circular: &circular, Primers: primers, TargetTm: 55.0, Templates: []string{gene}}
complexReq := &gen.PostPcrComplexPcrJSONBody{Circular: &circular, Primers: primers, TargetTm: 55.0, Templates: []string{gene}}
b, err := json.Marshal(complexReq)
if err != nil {
t.Errorf("Failed to marshal: %s", err)
}
req := httptest.NewRequest("POST", "/api/simulate/complex_pcr", bytes.NewBuffer(b))
req := httptest.NewRequest("POST", "/api/pcr/complex_pcr", bytes.NewBuffer(b))
resp := httptest.NewRecorder()
app.Router.ServeHTTP(resp, req)
r := `["TTATAGGTCTCATACTAATAATTACACCGAGATAACACATCATGGATAAACCGATACTCAAAGATTCTATGAAGCTATTTGAGGCACTTGGTACGATCAAGTCGCGCTCAATGTTTGGTGGCTTCGGACTTTTCGCTGATGAAACGATGTTTGCACTGGTTGTGAATGATCAACTTCACATACGAGCAGACCAGCAAACTTCATCTAACTTCGAGAAGCAAGGGCTAAAACCGTACGTTTATAAAAAGCGTGGTTTTCCAGTCGTTACTAAGTACTACGCGATTTCCGACGACTTGTGGGAATCCAGTGAACGCTTGATAGAAGTAGCGAAGAAGTCGTTAGAACAAGCCAATTTGGAAAAAAAGCAACAGGCAAGTAGTAAGCCCGACAGGTTGAAAGACCTGCCTAACTTACGACTAGCGACTGAACGAATGCTTAAGAAAGCTGGTATAAAATCAGTTGAACAACTTGAAGAGAAAGGTGCATTGAATGCTTACAAAGCGATACGTGACTCTCACTCCGCAAAAGTAAGTATTGAGCTACTCTGGGCTTTAGAAGGAGCGATAAACGGCACGCACTGGAGCGTCGTTCCTCAATCTCGCAGAGAAGAGCTGGAAAATGCGCTTTCTTAAATGAAGAGACCATATA"]`
if strings.TrimSpace(resp.Body.String()) != r {
t.Errorf("Unexpected response. Expected: " + r + "\nGot: " + resp.Body.String())
}

simpleReq := &gen.PostSimulatePcrJSONBody{Circular: &circular, TargetTm: 55.0, Template: gene, ForwardPrimer: fwdPrimer, ReversePrimer: revPrimer}
simpleReq := &gen.PostPcrSimplePcrJSONBody{Circular: &circular, TargetTm: 55.0, Template: gene, ForwardPrimer: fwdPrimer, ReversePrimer: revPrimer}
b, err = json.Marshal(simpleReq)
if err != nil {
t.Errorf("Failed to marshal: %s", err)
}
req = httptest.NewRequest("POST", "/api/simulate/pcr", bytes.NewBuffer(b))
req = httptest.NewRequest("POST", "/api/pcr/simple_pcr", bytes.NewBuffer(b))
resp = httptest.NewRecorder()
app.Router.ServeHTTP(resp, req)
r = `"TTATAGGTCTCATACTAATAATTACACCGAGATAACACATCATGGATAAACCGATACTCAAAGATTCTATGAAGCTATTTGAGGCACTTGGTACGATCAAGTCGCGCTCAATGTTTGGTGGCTTCGGACTTTTCGCTGATGAAACGATGTTTGCACTGGTTGTGAATGATCAACTTCACATACGAGCAGACCAGCAAACTTCATCTAACTTCGAGAAGCAAGGGCTAAAACCGTACGTTTATAAAAAGCGTGGTTTTCCAGTCGTTACTAAGTACTACGCGATTTCCGACGACTTGTGGGAATCCAGTGAACGCTTGATAGAAGTAGCGAAGAAGTCGTTAGAACAAGCCAATTTGGAAAAAAAGCAACAGGCAAGTAGTAAGCCCGACAGGTTGAAAGACCTGCCTAACTTACGACTAGCGACTGAACGAATGCTTAAGAAAGCTGGTATAAAATCAGTTGAACAACTTGAAGAGAAAGGTGCATTGAATGCTTACAAAGCGATACGTGACTCTCACTCCGCAAAAGTAAGTATTGAGCTACTCTGGGCTTTAGAAGGAGCGATAAACGGCACGCACTGGAGCGTCGTTCCTCAATCTCGCAGAGAAGAGCTGGAAAATGCGCTTTCTTAAATGAAGAGACCATATA"`
Expand Down
6 changes: 3 additions & 3 deletions api/api/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ func (j jsonValue) MarshalJSON() (data []byte, err error) {
for key != lua.LNil {
if key.Type() != lua.LTNumber {
err = errInvalidKeys
return
return data, err
}
if expectedKey != key {
err = errSparseArray
return
return data, err
}
arr = append(arr, jsonValue{value, j.visited})
expectedKey++
Expand All @@ -122,7 +122,7 @@ func (j jsonValue) MarshalJSON() (data []byte, err error) {
for key != lua.LNil {
if key.Type() != lua.LTString {
err = errInvalidKeys
return
return data, err
}
obj[key.String()] = jsonValue{value, j.visited}
key, value = converted.Next(key)
Expand Down
249 changes: 0 additions & 249 deletions api/api/lua.go

This file was deleted.

23 changes: 23 additions & 0 deletions api/api/templates/scalar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!doctype html>
<html>
<head>
<title>API Reference</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1" />
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<!-- Scalar API Documentation -->
<!-- Be sure to have the Scalar API reference script available -->
<script id="api-reference" type="application/json">
{{.JsonSwagger}}
</script>
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
</body>
</html>
Loading

0 comments on commit c51aff9

Please sign in to comment.