Skip to content

Commit

Permalink
Add Get feature, plus improve uniprot parser (#37)
Browse files Browse the repository at this point in the history
* Add Get feature, plus improve uniprot parser
  • Loading branch information
Koeng101 authored Dec 20, 2023
1 parent 5f1535f commit cde4570
Show file tree
Hide file tree
Showing 6 changed files with 4,589 additions and 99 deletions.
10 changes: 3 additions & 7 deletions lib/bio/bio.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,9 @@ func NewPileupParserWithMaxLineLength(r io.Reader, maxLineLength int) (*Parser[*
}

// NewUniprotParser initiates a new Uniprot parser from an io.Reader. No
// maxLineLength is necessary. The parser should be reading a gzipped xml file.
func NewUniprotParser(r io.Reader) (*Parser[*uniprot.Entry, *uniprot.Header], error) {
parser, err := uniprot.NewParser(r)
if err != nil {
return &Parser[*uniprot.Entry, *uniprot.Header]{}, err
}
return &Parser[*uniprot.Entry, *uniprot.Header]{parserInterface: parser}, nil
// maxLineLength is necessary.
func NewUniprotParser(r io.Reader) *Parser[*uniprot.Entry, *uniprot.Header] {
return &Parser[*uniprot.Entry, *uniprot.Header]{parserInterface: uniprot.NewParser(r)}
}

/******************************************************************************
Expand Down
15 changes: 3 additions & 12 deletions lib/bio/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/koeng101/dnadesign/lib/bio"
"github.com/koeng101/dnadesign/lib/bio/fasta"
"github.com/koeng101/dnadesign/lib/bio/uniprot"
)

// Example_read shows an example of reading a file from disk.
Expand Down Expand Up @@ -294,7 +293,7 @@ func ExampleNewUniprotParser() {
// The following is a real entry in Swiss-Prot. We're going to gzip it and
// put the gzipped text as an io.Reader to mock a file. You can edit the
// text here to see how the parser works.
uniprotEntryText := `<entry dataset="Swiss-Prot" created="2009-05-05" modified="2020-08-12" version="9" xmlns="http://uniprot.org/uniprot">
uniprotEntryText := strings.NewReader(`<entry dataset="Swiss-Prot" created="2009-05-05" modified="2020-08-12" version="9" xmlns="http://uniprot.org/uniprot">
<accession>P0C9F0</accession>
<name>1001R_ASFK5</name>
<protein>
Expand Down Expand Up @@ -378,17 +377,9 @@ func ExampleNewUniprotParser() {
<evidence type="ECO:0000250" key="1"/>
<evidence type="ECO:0000305" key="2"/>
<sequence length="122" mass="14969" checksum="C5E63C34B941711C" modified="2009-05-05" version="1">MVRLFYNPIKYLFYRRSCKKRLRKALKKLNFYHPPKECCQIYRLLENAPGGTYFITENMTNELIMIAKDPVDKKIKSVKLYLTGNYIKINQHYYINIYMYLMRYNQIYKYPLICFSKYSKIL</sequence>
</entry>`
// Encode the string into an gzip io.Reader
var buf bytes.Buffer
gz := gzip.NewWriter(&buf)
_, _ = gz.Write([]byte(uniprotEntryText))
_ = gz.Close()

r := bytes.NewReader(buf.Bytes())

</entry>`)
// Now we load the parser, and get the first entry out.
parser, _ := uniprot.NewParser(r)
parser := bio.NewUniprotParser(uniprotEntryText)
entry, _ := parser.Next()

fmt.Println(entry.Accession[0])
Expand Down
Loading

0 comments on commit cde4570

Please sign in to comment.