Skip to content

Commit

Permalink
updates uniprot to read IDs (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koeng101 authored Dec 11, 2024
1 parent 01b1ed4 commit 1e2a946
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Updates uniprot parser to read IDs [#104](https://github.com/Koeng101/dnadesign/pull/104)
- Fixes RecursiveFragment to not add flanks to the initial input [#102](https://github.com/Koeng101/dnadesign/pull/102)
- Fixes add flank bug, releases new version of python lib [#101](https://github.com/Koeng101/dnadesign/pull/101)
- Adds feature for adding flanks to RecursiveFragment. [#100](https://github.com/Koeng101/dnadesign/pull/100)
Expand Down
36 changes: 18 additions & 18 deletions lib/bio/uniprot/uniprot.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,35 @@ type Parser struct {
decoder Decoder
}

// NewParser returns a Parser that uses r as the source
// from which to parse fasta formatted sequences.
func NewParser(r io.Reader) *Parser {
decoder := xml.NewDecoder(r)
return &Parser{decoder: decoder}
}

func (p *Parser) Next() (Entry, error) {
decoderToken, err := p.decoder.Token()
for {
decoderToken, err := p.decoder.Token()

// Check decoding
if err != nil {
// If we are the end of the file, return io.EOF
if err.Error() == "EOF" {
return Entry{}, io.EOF
}
}

// Actual parsing
startElement, ok := decoderToken.(xml.StartElement)
if ok && startElement.Name.Local == "entry" {
var e Entry
err = p.decoder.DecodeElement(&e, &startElement)
// Check decoding
if err != nil {
// If we are the end of the file, return io.EOF
if err.Error() == "EOF" {
return Entry{}, io.EOF
}
return Entry{}, err
}
return e, nil

// Actual parsing
startElement, ok := decoderToken.(xml.StartElement)
if ok && startElement.Name.Local == "entry" {
var e Entry
err = p.decoder.DecodeElement(&e, &startElement)
if err != nil {
return Entry{}, err
}
return e, nil
}
}
return p.Next()
}

// BaseURL encodes the base URL for the Uniprot REST API.
Expand Down
7 changes: 7 additions & 0 deletions lib/bio/uniprot/uniprot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,11 @@ func TestGet(t *testing.T) {
if err == nil {
t.Errorf("Expected an error for invalid URL, but got none")
}
for _, reference := range entry.DbReference {
if reference.Type == "Pfam" {
if reference.Id != "PF01353" {
t.Errorf("Expected Pfam ID PF01353")
}
}
}
}
1 change: 1 addition & 0 deletions lib/bio/uniprot/xml.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1e2a946

Please sign in to comment.