Skip to content

Commit

Permalink
remove not-working error handling from GetSequence functions; update …
Browse files Browse the repository at this point in the history
…links in CONTRIBUTING.md (bebop#352)
  • Loading branch information
Alena Maslova committed Nov 25, 2023
1 parent 35a5492 commit ae93c15
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 53 deletions.
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ Unsure where to begin contributing to Poly? You can start by looking through the

### Working on your first Pull Request?

You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).

You can also check out [these](http://makeapullrequest.com/) [tutorials](http://www.firsttimersonly.com/).
You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github).
You can also check out this [tutorial](http://www.firsttimersonly.com/).

At this point, you're ready to make your changes! Feel free to ask for help; everyone is a beginner at first :smile_cat:

Expand Down
31 changes: 10 additions & 21 deletions bio/genbank/genbank.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,10 @@ var (
// StoreFeatureSequences calls StoreSequence on all features.
// The resulting JSON is guaranteed to have useful Feature.Sequence values.
// Useful when exporting for downstream analysis, such as with json.Marshal.
func (sequence *Genbank) StoreFeatureSequences() error {
func (sequence *Genbank) StoreFeatureSequences() {
for i := range sequence.Features {
_, err := sequence.Features[i].StoreSequence()
if err != nil {
return err
}
sequence.Features[i].StoreSequence()
}
return nil
}

// AddFeature adds a feature to a Genbank struct.
Expand All @@ -151,21 +147,18 @@ 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)
}

// StoreSequence infers and assigns the value of feature.Sequence
// if currently an empty string.
func (feature *Feature) StoreSequence() (string, error) {
func (feature *Feature) StoreSequence() string {
if feature.Sequence != "" {
return feature.Sequence, nil
return feature.Sequence
}
seq, err := getFeatureSequence(*feature, feature.Location)
if err == nil {
feature.Sequence = seq
}
return seq, err
seq := getFeatureSequence(*feature, feature.Location)
return seq
}

// Copy creates deep copy of Feature, which supports safe duplication.
Expand All @@ -186,19 +179,15 @@ func CopyLocation(location Location) 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
parentSequence := feature.ParentSequence.Sequence

if len(location.SubLocations) == 0 {
sequenceBuffer.WriteString(parentSequence[location.Start:location.End])
} else {
for _, subLocation := range location.SubLocations {
sequence, err := getFeatureSequence(feature, subLocation)
if err != nil {
return "", err
}

sequence := getFeatureSequence(feature, subLocation)
sequenceBuffer.WriteString(sequence)
}
}
Expand All @@ -209,7 +198,7 @@ func getFeatureSequence(feature Feature, location Location) (string, error) {
sequenceString = transform.ReverseComplement(sequenceString)
}

return sequenceString, nil
return sequenceString
}

// WriteTo implements the io.WriterTo interface on genbank records.
Expand Down
14 changes: 7 additions & 7 deletions bio/genbank/genbank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,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 @@ -210,21 +210,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 @@ -235,14 +235,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 @@ -331,7 +331,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
4 changes: 2 additions & 2 deletions bio/polyjson/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func ExamplePoly_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 @@ -144,7 +144,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
11 changes: 4 additions & 7 deletions bio/polyjson/polyjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ func (sequence *Poly) AddFeature(feature *Feature) error {
}

// GetSequence takes a feature and returns a sequence string for that 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 @@ -93,10 +93,7 @@ func getFeatureSequence(feature Feature, location Location) (string, error) {
sequenceBuffer.WriteString(parentSequence[location.Start:location.End])
} else {
for _, subLocation := range location.SubLocations {
sequence, err := getFeatureSequence(feature, subLocation)
if err != nil { // todo: test error
return "", err
}
sequence := getFeatureSequence(feature, subLocation)
sequenceBuffer.WriteString(sequence)
}
}
Expand All @@ -108,7 +105,7 @@ func getFeatureSequence(feature Feature, location Location) (string, error) {
sequenceString = sequenceBuffer.String()
}

return sequenceString, nil
return sequenceString
}

// Parse parses a Poly JSON file and adds appropriate pointers to struct.
Expand Down
2 changes: 1 addition & 1 deletion bio/polyjson/polyjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestFeature_GetSequence(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 @@ -92,7 +92,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 @@ -125,7 +125,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 @@ -158,7 +158,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 @@ -317,7 +317,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 @@ -340,7 +340,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 @@ -391,7 +391,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 @@ -38,7 +38,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 @@ -117,7 +117,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 @@ -140,7 +140,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 @@ -175,7 +175,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 @@ -198,7 +198,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 @@ -125,7 +125,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 ae93c15

Please sign in to comment.