remove bytes.Copy

replace all calls with calls to copy
use copy in regexp and bytes.Buffer

R=rsc
CC=golang-dev
https://golang.org/cl/157073
This commit is contained in:
Rob Pike 2009-11-18 15:24:24 -08:00
parent 093493c6a5
commit e70cedfaec
22 changed files with 147 additions and 218 deletions

View file

@ -39,7 +39,6 @@ package main
import (
"bufio";
"bytes";
"flag";
"os";
"strings";
@ -55,7 +54,7 @@ func min(a, b int) int {
if a < b {
return a
}
return b
return b;
}
type AminoAcid struct {
@ -63,23 +62,23 @@ type AminoAcid struct {
c byte;
}
var lastrandom uint32 = 42
var lastrandom uint32 = 42
// Random number between 0.0 and 1.0
func myrandom() float {
const (
IM = 139968;
IA = 3877;
IC = 29573;
IM = 139968;
IA = 3877;
IC = 29573;
)
lastrandom = (lastrandom * IA + IC) % IM;
lastrandom = (lastrandom*IA + IC) % IM;
// Integer to float conversions are faster if the integer is signed.
return float(int32(lastrandom)) / IM;
}
func AccumulateProbabilities(genelist []AminoAcid) {
for i := 1; i < len(genelist); i++ {
genelist[i].p += genelist[i-1].p;
genelist[i].p += genelist[i-1].p
}
}
@ -90,16 +89,16 @@ func AccumulateProbabilities(genelist []AminoAcid) {
// It assumes that WIDTH <= len(s) + 1.
func RepeatFasta(s []byte, count int) {
pos := 0;
s2 := make([]byte, len(s) + WIDTH);
bytes.Copy(s2, s);
bytes.Copy(s2[len(s):len(s2)], s);
s2 := make([]byte, len(s)+WIDTH);
copy(s2, s);
copy(s2[len(s):len(s2)], s);
for count > 0 {
line := min(WIDTH, count);
out.Write(s2[pos:pos+line]);
out.Write(s2[pos : pos+line]);
out.WriteByte('\n');
pos += line;
if pos >= len(s) {
pos -= len(s);
pos -= len(s)
}
count -= line;
}
@ -114,7 +113,7 @@ func RepeatFasta(s []byte, count int) {
// This sequence is repeated count times.
// Between each WIDTH consecutive characters, the function prints a newline.
func RandomFasta(genelist []AminoAcid, count int) {
buf := make([]byte, WIDTH + 1);
buf := make([]byte, WIDTH+1);
for count > 0 {
line := min(WIDTH, count);
for pos := 0; pos < line; pos++ {
@ -125,7 +124,7 @@ func RandomFasta(genelist []AminoAcid, count int) {
buf[pos] = genelist[i].c;
}
buf[line] = '\n';
out.Write(buf[0:line + 1]);
out.Write(buf[0 : line+1]);
count -= line;
}
}
@ -136,29 +135,29 @@ func main() {
flag.Parse();
iub := []AminoAcid {
AminoAcid{ 0.27, 'a' },
AminoAcid{ 0.12, 'c' },
AminoAcid{ 0.12, 'g' },
AminoAcid{ 0.27, 't' },
AminoAcid{ 0.02, 'B' },
AminoAcid{ 0.02, 'D' },
AminoAcid{ 0.02, 'H' },
AminoAcid{ 0.02, 'K' },
AminoAcid{ 0.02, 'M' },
AminoAcid{ 0.02, 'N' },
AminoAcid{ 0.02, 'R' },
AminoAcid{ 0.02, 'S' },
AminoAcid{ 0.02, 'V' },
AminoAcid{ 0.02, 'W' },
AminoAcid{ 0.02, 'Y' }
iub := []AminoAcid{
AminoAcid{0.27, 'a'},
AminoAcid{0.12, 'c'},
AminoAcid{0.12, 'g'},
AminoAcid{0.27, 't'},
AminoAcid{0.02, 'B'},
AminoAcid{0.02, 'D'},
AminoAcid{0.02, 'H'},
AminoAcid{0.02, 'K'},
AminoAcid{0.02, 'M'},
AminoAcid{0.02, 'N'},
AminoAcid{0.02, 'R'},
AminoAcid{0.02, 'S'},
AminoAcid{0.02, 'V'},
AminoAcid{0.02, 'W'},
AminoAcid{0.02, 'Y'},
};
homosapiens := []AminoAcid {
AminoAcid{ 0.3029549426680, 'a' },
AminoAcid{ 0.1979883004921, 'c' },
AminoAcid{ 0.1975473066391, 'g' },
AminoAcid{ 0.3015094502008, 't' }
homosapiens := []AminoAcid{
AminoAcid{0.3029549426680, 'a'},
AminoAcid{0.1979883004921, 'c'},
AminoAcid{0.1975473066391, 'g'},
AminoAcid{0.3015094502008, 't'},
};
AccumulateProbabilities(iub);
@ -166,17 +165,17 @@ func main() {
alu := strings.Bytes(
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA");
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA");
out.WriteString(">ONE Homo sapiens alu\n");
RepeatFasta(alu, 2 * *n);
RepeatFasta(alu, 2**n);
out.WriteString(">TWO IUB ambiguity codes\n");
RandomFasta(iub, 3 * *n);
RandomFasta(iub, 3**n);
out.WriteString(">THREE Homo sapiens frequency\n");
RandomFasta(homosapiens, 5 * *n);
RandomFasta(homosapiens, 5**n);
}