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
|
package irelate
import (
"errors"
"fmt"
"strconv"
"strings"
"github.com/brentp/bix"
"github.com/brentp/irelate/interfaces"
)
const MaxUint32 = ^uint32(0)
const MaxInt32 = int(MaxUint32 >> 1)
func RegionToParts(region string) (string, int, int, error) {
parts := strings.Split(region, ":")
// e.g. just "chr"
if len(parts) == 1 {
parts = append(parts, fmt.Sprintf("1-%d", MaxInt32))
}
se := strings.Split(parts[1], "-")
if len(se) != 2 {
return "", 0, 0, errors.New(fmt.Sprintf("unable to parse region: %s", region))
}
s, err := strconv.Atoi(se[0])
if err != nil {
return "", 0, 0, errors.New(fmt.Sprintf("unable to parse region: %s", region))
}
e, err := strconv.Atoi(se[1])
if err != nil {
return "", 0, 0, errors.New(fmt.Sprintf("unable to parse region: %s", region))
}
return parts[0], s, e, nil
}
func AsQueryable(f string) (interfaces.Queryable, error) {
return bix.New(f, 1)
}
|