Skip to content

Commit

Permalink
Updated with Genbank in spec.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Koeng101 committed Dec 10, 2023
1 parent 71800fb commit e26c6b9
Show file tree
Hide file tree
Showing 16 changed files with 1,173 additions and 808 deletions.
24 changes: 23 additions & 1 deletion api/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func InitializeApp() App {

// IO handlers.
app.Router.HandleFunc("/api/io/fasta/parse", appImpl.PostIoFastaParse)
app.Router.HandleFunc("/api/io/genbank/parse", appImpl.PostIoGenbankParse)

// CDS design handlers.
app.Router.HandleFunc("/api/design/cds/fix", appImpl.PostDesignCdsFix)
Expand Down Expand Up @@ -145,11 +146,32 @@ func (app *App) PostIoFastaParse(ctx context.Context, request gen.PostIoFastaPar
}
data := make([]gen.FastaRecord, len(fastas))
for i, fastaRecord := range fastas {
data[i] = gen.FastaRecord{Name: fastaRecord.Identifier, Sequence: fastaRecord.Sequence}
data[i] = gen.FastaRecord(*fastaRecord)
}
return gen.PostIoFastaParse200JSONResponse(data), nil
}

func (app *App) PostIoGenbankParse(ctx context.Context, request gen.PostIoGenbankParseRequestObject) (gen.PostIoGenbankParseResponseObject, error) {
genbankString := *request.Body
parser, err := bio.NewGenbankParser(strings.NewReader(genbankString + "\n"))
if err != nil {
return gen.PostIoGenbankParse500TextResponse(fmt.Sprintf("Got error: %s", err)), nil
}
genbanks, err := parser.Parse()
if err != nil {
return gen.PostIoGenbankParse500TextResponse(fmt.Sprintf("Got error: %s", err)), nil
}
data := make([]gen.GenbankRecord, len(genbanks))
for i, genbankRecord := range genbanks {
err := genbankRecord.StoreFeatureSequences()
if err != nil {
return gen.PostIoGenbankParse500TextResponse(fmt.Sprintf("Got error: %s", err)), nil
}
data[i] = gen.GenbankRecord(*genbankRecord)
}
return gen.PostIoGenbankParse200JSONResponse(data), nil
}

/*
*****************************************************************************
Expand Down
57 changes: 56 additions & 1 deletion api/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,62 @@ IENY
resp := httptest.NewRecorder()
app.Router.ServeHTTP(resp, req)

r := `[{"name":"gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]","sequence":"LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLVEWIWGGFSVDKATLNRFFAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLGLLILILLLLLLALLSPDMLGDPDNHMPADPLNTPLHIKPEWYFLFAYAILRSVPNKLGGVLALFLSIVILGLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGXIENY"}]`
r := `[{"identifier":"gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]","sequence":"LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLVEWIWGGFSVDKATLNRFFAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLGLLILILLLLLLALLSPDMLGDPDNHMPADPLNTPLHIKPEWYFLFAYAILRSVPNKLGGVLALFLSIVILGLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGXIENY"}]`
if strings.TrimSpace(resp.Body.String()) != r {
t.Errorf("Unexpected response. Expected: " + r + "\nGot: " + resp.Body.String())
}
}

func TestIoGenbankParse(t *testing.T) {
baseGenbank := `LOCUS pUC19_lacZ 336 bp DNA linear UNA 12-SEP-2023
DEFINITION natural linear DNA
ACCESSION .
VERSION .
KEYWORDS .
SOURCE natural DNA sequence
ORGANISM unspecified
REFERENCE 1 (bases 1 to 336)
AUTHORS Keoni Gandall
TITLE Direct Submission
JOURNAL Exported Sep 12, 2023 from SnapGene 6.2.2
https://www.snapgene.com
FEATURES Location/Qualifiers
source 1..336
/mol_type="genomic DNA"
/organism="unspecified"
primer_bind 1..17
/label=M13 rev
/note="common sequencing primer, one of multiple similar
variants"
CDS 13..336
/codon_start=1
/gene="lacZ"
/product="LacZ-alpha fragment of beta-galactosidase"
/label=lacZ-alpha
/translation="MTMITPSLHACRSTLEDPRVPSSNSLAVVLQRRDWENPGVTQLNR
LAAHPPFASWRNSEEARTDRPSQQLRSLNGEWRLMRYFLLTHLCGISHRIWCTLSTICS
DAA"
misc_feature 30..86
/label=MCS
/note="pUC19 multiple cloning site"
primer_bind complement(87..103)
/label=M13 fwd
/note="common sequencing primer, one of multiple similar
variants"
ORIGIN
1 caggaaacag ctatgaccat gattacgcca agcttgcatg cctgcaggtc gactctagag
61 gatccccggg taccgagctc gaattcactg gccgtcgttt tacaacgtcg tgactgggaa
121 aaccctggcg ttacccaact taatcgcctt gcagcacatc cccctttcgc cagctggcgt
181 aatagcgaag aggcccgcac cgatcgccct tcccaacagt tgcgcagcct gaatggcgaa
241 tggcgcctga tgcggtattt tctccttacg catctgtgcg gtatttcaca ccgcatatgg
301 tgcactctca gtacaatctg ctctgatgcc gcatag
//
`
req := httptest.NewRequest("POST", "/api/io/genbank/parse", strings.NewReader(baseGenbank))
resp := httptest.NewRecorder()
app.Router.ServeHTTP(resp, req)

r := `[{"features":[{"attributes":{"mol_type":["genomic DNA"],"organism":["unspecified"]},"description":"","location":{"complement":false,"end":336,"fivePrimePartial":false,"gbkLocationString":"","join":false,"start":0,"subLocations":null,"threePrimePartial":false},"sequence":"caggaaacagctatgaccatgattacgccaagcttgcatgcctgcaggtcgactctagaggatccccgggtaccgagctcgaattcactggccgtcgttttacaacgtcgtgactgggaaaaccctggcgttacccaacttaatcgccttgcagcacatccccctttcgccagctggcgtaatagcgaagaggcccgcaccgatcgcccttcccaacagttgcgcagcctgaatggcgaatggcgcctgatgcggtattttctccttacgcatctgtgcggtatttcacaccgcatatggtgcactctcagtacaatctgctctgatgccgcatag","sequenceHash":"","sequenceHashFunction":"","type":"source"},{"attributes":{"label":["M13 rev"],"note":["common sequencing primer, one of multiple similarvariants"]},"description":"","location":{"complement":false,"end":17,"fivePrimePartial":false,"gbkLocationString":"","join":false,"start":0,"subLocations":null,"threePrimePartial":false},"sequence":"caggaaacagctatgac","sequenceHash":"","sequenceHashFunction":"","type":"primer_bind"},{"attributes":{"codon_start":["1"],"gene":["lacZ"],"label":["lacZ-alpha"],"product":["LacZ-alpha fragment of beta-galactosidase"],"translation":["MTMITPSLHACRSTLEDPRVPSSNSLAVVLQRRDWENPGVTQLNRLAAHPPFASWRNSEEARTDRPSQQLRSLNGEWRLMRYFLLTHLCGISHRIWCTLSTICSDAA"]},"description":"","location":{"complement":false,"end":336,"fivePrimePartial":false,"gbkLocationString":"","join":false,"start":12,"subLocations":null,"threePrimePartial":false},"sequence":"atgaccatgattacgccaagcttgcatgcctgcaggtcgactctagaggatccccgggtaccgagctcgaattcactggccgtcgttttacaacgtcgtgactgggaaaaccctggcgttacccaacttaatcgccttgcagcacatccccctttcgccagctggcgtaatagcgaagaggcccgcaccgatcgcccttcccaacagttgcgcagcctgaatggcgaatggcgcctgatgcggtattttctccttacgcatctgtgcggtatttcacaccgcatatggtgcactctcagtacaatctgctctgatgccgcatag","sequenceHash":"","sequenceHashFunction":"","type":"CDS"},{"attributes":{"label":["MCS"],"note":["pUC19 multiple cloning site"]},"description":"","location":{"complement":false,"end":86,"fivePrimePartial":false,"gbkLocationString":"","join":false,"start":29,"subLocations":null,"threePrimePartial":false},"sequence":"aagcttgcatgcctgcaggtcgactctagaggatccccgggtaccgagctcgaattc","sequenceHash":"","sequenceHashFunction":"","type":"misc_feature"},{"attributes":{"label":["M13 fwd"],"note":["common sequencing primer, one of multiple similarvariants"]},"description":"","location":{"complement":true,"end":103,"fivePrimePartial":false,"gbkLocationString":"complement(87..103)","join":false,"start":86,"subLocations":null,"threePrimePartial":false},"sequence":"gtaaaacgacggccagt","sequenceHash":"","sequenceHashFunction":"","type":"primer_bind"}],"meta":{"accession":".","baseCount":null,"date":"","definition":"natural linear DNA","keywords":".","locus":{"circular":false,"genbankDivision":"UNA","modificationDate":"12-SEP-2023","moleculeType":"DNA","name":"pUC19_lacZ","sequenceCoding":"bp","sequenceLength":"336"},"name":"","organism":"unspecified","origin":"","other":{},"references":[{"authors":"Keoni Gandall","consortium":"","journal":"Exported Sep 12, 2023 from SnapGene 6.2.2 https://www.snapgene.com","pubMed":"","range":"(bases 1 to 336)","remark":"","title":"Direct Submission"}],"sequenceHash":"","sequenceHashFunction":"","source":"natural DNA sequence","taxonomy":null,"version":"."},"sequence":"caggaaacagctatgaccatgattacgccaagcttgcatgcctgcaggtcgactctagaggatccccgggtaccgagctcgaattcactggccgtcgttttacaacgtcgtgactgggaaaaccctggcgttacccaacttaatcgccttgcagcacatccccctttcgccagctggcgtaatagcgaagaggcccgcaccgatcgcccttcccaacagttgcgcagcctgaatggcgaatggcgcctgatgcggtattttctccttacgcatctgtgcggtatttcacaccgcatatggtgcactctcagtacaatctgctctgatgccgcatag"}]`
if strings.TrimSpace(resp.Body.String()) != r {
t.Errorf("Unexpected response. Expected: " + r + "\nGot: " + resp.Body.String())
}
Expand Down
Loading

0 comments on commit e26c6b9

Please sign in to comment.