-
Notifications
You must be signed in to change notification settings - Fork 0
/
plasmid_inventory.go
66 lines (59 loc) · 1.6 KB
/
plasmid_inventory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package stockcenter
import (
"bufio"
"io"
"strings"
"time"
"github.com/dictyBase/modware-import/internal/datasource"
tsource "github.com/dictyBase/modware-import/internal/datasource/tsv"
)
// PlasmidInventory is the container for plasmid inventory
type PlasmidInventory struct {
PlasmidID string
PrivateComment string
StoredOn time.Time
PhysicalLocation string
StoredAs string
ObtainedAs string
RecordLine string
}
// PlasmidInventoryReader is the defined interface for reading the data
type PlasmidInventoryReader interface {
datasource.IteratorWithoutValue
Value() (*PlasmidInventory, error)
}
type tsvPlasmidInventoryReader struct {
*tsource.TsvReader
}
// NewTsvPlasmidInventoryReader is to get an instance of PlasmidInventoryReader
func NewTsvPlasmidInventoryReader(r io.Reader) PlasmidInventoryReader {
tr := bufio.NewScanner(r)
return &tsvPlasmidInventoryReader{&tsource.TsvReader{Reader: tr}}
}
// Value gets a new StrainInventory instance
func (pir *tsvPlasmidInventoryReader) Value() (*PlasmidInventory, error) {
inv := new(PlasmidInventory)
if pir.Err != nil {
return inv, pir.Err
}
inv.PlasmidID = pir.Record[0]
inv.PhysicalLocation = pir.Record[1]
if len(pir.Record[2]) > 0 {
inv.ObtainedAs = pir.Record[2]
}
if len(pir.Record[3]) > 0 {
inv.StoredAs = pir.Record[3]
}
if len(pir.Record[4]) > 0 {
storedOn, err := parseInvDate(pir.Record[4])
if err != nil {
return inv, err
}
inv.StoredOn = storedOn
}
if len(pir.Record[5]) > 0 {
inv.PrivateComment = pir.Record[5]
}
inv.RecordLine = strings.Join(pir.Record, "\t")
return inv, nil
}