1
1
package api
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
5
6
"embed"
6
7
"encoding/json"
@@ -17,6 +18,9 @@ import (
17
18
luajson "github.com/koeng101/dnadesign/api/api/json"
18
19
"github.com/koeng101/dnadesign/api/gen"
19
20
"github.com/koeng101/dnadesign/lib/bio"
21
+ "github.com/koeng101/dnadesign/lib/bio/fasta"
22
+ "github.com/koeng101/dnadesign/lib/bio/fastq"
23
+ "github.com/koeng101/dnadesign/lib/bio/slow5"
20
24
"github.com/koeng101/dnadesign/lib/primers/pcr"
21
25
"github.com/koeng101/dnadesign/lib/synthesis/codon"
22
26
"github.com/koeng101/dnadesign/lib/synthesis/fix"
@@ -209,16 +213,24 @@ func (app *App) ExecuteLua(data string, attachments []gen.Attachment) (string, s
209
213
L .SetGlobal ("fasta_parse" , L .NewFunction (app .LuaIoFastaParse ))
210
214
L .SetGlobal ("genbank_parse" , L .NewFunction (app .LuaIoGenbankParse ))
211
215
212
- // Add CDS design functions
216
+ // Add CDS functions
213
217
L .SetGlobal ("fix" , L .NewFunction (app .LuaCdsFix ))
214
218
L .SetGlobal ("optimize" , L .NewFunction (app .LuaCdsOptimize ))
215
219
L .SetGlobal ("translate" , L .NewFunction (app .LuaCdsTranslate ))
216
220
217
- // Add simulate functions
218
- L .SetGlobal ("fragment" , L .NewFunction (app .LuaCloningFragment ))
221
+ // Add PCR functions
219
222
L .SetGlobal ("complex_pcr" , L .NewFunction (app .LuaPcrComplexPcr ))
220
223
L .SetGlobal ("pcr" , L .NewFunction (app .LuaPcrSimplePcr ))
221
224
225
+ // Add Cloning functions
226
+ L .SetGlobal ("fragment" , L .NewFunction (app .LuaCloningFragment ))
227
+
228
+ // Add Folding functions
229
+ // Add Seqhash functions
230
+ // Add CodonTable functions
231
+ // Add Utils functions
232
+ // Add Random functions
233
+
222
234
// Execute the Lua script
223
235
if err := L .DoString (data ); err != nil {
224
236
return "" , "" , err
@@ -315,7 +327,12 @@ func (app *App) LuaIoFastaParse(L *lua.LState) int {
315
327
}
316
328
317
329
func (app * App ) PostIoFastaWrite (ctx context.Context , request gen.PostIoFastaWriteRequestObject ) (gen.PostIoFastaWriteResponseObject , error ) {
318
- return nil , nil
330
+ var w bytes.Buffer
331
+ for _ , fastaRecord := range * request .Body {
332
+ fastaStruct := fasta .Record (fastaRecord )
333
+ _ , _ = fastaStruct .WriteTo (& w ) // other than memory problems, there are no circumstances where bytes.Buffer errors
334
+ }
335
+ return gen .PostIoFastaWrite200TextResponse (w .String ()), nil
319
336
}
320
337
func (app * App ) LuaIoFastaWrite (L * lua.LState ) int { return 0 }
321
338
@@ -357,7 +374,12 @@ func (app *App) PostIoFastqParse(ctx context.Context, request gen.PostIoFastqPar
357
374
func (app * App ) LuaIoFastqParse (L * lua.LState ) int { return 0 }
358
375
359
376
func (app * App ) PostIoFastqWrite (ctx context.Context , request gen.PostIoFastqWriteRequestObject ) (gen.PostIoFastqWriteResponseObject , error ) {
360
- return nil , nil
377
+ var w bytes.Buffer
378
+ for _ , fastqRead := range * request .Body {
379
+ fastqStruct := fastq.Read {Identifier : fastqRead .Identifier , Sequence : fastqRead .Sequence , Quality : fastqRead .Quality , Optionals : * fastqRead .Optionals }
380
+ _ , _ = fastqStruct .WriteTo (& w ) // other than memory problems, there are no circumstances where bytes.Buffer errors
381
+ }
382
+ return gen .PostIoFastqWrite200TextResponse (w .String ()), nil
361
383
}
362
384
func (app * App ) LuaIoFastqWrite (L * lua.LState ) int { return 0 }
363
385
@@ -367,7 +389,20 @@ func (app *App) PostIoSlow5Parse(ctx context.Context, request gen.PostIoSlow5Par
367
389
func (app * App ) LuaIoSlow5Parse (L * lua.LState ) int { return 0 }
368
390
369
391
func (app * App ) PostIoSlow5Write (ctx context.Context , request gen.PostIoSlow5WriteRequestObject ) (gen.PostIoSlow5WriteResponseObject , error ) {
370
- return nil , nil
392
+ var w bytes.Buffer
393
+ var headerValues []slow5.HeaderValue
394
+ requestHeaderValues := request .Body .Header .HeaderValues
395
+ for _ , headerValue := range requestHeaderValues {
396
+ headerValues = append (headerValues , slow5.HeaderValue {ReadGroupID : uint32 (headerValue .ReadGroupID ), Slow5Version : headerValue .Slow5Version , EndReasonHeaderMap : headerValue .EndReasonHeaderMap })
397
+ }
398
+ header := slow5.Header {HeaderValues : headerValues }
399
+ reads := request .Body .Reads
400
+ _ , _ = header .WriteTo (& w )
401
+ for _ , read := range * reads {
402
+ slow5Struct := ConvertSlow5ReadToRead (read )
403
+ _ , _ = slow5Struct .WriteTo (& w )
404
+ }
405
+ return gen .PostIoSlow5Write200TextResponse (w .String ()), nil
371
406
}
372
407
func (app * App ) LuaIoSlow5Write (L * lua.LState ) int { return 0 }
373
408
@@ -387,7 +422,12 @@ func (app *App) PostIoPileupParse(ctx context.Context, request gen.PostIoPileupP
387
422
func (app * App ) LuaIoPileupParse (L * lua.LState ) int { return 0 }
388
423
389
424
func (app * App ) PostIoPileupWrite (ctx context.Context , request gen.PostIoPileupWriteRequestObject ) (gen.PostIoPileupWriteResponseObject , error ) {
390
- return nil , nil
425
+ var w bytes.Buffer
426
+ for _ , pileupLine := range * request .Body {
427
+ pileupStruct := ConvertGenPileupLineToPileupLine (pileupLine )
428
+ _ , _ = pileupStruct .WriteTo (& w ) // other than memory problems, there are no circumstances where bytes.Buffer errors
429
+ }
430
+ return gen .PostIoPileupWrite200TextResponse (w .String ()), nil
391
431
}
392
432
func (app * App ) LuaIoPileupWrite (L * lua.LState ) int { return 0 }
393
433
0 commit comments