From ae93c15e41392cedf648f0664a6cea33fbe8f085 Mon Sep 17 00:00:00 2001 From: Alena Maslova <4malien@gmail.com> Date: Sat, 25 Nov 2023 21:20:20 +0300 Subject: [PATCH] remove not-working error handling from GetSequence functions; update links in CONTRIBUTING.md (#352) --- CONTRIBUTING.md | 5 ++--- bio/genbank/genbank.go | 31 ++++++++++-------------------- bio/genbank/genbank_test.go | 14 +++++++------- bio/polyjson/example_test.go | 4 ++-- bio/polyjson/polyjson.go | 11 ++++------- bio/polyjson/polyjson_test.go | 2 +- synthesis/codon/codon_test.go | 12 ++++++------ synthesis/codon/example_test.go | 10 +++++----- tutorials/001_input_output_test.go | 2 +- 9 files changed, 38 insertions(+), 53 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b29dc2a8b..2276e4ec9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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: diff --git a/bio/genbank/genbank.go b/bio/genbank/genbank.go index f2152b23b..5b8245af6 100644 --- a/bio/genbank/genbank.go +++ b/bio/genbank/genbank.go @@ -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. @@ -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. @@ -186,7 +179,7 @@ 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 @@ -194,11 +187,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 { - return "", err - } - + sequence := getFeatureSequence(feature, subLocation) sequenceBuffer.WriteString(sequence) } } @@ -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. diff --git a/bio/genbank/genbank_test.go b/bio/genbank/genbank_test.go index 8e148c5c6..df486e34a 100644 --- a/bio/genbank/genbank_test.go +++ b/bio/genbank/genbank_test.go @@ -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) @@ -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) @@ -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) @@ -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 { diff --git a/bio/polyjson/example_test.go b/bio/polyjson/example_test.go index ec5899771..f98ec1d75 100644 --- a/bio/polyjson/example_test.go +++ b/bio/polyjson/example_test.go @@ -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) @@ -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) diff --git a/bio/polyjson/polyjson.go b/bio/polyjson/polyjson.go index 359370e5a..7183eb950 100644 --- a/bio/polyjson/polyjson.go +++ b/bio/polyjson/polyjson.go @@ -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 @@ -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) } } @@ -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. diff --git a/bio/polyjson/polyjson_test.go b/bio/polyjson/polyjson_test.go index dedd70397..47331289d 100644 --- a/bio/polyjson/polyjson_test.go +++ b/bio/polyjson/polyjson_test.go @@ -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 { diff --git a/synthesis/codon/codon_test.go b/synthesis/codon/codon_test.go index 0374e7999..8f4979f10 100644 --- a/synthesis/codon/codon_test.go +++ b/synthesis/codon/codon_test.go @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) } } diff --git a/synthesis/codon/example_test.go b/synthesis/codon/example_test.go index 213ce650b..e30e30ecf 100644 --- a/synthesis/codon/example_test.go +++ b/synthesis/codon/example_test.go @@ -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. @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) } } diff --git a/tutorials/001_input_output_test.go b/tutorials/001_input_output_test.go index b0d252007..11cb3d215 100644 --- a/tutorials/001_input_output_test.go +++ b/tutorials/001_input_output_test.go @@ -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)