Example #1
0
func main() {
	br := bufio.NewReader(os.Stdin)

	line, err := br.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	rna := line[:len(line)-1]

	prot, err := gene.Translate(rna)
	fmt.Println(prot)
	if err != nil {
		log.Fatal(err)
	}
}
Example #2
0
func main() {
	br := bufio.NewReader(os.Stdin)

	line, err := br.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	dna := strings.TrimSpace(line)

	introns := []string{}
	for {
		line, err = br.ReadString('\n')
		if err == io.EOF {
			break
		} else if err != nil {
			log.Fatal(err)
		}
		introns = append(introns, strings.TrimSpace(line))
	}

	spliced := make([]byte, 0, len(dna))
	r := regexp.MustCompile(strings.Join(introns, "|"))
	begin := 0
	for {
		loc := r.FindStringIndex(dna[begin:])
		if loc == nil {
			spliced = append(spliced, dna[begin:]...)
			break
		}
		spliced = append(spliced, dna[begin:begin+loc[0]]...)
		begin += loc[1]
	}

	for i, b := range spliced {
		if b == 'T' {
			spliced[i] = 'U'
		}
	}

	prot, _ := gene.Translate(string(spliced))
	fmt.Println(prot)
}
Example #3
0
func main() {
	br := bufio.NewReader(os.Stdin)

	line, err := br.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	dna := strings.TrimSpace(line)
	rnaBytes := []byte(dna)
	for i, b := range rnaBytes {
		if b == 'T' {
			rnaBytes[i] = 'U'
		}
	}
	rna := string(rnaBytes)
	revRna := strings.Replace(gene.DnaReverseComplement(dna), "T", "U", -1)

	c := gene.CodonsOf('M')
	if len(c) != 1 {
		panic(fmt.Sprintf("Unexpected start codons: %v", c))
	}
	startCodon := c[0]

	seen := make(map[string]bool)
	for _, s := range []string{rna, revRna} {
		for offset := 0; offset < 3; offset++ {
			for i := offset; i < len(s)-2; i += 3 {
				if s[i:i+3] == startCodon {
					protein, err := gene.Translate(s[i:])
					if err == nil && !seen[protein] {
						fmt.Println(protein)
						seen[protein] = true
					}
				}
			}
		}
	}
}