Skip to content

Instantly share code, notes, and snippets.

@emepyc
Created September 12, 2011 12:50
Show Gist options
  • Save emepyc/1211174 to your computer and use it in GitHub Desktop.
Save emepyc/1211174 to your computer and use it in GitHub Desktop.
type Header []byte
type Hit struct {
subject Header
gi int
qfrom, qto, sfrom, sto int
bitsc float32
}
func parseLine (line Line) *Hit {
parts := bytes.Split(line, []byte("\t"))
var bitscStr []byte
if parts[11][0] == ' ' {
bitscStr = parts[11][1:]
} else {
bitscStr = parts[11]
}
qfrom, _ := strconv.Atoi(string(parts[6]))
qto , _ := strconv.Atoi(string(parts[7]))
sfrom, _ := strconv.Atoi(string(parts[8]))
sto , _ := strconv.Atoi(string(parts[9]))
bitsc, _ := strconv.Atof32(string(bitscStr))
if qfrom > qto {
qfrom, qto = qto, qfrom
}
if sfrom > sto {
sfrom, sto = sto, sfrom
}
gi, gierr := Header(parts[1]).extractGI()
if gierr != nil {
log.Fatal(gierr)
}
return &Hit {
gi: gi,
qfrom: qfrom,
qto: qto,
sfrom: sfrom,
sto: sto,
bitsc: bitsc }
}
func (b Header) extractGI () (int, os.Error) {
gib := make([]byte, 0, 10)
for i,v := range b {
if v == 'g' && b[i+1] == 'i' && b[i+2] == '|' {
for j:=i+3; j<len(b); j++ {
if b[j] == '|' {
gi, err := strconv.Atoi(string(gib))
if err != nil {
return -1, err
}
return gi, nil
}
gib = append(gib, b[j])
}
nerr := os.NewError(fmt.Sprintf("No Gi found in %s", b))
return -1, nerr
}
}
lerr := os.NewError(fmt.Sprintf("No gi| found in: %s", b))
return -1, lerr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment