Esempio n. 1
0
func main() {
	const k = 4
	const n = 1 << (2 * 4)

	trMap := [256]byte{'A': '0', 'C': '1', 'G': '2', 'T': '3'}
	comp := make([]int, n)
	dna, err := gene.ReadFasta(os.Stdin)
	if err != nil {
		log.Fatal(err)
	}

	for i := 0; i < len(dna.Data)-k+1; i++ {
		kmer := dna.Data[i : i+k]
		mapped := make([]byte, k)
		for j := 0; j < k; j++ {
			mapped[j] = trMap[kmer[j]]
		}
		p, err := strconv.ParseInt(string(mapped), 4, 32)
		if err != nil {
			log.Fatal(err)
		}
		comp[int(p)] += 1
	}
	fmt.Println(comp)
}
Esempio n. 2
0
func findMotif(accessId string) {
	resp, err := http.Get("http://www.uniprot.org/uniprot/" + accessId + ".fasta")
	if err != nil {
		log.Println(err)
		return
	}
	defer resp.Body.Close()

	s, err := gene.ReadFasta(resp.Body)
	if err != nil {
		log.Println(err)
		return
	}

	start := 0
	for {
		loc := nGlycoMotifRe.FindStringIndex(s.Data[start:])
		if loc == nil {
			break
		}

		if start == 0 {
			fmt.Println(accessId)
		}
		fmt.Print(start+loc[0]+1, " ")
		start += loc[0] + 1
	}
	if start > 0 {
		fmt.Println()
	}
}
Esempio n. 3
0
func main() {
	s, _ := gene.ReadFasta(os.Stdin)

	var matchings func(int, int) *big.Int
	memo := make(map[[2]int]*big.Int)
	matchings = func(begin, end int) *big.Int {
		switch {
		case begin == end:
			return big.NewInt(1)
		case begin > end:
			return big.NewInt(0)
		case (end-begin)%2 == 1:
			return big.NewInt(0)
		}

		key := [2]int{begin, end}
		if n, ok := memo[key]; ok {
			return n
		}

		n := big.NewInt(0)
		compl := Complement[s.Data[begin]]
		for i := begin + 1; i < end; i++ {
			if s.Data[i] == compl {
				var t big.Int
				t.Mul(matchings(begin+1, i), matchings(i+1, end))
				n.Add(n, &t)
			}
		}
		memo[key] = n
		return n
	}

	n := matchings(0, len(s.Data))
	//n1m := big.NewInt(1000000)
	//n1m.Rem(n, n1m)
	//fmt.Println(n1m)
	fmt.Println(n)
}
Esempio n. 4
0
func main() {
	s, _ := gene.ReadFasta(os.Stdin)

	nA := 0
	nC := 0
	for _, b := range s.Data {
		switch b {
		case 'A':
			nA++
		case 'C':
			nC++
		}
	}

	matchings := big.NewInt(1)
	for i := 1; i <= nA; i++ {
		matchings.Mul(matchings, big.NewInt(int64(i)))
	}
	for i := 1; i <= nC; i++ {
		matchings.Mul(matchings, big.NewInt(int64(i)))
	}
	fmt.Println(matchings)
}