Skip to content

Commit

Permalink
resolves bebop#352 remove error from Feature.GetSequence() as it has …
Browse files Browse the repository at this point in the history
…nothing to return
  • Loading branch information
Alena Maslova committed Oct 7, 2023
1 parent 5bd6a5d commit 214e836
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions io/genbank/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func ExampleGenbank_AddFeature() {
_ = sequence.AddFeature(&feature)

// get the GFP feature sequence string from the sequence struct.
featureSequence, _ := feature.GetSequence()
featureSequence := feature.GetSequence()

// check to see if the feature was inserted properly into the sequence.
fmt.Println(gfpSequence == featureSequence)
Expand Down Expand Up @@ -159,7 +159,7 @@ func ExampleFeature_GetSequence() {
_ = sequence.AddFeature(&feature)

// get the GFP feature sequence string from the sequence struct.
featureSequence, _ := feature.GetSequence()
featureSequence := feature.GetSequence()

// check to see if the feature was inserted properly into the sequence.
fmt.Println(gfpSequence == featureSequence)
Expand Down
8 changes: 4 additions & 4 deletions io/genbank/genbank.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ func (sequence *Genbank) AddFeature(feature *Feature) error {
}

// GetSequence returns the sequence of a feature.
func (feature Feature) GetSequence() (string, error) {
func (feature Feature) GetSequence() string {
return getFeatureSequence(feature, feature.Location)
}

// getFeatureSequence takes a feature and location object and returns a sequence string.
func getFeatureSequence(feature Feature, location Location) (string, error) {
func getFeatureSequence(feature Feature, location Location) string {
var sequenceBuffer bytes.Buffer
var sequenceString string
parentSequence := feature.ParentSequence.Sequence
Expand All @@ -140,7 +140,7 @@ func getFeatureSequence(feature Feature, location Location) (string, error) {
sequenceBuffer.WriteString(parentSequence[location.Start:location.End])
} else {
for _, subLocation := range location.SubLocations {
sequence, _ := getFeatureSequence(feature, subLocation)
sequence := getFeatureSequence(feature, subLocation)

sequenceBuffer.WriteString(sequence)
}
Expand All @@ -153,7 +153,7 @@ func getFeatureSequence(feature Feature, location Location) (string, error) {
sequenceString = sequenceBuffer.String()
}

return sequenceString, nil
return sequenceString
}

// Read reads a GBK file from path and returns a Genbank struct.
Expand Down
14 changes: 7 additions & 7 deletions io/genbank/genbank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestGetSequenceMethod(t *testing.T) {
gbk, _ := Read("../../data/t4_intron.gb")

// Check to see if GetSequence method works on Features struct
feature, _ := gbk.Features[1].GetSequence()
feature := gbk.Features[1].GetSequence()
seq := "atgagattacaacgccagagcatcaaagattcagaagttagaggtaaatggtattttaatatcatcggtaaagattctgaacttgttgaaaaagctgaacatcttttacgtgatatgggatgggaagatgaatgcgatggatgtcctctttatgaagacggagaaagcgcaggattttggatttaccattctgacgtcgagcagtttaaagctgattggaaaattgtgaaaaagtctgtttga"
if feature != seq {
t.Errorf("Feature GetSequence method has failed. Got this:\n%s instead of \n%s", feature, seq)
Expand All @@ -183,21 +183,21 @@ func TestLocationParser(t *testing.T) {
gbk, _ := Read("../../data/t4_intron.gb")

// Read 1..243
feature, _ := gbk.Features[1].GetSequence()
feature := gbk.Features[1].GetSequence()
seq := "atgagattacaacgccagagcatcaaagattcagaagttagaggtaaatggtattttaatatcatcggtaaagattctgaacttgttgaaaaagctgaacatcttttacgtgatatgggatgggaagatgaatgcgatggatgtcctctttatgaagacggagaaagcgcaggattttggatttaccattctgacgtcgagcagtttaaagctgattggaaaattgtgaaaaagtctgtttga"
if feature != seq {
t.Errorf("Feature sequence parser has changed on test '1..243'. Got this:\n%s instead of \n%s", feature, seq)
}

// Read join(893..1441,2459..2770)
featureJoin, _ := gbk.Features[6].GetSequence()
featureJoin := gbk.Features[6].GetSequence()
seqJoin := "atgaaacaataccaagatttaattaaagacatttttgaaaatggttatgaaaccgatgatcgtacaggcacaggaacaattgctctgttcggatctaaattacgctgggatttaactaaaggttttcctgcggtaacaactaagaagctcgcctggaaagcttgcattgctgagctaatatggtttttatcaggaagcacaaatgtcaatgatttacgattaattcaacacgattcgttaatccaaggcaaaacagtctgggatgaaaattacgaaaatcaagcaaaagatttaggataccatagcggtgaacttggtccaatttatggaaaacagtggcgtgattttggtggtgtagaccaaattatagaagttattgatcgtattaaaaaactgccaaatgataggcgtcaaattgtttctgcatggaatccagctgaacttaaatatatggcattaccgccttgtcatatgttctatcagtttaatgtgcgtaatggctatttggatttgcagtggtatcaacgctcagtagatgttttcttgggtctaccgtttaatattgcgtcatatgctacgttagttcatattgtagctaagatgtgtaatcttattccaggggatttgatattttctggtggtaatactcatatctatatgaatcacgtagaacaatgtaaagaaattttgaggcgtgaacctaaagagctttgtgagctggtaataagtggtctaccttataaattccgatatctttctactaaagaacaattaaaatatgttcttaaacttaggcctaaagatttcgttcttaacaactatgtatcacaccctcctattaaaggaaagatggcggtgtaa"
if featureJoin != seqJoin {
t.Errorf("Feature sequence parser has changed on test 'join(893..1441,2459..2770)'. Got this:\n%s instead of \n%s", featureJoin, seqJoin)
}

// Read complement(2791..3054)
featureComplement, _ := gbk.Features[10].GetSequence()
featureComplement := gbk.Features[10].GetSequence()
seqComplement := "ttattcactacccggcatagacggcccacgctggaataattcgtcatattgtttttccgttaaaacagtaatatcgtagtaacagtcagaagaagttttaactgtggaaattttattatcaaaatactcacgagtcattttatgagtatagtattttttaccataaatggtaataggctgttctggtcctggaacttctaactcgcttgggttaggaagtgtaaaaagaactacaccagaagtatctttaaatcgtaaaatcat"
if featureComplement != seqComplement {
t.Errorf("Feature sequence parser has changed on test 'complement(2791..3054)'. Got this:\n%s instead of \n%s", featureComplement, seqComplement)
Expand All @@ -208,14 +208,14 @@ func TestLocationParser(t *testing.T) {
// that the first sequence should be appended to the reverse sequence, instead of the second sequence
// getting appended to the first. Biopython appends the second sequence to the first, and that is logically
// the most obvious thing to do, so we are implementing it that way.
featureJoinComplement, _ := gbk.Features[3].GetSequence()
featureJoinComplement := gbk.Features[3].GetSequence()
seqJoinComplement := "ataccaatttaatcattcatttatatactgattccgtaagggttgttacttcatctattttataccaatgcgtttcaaccatttcacgcttgcttatatcatcaagaaaacttgcgtctaattgaactgttgaattaacacgatgccttttaacgatgcgagaaacaactacttcatctgcataaggtaatgcagcatataacagagcaggcccgccaattacacttactttagaattctgatcaagcatagtttcgaatggtgcattagggcttgacacttgaatttcgccgccagaaatgtaagttatatattgctcccaagtaatatagaaatgtgctaaatcgccgtctttagttacaggataatcacgcgcaaggtcacacaccacaatatggctacgaccaggaagtaatgtaggcaatgactggaacgttttagcacccataatcataattgtgccttcagtacgagctttaaaattctggaggtcctttttaactcgtccccatggtaaaccatcacctaaaccgaatgctaattcattaaagccgtcgaccgttttagttggaga"
if featureJoinComplement != seqJoinComplement {
t.Errorf("Feature sequence parser has changed on test 'join(complement(315..330),complement(339..896))'. Got this:\n%s instead of \n%s", featureJoinComplement, seqJoinComplement)
}

// Read complement(join(893..1098,1101..2770))
featureComplementJoin, _ := gbk.Features[5].GetSequence()
featureComplementJoin := gbk.Features[5].GetSequence()
seqComplementJoin := "ttacaccgccatctttcctttaataggagggtgtgatacatagttgttaagaacgaaatctttaggcctaagtttaagaacatattttaattgttctttagtagaaagatatcggaatttataaggtagaccacttattaccagctcacaaagctctttaggttcacgcctcaaaatttctttacattgttctacgtgattcatatagatatgagtattaccaccagaaaatatcaaatcccctggaataagattacacatcttagctacaatatgaactaacgtagcatatgacgcaatattaaacggtagcattatgttcagataaggtcgttaatcttaccccggaattatatccagctgcatgtcaccatgcagagcagactatatctccaacttgttaaagcaagttgtctatcgtttcgagtcacttgaccctactccccaaagggatagtcgttaggcatttatgtagaaccaattccatttatcagattttacacgataagtaactaatccagacgaaattttaaaatgtctagctgcatctgctgcacaatcaaaaataaccccatcacatgaaatctttttaatattactaggctttttacctttcatcttttctgatattttagatttagttatgtctgaatgcttatgattaaagaatgaattattttcacctgaacgatttctgcatttactacaagtataagcagaagtttgtatgcgaacaccgcacttacaaaacttatgggtttctggattccaacgcccgtttttacttccgggtttactgtaaagagctttccgaccatcaggtccaagtttaagcatcttagctttaacagtttcagaacgtttcttaataatttcttcttttaatggatgcgtagaacatgtatcaccaaacgttgcatcagcaatattgtatccattaattttagaattaagctctttaatccaaaaattttctcgttcaataatcaaatctttctcatatggaatttcttccaaaatagaacattcaaacacattaccatgtttgttaaaagacctctgaagttttatagaagaatggcatcctttttctaaatctttaaaatgcctcttccatctcttttcaaaatctttagcacttcctacatatactttattgtttaaagtatttttaatctgataaattccgcttttcataaatacctctttaaatatagaagtatttattaaagggcaagtcctacaatttagcacgggattgtctactagagaggttccccgtttagatagattacaagtataagtcaccttatactcaggcctcaattaacccaagaaaacatctactgagcgttgataccactgcaaatccaaatagccattacgcacattaaactgatagaacatatgacaaggcggtaatgccatatatttaagttcagctggattccatgcagaaacaatttgacgcctatcatttggcagttttttaatacgatcaataacttctataatttggtctacaccaccaaaatcacgccactgttttccataaattggaccaagttcaccgctatggtatcctaaatcttttgcttgattttcgtaattttcatcccagactgttttgccttggattaacgaatcgtgttgaattaatcgtaaatcatacatttgtgcttcctgataaaaaccatattagctcagcaatgcaagctttccaggcgagcttcttagttgttaccgcaggaaaacctttagttaaatcccagcgtaatttagatccgaacagagcaattgttcctgtgcctgtacgatcatcggtttcataaccattttcaaaaatgtctttaattaaatcttggtattgtttcat"
if featureComplementJoin != seqComplementJoin {
t.Errorf("Feature sequence parser has changed on test 'complement(join(893..1098,1101..2770))'. Got this:\n%s instead of \n%s", featureComplementJoin, seqComplementJoin)
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestFeature_GetSequence_Legacy(t *testing.T) {
_ = sequence.AddFeature(&feature)

// get the GFP feature sequence string from the sequence struct.
featureSequence, _ := feature.GetSequence()
featureSequence := feature.GetSequence()

// check to see if the feature was inserted properly into the sequence.
if gfpSequence != featureSequence {
Expand Down
12 changes: 6 additions & 6 deletions synthesis/codon/codon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestOptimize(t *testing.T) {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
codingRegionsBuilder.WriteString(sequence)
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestOptimizeSameSeed(t *testing.T) {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
codingRegionsBuilder.WriteString(sequence)
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestOptimizeDifferentSeed(t *testing.T) {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
codingRegionsBuilder.WriteString(sequence)
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestCompromiseCodonTable(t *testing.T) {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
codingRegionsBuilder.WriteString(sequence)
}
}
Expand All @@ -322,7 +322,7 @@ func TestCompromiseCodonTable(t *testing.T) {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence2.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
codingRegionsBuilder2.WriteString(sequence)
}
}
Expand Down Expand Up @@ -370,7 +370,7 @@ func TestCapitalizationRegression(t *testing.T) {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
codingRegionsBuilder.WriteString(sequence)
}
}
Expand Down
10 changes: 5 additions & 5 deletions synthesis/codon/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func ExampleOptimize() {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
// Note: sometimes, genbank files will have annotated CDSs that are pseudo genes (not having triplet codons).
// This will shift the entire codon table, messing up the end results. To fix this, make sure to do a modulo
// check.
Expand Down Expand Up @@ -108,7 +108,7 @@ func ExampleCompromiseCodonTable() {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
codingRegionsBuilder.WriteString(sequence)
}
}
Expand All @@ -127,7 +127,7 @@ func ExampleCompromiseCodonTable() {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence2.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
codingRegionsBuilder2.WriteString(sequence)
}
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func ExampleAddCodonTable() {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
codingRegionsBuilder.WriteString(sequence)
}
}
Expand All @@ -179,7 +179,7 @@ func ExampleAddCodonTable() {
// iterate through the features of the genbank file and if the feature is a coding region, append the sequence to the string builder
for _, feature := range sequence2.Features {
if feature.Type == "CDS" {
sequence, _ := feature.GetSequence()
sequence := feature.GetSequence()
codingRegionsBuilder2.WriteString(sequence)
}
}
Expand Down
2 changes: 1 addition & 1 deletion tutorials/001_input_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestFileIOTutorial(t *testing.T) {
// get the sequence of each feature using the GetSequence method.

feature := puc19.Features[1]
featureSequence, _ := feature.GetSequence() // this is the sequence of the feature
featureSequence := feature.GetSequence() // this is the sequence of the feature
expectedFeatureSequence := "gggaaacgcctggtatcttt" // this is what we expect the sequence of the feature to be
if featureSequence != expectedFeatureSequence {
t.Errorf("Expected feature sequence to be %s but got %s", expectedFeatureSequence, featureSequence)
Expand Down

0 comments on commit 214e836

Please sign in to comment.