예제 #1
0
// not crazy about this
func capitalize(sentence []byte) []byte {
	l := len(sentence)
	l1 := l - 1
	for i := 0; i < l1; i++ {
		if sentence[i] == ' ' && sentence[i+1] != ' ' {
			sentence[i+1] = bytes.ToUpper(sentence[i+1 : i+2])[0]
		}
	}
	if sentence[0] != ' ' {
		sentence[0] = bytes.ToUpper(sentence[0:1])[0]
	}
	return sentence
}
예제 #2
0
func upperFirst(s string) string {
	if s == "" {
		return ""
	}

	return string(bytes.ToUpper([]byte(s[0:1]))) + s[1:]
}
예제 #3
0
func ParseMessage(line []byte) *Message {
	line = bytes.TrimSpace(line)
	if len(line) <= 0 {
		return nil
	}
	m := new(Message)
	if line[0] == ':' {
		split := bytes.SplitN(line, []byte{' '}, 2)
		if len(split) <= 1 {
			return nil
		}
		m.Prefix = string(split[0][1:])
		line = split[1]
	}
	split := bytes.SplitN(line, []byte{':'}, 2)
	args := bytes.Split(bytes.TrimSpace(split[0]), []byte{' '})
	m.Command = string(bytes.ToUpper(args[0]))
	m.Args = make([]string, 0, len(args))
	for _, arg := range args[1:] {
		m.Args = append(m.Args, string(arg))
	}
	if len(split) > 1 {
		m.Args = append(m.Args, string(split[1]))
	}
	return m
}
예제 #4
0
// 对 parameters 里的参数做 MD5 签名.
// 签名方法:
// 1. 对参数 parameters 按照 key 的 ASCII 码从小到大排序(字典序)后,使用 URL 键值对的
// 格式(即 key1=value1&key2=value2...)拼接成字符串 string1,
// 注意:值为空的参数不参与签名;
// 2. 在 string1 最后拼接上 key=Key(商户支付密钥) 得到 stringSignTemp 字符串, 并对
// stringSignTemp 进行 md5 运算,再将得到的字符串所有字符转换为大写,得到 sign 值
// signValue。
//
//  parameters:  待签名的参数
//  Key:         支付签名的 Key
func MD5Signature(parameters map[string]string, Key string) (signature string) {
	keys := make([]string, 0, len(parameters))
	for key, value := range parameters {
		if value == "" { // 值为空不参加签名
			continue
		}
		if key == "sign" {
			continue
		}

		keys = append(keys, key)
	}
	sort.Strings(keys)

	Hash := md5.New()
	hashsum := make([]byte, md5.Size*2)

	for _, key := range keys {
		value := parameters[key]

		Hash.Write([]byte(key))
		Hash.Write([]byte{'='})
		Hash.Write([]byte(value))
		Hash.Write([]byte{'&'})
	}
	Hash.Write([]byte("key="))
	Hash.Write([]byte(Key))

	hex.Encode(hashsum, Hash.Sum(nil))
	signature = string(bytes.ToUpper(hashsum))
	return
}
예제 #5
0
파일: mapgen.go 프로젝트: jclohmann/mapgen
func (mg MapGen) Generate() error {
	filename := filepath.Join(mg.path, strings.ToLower(mg.typeName)+"-mapping.go")
	if _, err := os.Stat(filename); err == nil {
		os.Remove(filename)
	}

	data := mapGenTplData{
		PackageName: mg.packageName,
		TypeName:    mg.typeName,
		Targets:     make(map[string]string),
	}
	removeSpecialCharsRegex := regexp.MustCompile("[^a-zA-Z0-9]+")
	for _, targetType := range mg.targets {
		typeName := targetType

		typeNameBytes := []byte(typeName)

		typeNameBytes = removeSpecialCharsRegex.ReplaceAll(typeNameBytes, []byte(""))

		// set the first character to uppercase
		typeNameBytes[0] = bytes.ToUpper(typeNameBytes[0:1])[0]
		typeName = string(typeNameBytes)

		data.Targets[targetType] = typeName
	}

	file, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0777)
	if err != nil {
		return err
	}
	err = mapGenTpl.Execute(file, data)

	return err
}
예제 #6
0
func ExampleWordDecoder_Decode() {
	dec := new(WordDecoder)
	header, err := dec.Decode("=?utf-8?q?=C2=A1Hola,_se=C3=B1or!?=")
	if err != nil {
		panic(err)
	}
	fmt.Println(header)

	dec.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
		switch charset {
		case "x-case":
			// Fake character set for example.
			// Real use would integrate with packages such
			// as code.google.com/p/go-charset
			content, err := ioutil.ReadAll(input)
			if err != nil {
				return nil, err
			}
			return bytes.NewReader(bytes.ToUpper(content)), nil
		}
		return nil, fmt.Errorf("unhandled charset %q", charset)
	}
	header, err = dec.Decode("=?x-case?q?hello!?=")
	if err != nil {
		panic(err)
	}
	fmt.Println(header)
	// Output:
	// ¡Hola, señor!
	// HELLO!
}
예제 #7
0
파일: sign_test.go 프로젝트: Wang/wechat
// 传统的签名代码, Sign 是优化后的代码, 要提高 35% 的速度
func Sign2(parameters map[string]string, apiKey string, fn func() hash.Hash) string {
	ks := make([]string, 0, len(parameters))
	for k := range parameters {
		if k == "sign" {
			continue
		}
		ks = append(ks, k)
	}
	sort.Strings(ks)

	if fn == nil {
		fn = md5.New
	}
	h := fn()
	signature := make([]byte, h.Size()*2)

	for _, k := range ks {
		v := parameters[k]
		if v == "" {
			continue
		}
		h.Write([]byte(k))
		h.Write([]byte{'='})
		h.Write([]byte(v))
		h.Write([]byte{'&'})
	}
	h.Write([]byte("key="))
	h.Write([]byte(apiKey))

	hex.Encode(signature, h.Sum(nil))
	return string(bytes.ToUpper(signature))
}
예제 #8
0
파일: vimdoc.go 프로젝트: FooSoft/md2vim
func (v *vimDoc) Header(out *bytes.Buffer, text func() bool, level int, id string) {
	initPos := out.Len()
	if v.flags&flagNoRules == 0 {
		switch level {
		case 1:
			v.writeRule(out, "=")
		case 2:
			v.writeRule(out, "-")
		}
	}

	headingPos := out.Len()
	if !text() {
		out.Truncate(initPos)
		return
	}

	var temp []byte
	temp = append(temp, out.Bytes()[headingPos:]...)
	out.Truncate(headingPos)

	h := &heading{temp, level}
	v.headings = append(v.headings, h)

	tag := fmt.Sprintf("*%s*", v.buildHelpTag(h.text))
	v.writeSplitText(out, bytes.ToUpper(h.text), []byte(tag), " ", 2)
	out.WriteString("\n")
}
예제 #9
0
파일: case.go 프로젝트: rif/golang-stuff
func main() {
	quickBrownFox := []byte("The quick brown fox jumped over the lazy dog")

	title := bytes.Title(quickBrownFox)
	log.Printf("Title turned %q into %q", quickBrownFox, title)

	allTitle := bytes.ToTitle(quickBrownFox)
	log.Printf("ToTitle turned %q to %q", quickBrownFox, allTitle)

	allTitleTurkish := bytes.ToTitleSpecial(unicode.TurkishCase, quickBrownFox)
	log.Printf("ToTitleSpecial turned %q into %q using the Turkish case rules", quickBrownFox, allTitleTurkish)

	lower := bytes.ToLower(title)
	log.Printf("ToLower turned %q into %q", title, lower)

	turkishCapitalI := []byte("İ")
	turkishLowerI := bytes.ToLowerSpecial(unicode.TurkishCase, turkishCapitalI)
	log.Printf("ToLowerSpecial turned %q into %q using the Turkish case rules", turkishCapitalI, turkishLowerI)

	upper := bytes.ToUpper(quickBrownFox)
	log.Printf("ToUpper turned %q to %q", quickBrownFox, upper)

	upperSpecial := bytes.ToUpperSpecial(unicode.TurkishCase, quickBrownFox)
	log.Printf("ToUpperSpecial turned %q into %q using the Turkish case rules", quickBrownFox, upperSpecial)
}
예제 #10
0
파일: sign.go 프로젝트: btbxbob/wechat
// jssdk 支付签名, signType 只支持 "MD5", "SHA1", 传入其他的值会 panic.
func JsapiSign(appId, timeStamp, nonceStr, packageStr, signType string, apiKey string) string {
	var h hash.Hash
	switch signType {
	case "MD5":
		h = md5.New()
	case "SHA1":
		h = sha1.New()
	default:
		panic("unsupported signType")
	}
	bufw := bufio.NewWriterSize(h, 128)

	// appId
	// nonceStr
	// package
	// signType
	// timeStamp
	bufw.WriteString("appId=")
	bufw.WriteString(appId)
	bufw.WriteString("&nonceStr=")
	bufw.WriteString(nonceStr)
	bufw.WriteString("&package=")
	bufw.WriteString(packageStr)
	bufw.WriteString("&signType=")
	bufw.WriteString(signType)
	bufw.WriteString("&timeStamp=")
	bufw.WriteString(timeStamp)
	bufw.WriteString("&key=")
	bufw.WriteString(apiKey)

	bufw.Flush()
	signature := make([]byte, hex.EncodedLen(h.Size()))
	hex.Encode(signature, h.Sum(nil))
	return string(bytes.ToUpper(signature))
}
예제 #11
0
파일: sign.go 프로젝트: btbxbob/wechat
// Sign 微信支付签名.
//  params: 待签名的参数集合
//  apiKey: api密钥
//  fn:     func() hash.Hash, 如果为 nil 则默认用 md5.New
func Sign(params map[string]string, apiKey string, fn func() hash.Hash) string {
	if fn == nil {
		fn = md5.New
	}
	h := fn()
	bufw := bufio.NewWriterSize(h, 128)

	keys := make([]string, 0, len(params))
	for k := range params {
		if k == "sign" {
			continue
		}
		keys = append(keys, k)
	}
	sort.Strings(keys)

	for _, k := range keys {
		v := params[k]
		if v == "" {
			continue
		}
		bufw.WriteString(k)
		bufw.WriteByte('=')
		bufw.WriteString(v)
		bufw.WriteByte('&')
	}
	bufw.WriteString("key=")
	bufw.WriteString(apiKey)

	bufw.Flush()
	signature := make([]byte, hex.EncodedLen(h.Size()))
	hex.Encode(signature, h.Sum(nil))
	return string(bytes.ToUpper(signature))
}
예제 #12
0
파일: parser.go 프로젝트: rainliu/GoABNF
func (this *Parser) MatchExpectedIgnoreCase(value int, expected byte) bool {
	var lowers [2]byte
	lowers[0] = byte(value)
	lowers[1] = expected
	uppers := bytes.ToUpper(lowers[:])
	return uppers[0] == uppers[1] //Character.toUpperCase(value) == Character.toUpperCase(expected);
}
예제 #13
0
파일: post.go 프로젝트: kyanny/qbox
func Top(w http.ResponseWriter, r *http.Request) {
	method := bytes.ToUpper([]byte(r.Method))
	if string(method) != "POST" {
		http.Error(w, string(method)+" is not allowed", 403)
	} else {
		fmt.Fprintln(w, r.Method+" is ok")
	}
}
예제 #14
0
파일: redis.go 프로젝트: davidsoloman/beats
func (redis *Redis) newTransaction(requ, resp *redisMessage) common.MapStr {
	error := common.OK_STATUS
	if resp.IsError {
		error = common.ERROR_STATUS
	}

	var returnValue map[string]common.NetString
	if resp.IsError {
		returnValue = map[string]common.NetString{
			"error": resp.Message,
		}
	} else {
		returnValue = map[string]common.NetString{
			"return_value": resp.Message,
		}
	}

	src := &common.Endpoint{
		Ip:   requ.TcpTuple.Src_ip.String(),
		Port: requ.TcpTuple.Src_port,
		Proc: string(requ.CmdlineTuple.Src),
	}
	dst := &common.Endpoint{
		Ip:   requ.TcpTuple.Dst_ip.String(),
		Port: requ.TcpTuple.Dst_port,
		Proc: string(requ.CmdlineTuple.Dst),
	}
	if requ.Direction == tcp.TcpDirectionReverse {
		src, dst = dst, src
	}

	// resp_time in milliseconds
	responseTime := int32(resp.Ts.Sub(requ.Ts).Nanoseconds() / 1e6)

	event := common.MapStr{
		"@timestamp":   common.Time(requ.Ts),
		"type":         "redis",
		"status":       error,
		"responsetime": responseTime,
		"redis":        returnValue,
		"method":       common.NetString(bytes.ToUpper(requ.Method)),
		"resource":     requ.Path,
		"query":        requ.Message,
		"bytes_in":     uint64(requ.Size),
		"bytes_out":    uint64(resp.Size),
		"src":          src,
		"dst":          dst,
	}
	if redis.SendRequest {
		event["request"] = requ.Message
	}
	if redis.SendResponse {
		event["response"] = resp.Message
	}

	return event
}
예제 #15
0
파일: upcase.go 프로젝트: get3w/get3w
// convert an input string to uppercase
func Upcase(input interface{}, data map[string]interface{}) interface{} {
	switch typed := input.(type) {
	case []byte:
		return bytes.ToUpper(typed)
	case string:
		return strings.ToUpper(typed)
	default:
		return input
	}
}
예제 #16
0
파일: passgo.go 프로젝트: prinsmike/passgo
func (g *Generator) ToUpper(char []byte) byte {
	var b byte
	rand.Seed(time.Now().UTC().UnixNano())
	n := rand.Intn(g.CapitalizeOdds)
	if n == g.CapitalizeOdds-1 {
		b = bytes.ToUpper(char)[0]
	} else {
		b = char[0]
	}
	return b
}
예제 #17
0
파일: jsapi.go 프로젝트: daqinbuyi/wechat
// 设置签名字段.
//  appKey: 商户支付密钥Key
//
//  NOTE: 要求在 JSAPIPayRequestParameters 其他字段设置完毕后才能调用这个函数, 否则签名就不正确.
func (para *JSAPIPayRequestParameters) SetSignature(appKey string) (err error) {
	var Hash hash.Hash
	var hashsum []byte

	switch para.SignMethod {
	case "md5", "MD5":
		Hash = md5.New()
		hashsum = make([]byte, md5.Size*2)

	default:
		err = fmt.Errorf(`unknown sign method: %q`, para.SignMethod)
		return
	}

	// 字典序
	// appId
	// nonceStr
	// package
	// signType
	// timeStamp
	if len(para.AppId) > 0 {
		Hash.Write([]byte("appId="))
		Hash.Write([]byte(para.AppId))
		Hash.Write([]byte{'&'})
	}
	if len(para.NonceStr) > 0 {
		Hash.Write([]byte("nonceStr="))
		Hash.Write([]byte(para.NonceStr))
		Hash.Write([]byte{'&'})
	}
	if len(para.Package) > 0 {
		Hash.Write([]byte("package="))
		Hash.Write([]byte(para.Package))
		Hash.Write([]byte{'&'})
	}
	if len(para.SignMethod) > 0 {
		Hash.Write([]byte("signType="))
		Hash.Write([]byte(para.SignMethod))
		Hash.Write([]byte{'&'})
	}
	if len(para.TimeStamp) > 0 {
		Hash.Write([]byte("timeStamp="))
		Hash.Write([]byte(para.TimeStamp))
		Hash.Write([]byte{'&'})
	}
	Hash.Write([]byte("key="))
	Hash.Write([]byte(appKey))

	hex.Encode(hashsum, Hash.Sum(nil))
	hashsum = bytes.ToUpper(hashsum)

	para.Signature = string(hashsum)
	return
}
예제 #18
0
파일: otpc.go 프로젝트: kisom/cryptutils
func sanitiseSecret(in []byte) []byte {
	in = bytes.ToUpper(in)
	in = bytes.Replace(in, []byte(" "), []byte(""), -1)
	if len(in)%8 != 0 {
		padding := 8 - (len(in) % 8)
		for i := 0; i < padding; i++ {
			in = append(in, '=')
		}
	}
	return in
}
예제 #19
0
파일: filter.go 프로젝트: mingzhi/pileup
func readRefSeq(fnaFile string) map[string][]byte {
	f := openFile(fnaFile)
	fastaReader := seq.NewFastaReader(f)
	fastaReader.DeflineParser = func(s string) string { return strings.Split(strings.TrimSpace(s), " ")[0] }
	m := make(map[string][]byte)
	sequences, err := fastaReader.ReadAll()
	raiseError(err)
	for _, s := range sequences {
		m[s.Id] = bytes.ToUpper(s.Seq)
	}
	return m
}
예제 #20
0
func confirm(prompt string) (bool, error) {
	fmt.Printf("%s (y/N): ", prompt)
	bio := bufio.NewReader(os.Stdin)
	line, _, err := bio.ReadLine()
	if err != nil {
		return false, err
	}
	if len(line) > 0 && bytes.ToUpper(line)[0] == 'Y' {
		return true, nil
	}
	return false, nil
}
예제 #21
0
func (tkn *Tokenizer) scanIdentifier() (int, []byte) {
	buffer := bytes.NewBuffer(make([]byte, 0, 8))
	buffer.WriteByte(byte(tkn.lastChar))
	for tkn.next(); isLetter(tkn.lastChar) || isDigit(tkn.lastChar); tkn.next() {
		buffer.WriteByte(byte(tkn.lastChar))
	}
	uppered := bytes.ToUpper(buffer.Bytes())
	if keywordID, found := keywords[string(uppered)]; found {
		return keywordID, uppered
	}
	return tokID, buffer.Bytes()
}
예제 #22
0
파일: NFAState.go 프로젝트: rainliu/GoABNF
//向迁移函数添加一个映射,给定下一个状态节点
//假定我们的上下文无关文法是大小写不敏感的,当输入字符是char类型并且是字母时,
//生成大写字母和小写字母两个映射
func (this *NFAState) AddTransitByte2(input byte, next *NFAState) *NFAState {
	if input >= 'a' && input <= 'z' && input >= 'A' && input <= 'Z' {
		var b [1]byte
		b[0] = input
		this.AddTransitInt2(int(bytes.ToUpper(b[:])[0]), next)
		this.AddTransitInt2(int(bytes.ToLower(b[:])[0]), next)
		return next
	} else {
		this.AddTransitInt2(int(input), next)
		return next
	}
}
예제 #23
0
파일: lib.go 프로젝트: Fantasim/Langage-Go
func MakeFirstUpperCase(s string) string {

	if len(s) < 2 {
		return strings.ToLower(s)
	}

	bts := []byte(s)

	lc := bytes.ToUpper([]byte{bts[0]})
	rest := bts[1:]

	return string(bytes.Join([][]byte{lc, rest}, nil))
}
예제 #24
0
// 生成 native 支付 静态链接 URL.
//  AppId:      必须, 微信分配的公众账号ID
//  AppKey:     必须, 即 paySignKey, 公众号支付请求中用于加密的密钥 Key
//  NonceStr:   必须, 32个字符以内, 商户生成的随机字符串
//  Timestamp:  必须, unixtime, 商户生成
//  ProductId:  必须, 32个字符以内, 商户需要定义并维护自己的商品id,这个id 与一张订单等价,
//                   微信后台凭借该id 通过POST 商户后台获取交易必须信息;传此参数必须在
//                   申请的时候配置了Package 请求回调地址;
//  MerchantId: 必须, 微信支付分配的商户号
//
//  NOTE: 该函数没有做 url escape, 因为正常情况下根本不需要做 url escape
func NativeURL(AppId, AppKey, NonceStr, Timestamp, ProductId, MerchantId string) string {
	Hash := md5.New()
	hashsum := make([]byte, md5.Size*2)

	// 字典序
	// appid
	// mch_id
	// nonce_str
	// product_id
	// time_stamp
	if len(AppId) > 0 {
		Hash.Write([]byte("appid="))
		Hash.Write([]byte(AppId))
		Hash.Write([]byte{'&'})
	}
	if len(MerchantId) > 0 {
		Hash.Write([]byte("mch_id="))
		Hash.Write([]byte(MerchantId))
		Hash.Write([]byte{'&'})
	}
	if len(NonceStr) > 0 {
		Hash.Write([]byte("nonce_str="))
		Hash.Write([]byte(NonceStr))
		Hash.Write([]byte{'&'})
	}
	if len(ProductId) > 0 {
		Hash.Write([]byte("product_id="))
		Hash.Write([]byte(ProductId))
		Hash.Write([]byte{'&'})
	}
	if len(Timestamp) > 0 {
		Hash.Write([]byte("time_stamp="))
		Hash.Write([]byte(Timestamp))
		Hash.Write([]byte{'&'})
	}
	Hash.Write([]byte("key="))
	Hash.Write([]byte(AppKey))

	hex.Encode(hashsum, Hash.Sum(nil))
	hashsum = bytes.ToUpper(hashsum)

	// weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX
	//          &product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX
	return "weixin://wxpay/bizpayurl?sign=" + string(hashsum) +
		"&appid=" + AppId +
		"&mch_id=" + MerchantId +
		"&product_id=" + ProductId +
		"&time_stamp=" + Timestamp +
		"&nonce_str=" + NonceStr
}
예제 #25
0
파일: filter.go 프로젝트: mingzhi/pileup
func (d *DiversityFilter) findGenome(r *sam.Record, env *lmdb.Env, dbname string) (val []byte, err error) {
	fn := func(txn *lmdb.Txn) error {
		dbi, err := txn.OpenDBI(dbname, 0)
		if err != nil {
			return err
		}
		key := []byte(r.Ref.Name())
		val, err = txn.Get(dbi, key)
		val = bytes.ToUpper(val)
		return err
	}
	err = env.View(fn)
	return
}
예제 #26
0
파일: packet.go 프로젝트: keysonZZZ/kmg
func (p *SuccessPacket) Encode() (b []byte) {
	len := 4 + 2 + 40 + 3 + len(p.Message)
	b = make([]byte, len)
	b[0] = byte(p.OpCode())
	b[1] = byte(p.Identifier)
	binary.BigEndian.PutUint16(b[2:4], uint16(len))
	copy(b[4:6], "S=")
	hex.Encode(b[6:46], p.Auth[:])
	out := bytes.ToUpper(b[6:46])
	copy(b[6:46], out)
	copy(b[46:49], " M=")
	copy(b[49:], p.Message)
	return b
}
예제 #27
0
func transformRegExp(ecmaRegExp string) (goRegExp string) {
	// https://bugzilla.mozilla.org/show_bug.cgi/show_bug.cgi?id=334158
	tmp := []byte(ecmaRegExp)
	for _, value := range transformRegExp_unescape {
		tmp = value.ReplaceAll(tmp, []byte(`$1$2`))
	}
	tmp = transformRegExp_escape_c.ReplaceAllFunc(tmp, func(in []byte) []byte {
		in = bytes.ToUpper(in)
		return []byte(fmt.Sprintf("\\%o", in[0]-64)) // \cA => \001 (A == 65)
	})
	tmp = transformRegExp_unescape_c.ReplaceAll(tmp, []byte(`c`))
	tmp = transformRegExp_unescapeDollar.ReplaceAll(tmp, []byte(`$1`))
	tmp = transformRegExp_matchSlashU.ReplaceAll(tmp, []byte(`\x{$1}`))
	return string(tmp)
}
예제 #28
0
// 创建订单查询的 package 数据
func MakeOrderQueryRequestPackage(
	OutTradeNo string, // 第三方唯一订单号
	PartnerId string, // 财付通商户身份标识
	PartnerKey string, // 财付通商户权限密钥

) string {

	// 签名的源
	const keysLen1 = len(`out_trade_no=&partner=&key=`)
	n1 := keysLen1 + len(OutTradeNo) + len(PartnerId) + len(PartnerKey)

	// 最终结果
	const keysLen2 = len(`out_trade_no=&partner=&sign=`)
	n2 := keysLen2 + len(OutTradeNo) + len(PartnerId) + 32 // md5sum

	var n int
	if n1 >= n2 {
		n = n1
	} else {
		n = n2
	}
	buf := make([]byte, n)

	string1 := buf[:0]

	// 字典序
	// out_trade_no
	// partner
	string1 = append(string1, "out_trade_no="...)
	string1 = append(string1, OutTradeNo...)
	string1 = append(string1, "&partner="...)
	string1 = append(string1, PartnerId...)

	string2 := string1 // 到目前为止两者相同

	string1 = append(string1, "&key="...)
	string1 = append(string1, PartnerKey...)

	hashSumArray := md5.Sum(string1)

	string2 = append(string2, "&sign="...)
	signature := buf[len(string2) : len(string2)+32]
	hex.Encode(signature, hashSumArray[:])
	string2 = append(string2, bytes.ToUpper(signature)...)

	return string(string2)
}
예제 #29
0
파일: filter.go 프로젝트: mingzhi/pileup
// Obtain the sequence of a read mapping to the reference genome.
// Return the mapped sequence.
func map2Ref(r *sam.Record) []byte {
	s := []byte{}
	p := 0                                // position in the read sequence.
	read := bytes.ToUpper(r.Seq.Expand()) // read sequence.
	for _, c := range r.Cigar {
		switch c.Type() {
		case sam.CigarMatch, sam.CigarMismatch, sam.CigarEqual:
			s = append(s, read[p:p+c.Len()]...)
			p += c.Len()
		case sam.CigarInsertion, sam.CigarSoftClipped, sam.CigarHardClipped:
			p += c.Len()
		case sam.CigarDeletion, sam.CigarSkipped:
			s = append(s, bytes.Repeat([]byte{'*'}, c.Len())...)
		}
	}

	return s
}
예제 #30
0
파일: Seq.go 프로젝트: shenwei356/bio
/*BaseContent returns base content for given bases. For example:

  seq.BaseContent("gc")

*/
func (seq *Seq) BaseContent(list string) float64 {
	if len(seq.Seq) == 0 {
		return float64(0)
	}

	sum := 0
	for _, b := range []byte(list) {
		up := bytes.ToUpper([]byte{b})
		lo := bytes.ToLower([]byte{b})
		if string(up) == string(lo) {
			sum += bytes.Count(seq.Seq, up)
		} else {
			sum += bytes.Count(seq.Seq, up) + bytes.Count(seq.Seq, lo)
		}
	}

	return float64(sum) / float64(len(seq.Seq))
}