Skip to content

Commit

Permalink
bug fix - last enzyme in *.re file did not get parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchuette committed Sep 15, 2018
1 parent 086a498 commit 1a54297
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
13 changes: 11 additions & 2 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ func ParseEnzymesFromFile(file string) (map[string]RestrictEnzyme, error) {

Loop:
for i, n := 0, len(b); i < n; i++ {
// decide what to do next
// current char is the last char in the document => add parsed results to `enzymesMap'
if (i + 1) == n {
if itemContainer != nil {
if _, ok := enzymesMap[itemContainer.Name]; !ok {
enzymesMap[itemContainer.Name] = *itemContainer
}
}
}

// otherwise, the document is not yet fully parsed => decide what to do next
if i < len(b)-2 {
// if current char is a new line delimiter, decide how to proceed
if b[i] == '\n' {
Expand Down Expand Up @@ -126,7 +135,7 @@ Loop:
}
}

fmt.Printf("parsed %d enzymes from '%s'\n", line, file)
fmt.Printf("parsed %d of %d enzyme(s) from '%s'\n", len(enzymesMap), line, file)
return enzymesMap, nil
}

Expand Down
30 changes: 18 additions & 12 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cloningprimer

import (
"errors"
"log"
"testing"
)

Expand Down Expand Up @@ -37,10 +38,10 @@ func TestParseEnzymesFromFile(t *testing.T) {
want: map[string]RestrictEnzyme{
"AclI": {
Name: "AclI",
RecognitionSite: "aslkfhsdf",
NoPalinCleav: "sdlfkj",
ID: "sldkfj",
Isoschizomeres: []string{"sdfklj", "sdlfkj"},
RecognitionSite: "invalid",
NoPalinCleav: "invalid",
ID: "invalid",
Isoschizomeres: []string{"invalid", "invalid"},
},
},
err: nil,
Expand All @@ -51,10 +52,10 @@ func TestParseEnzymesFromFile(t *testing.T) {
want: map[string]RestrictEnzyme{
"AclI": {
Name: "AclI",
RecognitionSite: "aslkfhsdf",
NoPalinCleav: "sdlfkj",
ID: "sdfk",
Isoschizomeres: []string{"sdlkfj", "sdflkj"},
RecognitionSite: "invalid",
NoPalinCleav: "invalid",
ID: "invalid",
Isoschizomeres: []string{"invalid", "invalid"},
},
},
err: nil,
Expand All @@ -65,10 +66,10 @@ func TestParseEnzymesFromFile(t *testing.T) {
want: map[string]RestrictEnzyme{
"AclI": {
Name: "AclI",
RecognitionSite: "slfkj",
NoPalinCleav: "sdlkfj",
ID: "sldkfj",
Isoschizomeres: []string{"sldkjf"},
RecognitionSite: "invalid",
NoPalinCleav: "invalid",
ID: "invalid",
Isoschizomeres: []string{"invalid", "invalid"},
},
},
err: nil,
Expand All @@ -78,6 +79,8 @@ func TestParseEnzymesFromFile(t *testing.T) {
// loop over test cases
for _, c := range cases {
got, err := ParseEnzymesFromFile(c.in)
log.Printf("parsed len: %v, expect len: %v\n", len(got), len(c.want))
log.Printf("parsed: %v, expect: %v\n", got, c.want)

// test similarity of expected and received value
if !isSimilarMap(got, c.want) {
Expand Down Expand Up @@ -178,6 +181,9 @@ func isSimilarMap(m1, m2 map[string]RestrictEnzyme) bool {
if (m1 == nil) && (m2 == nil) {
return true
}
if (m1 == nil) || (m2 == nil) {
return false
}
for k, v := range m1 {
// test fields of type string
if val, ok := m2[k]; !ok {
Expand Down
2 changes: 1 addition & 1 deletion tests/parse2.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* a parsed without a problem
*/
enzyme_name recognition_sequence non_palindromic_cleaveage PDB_ID isoschizomers
'AclI' 'AACGTT' 'no'
'AclI' 'AACGTT' 'no' 'A1A1' 'AclI'
1 change: 1 addition & 0 deletions tests/parse3.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
* a parsed without a problem; even without column labels!
*/
'AclI' 'AACGTT' 'no' 'A1A1' 'AclI'
'AclII' 'ACCGGT' 'no' 'A2A2' 'AclII'

0 comments on commit 1a54297

Please sign in to comment.