Esempio n. 1
0
func main() {
	flag.BoolVar(&Mul, "c", false, "number of sequence to average")
	flag.Parse()
	if flag.NArg() != 1 {
		fmt.Println("Usage: executable [-c] filename\n")
		return
	}
	file, err := os.Open(flag.Arg(0))
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()
	seq, err := aln.Read(file)
	if err != nil {
		fmt.Println(err)
		return
	}
	if len(seq) == 0 {
		fmt.Println("File is empty")
		return
	}
	if Mul {
		l, r := 0, len(seq[0].Seq)-1
		for i, _ := range seq {
			for seq[i].Seq[l] == '-' && l < r {
				l++
			}
			for seq[i].Seq[r] == '-' && l < r {
				r--
			}
		}
		for i, _ := range seq {
			seq[i].Seq = seq[i].Seq[l : r+1]
		}
	}
	n := strings.LastIndexByte(os.Args[1], '.')
	if n > 0 {
		os.Args[1] = os.Args[1][:n]
	}
	file, err = os.Create(os.Args[1] + ".phy")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()
	err = phy.Write(file, seq)
	if err != nil {
		fmt.Println("Can't create output file\n")
		return
	}
}
Esempio n. 2
0
func main() {
	if len(os.Args) != 2 {
		fmt.Println("Usage: executable filename\n")
		return
	}
	file, err := os.Open(os.Args[1])
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()
	seq, err := aln.Read(file)
	if err != nil {
		fmt.Println(err)
		return
	}
	if len(seq) == 0 {
		fmt.Println("File is empty")
		return
	}
	l, r := 0, len(seq[0].Seq)-1
	for i, _ := range seq {
		for seq[i].Seq[l] == '-' && l < r {
			l++
		}
		for seq[i].Seq[r] == '-' && l < r {
			r--
		}
	}
	for i, _ := range seq {
		seq[i].Seq = seq[i].Seq[l : r+1]
	}
	n := strings.LastIndexByte(os.Args[1], '.')
	if n > 0 {
		os.Args[1] = os.Args[1][:n]
	}
	file, err = os.Create(os.Args[1] + ".fas")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()
	err = fas.Write(file, seq)
	if err != nil {
		fmt.Println("Can't create output file\n")
		return
	}
}
Esempio n. 3
0
func main() {
	switch len(os.Args) {
	case 1:
		fmt.Println("usage: executable aln-name [spl-name]")
		return
	case 2, 3:
		chest = os.Args[1]
		piece := strings.Split(chest, ".")
		if l := len(piece); l > 1 && piece[l-1] == "aln" {
			align = chest
			chest = strings.Join(piece[:l-1], ".")
		} else if l > 1 && piece[l-1] == "spl" {
			chest = strings.Join(piece[:l-1], ".")
			align = chest + ".aln"
		} else {
			align = chest + ".aln"
		}
		if len(os.Args) == 2 {
			split = chest + ".spl"
		} else {
			split = os.Args[2]
		}
	default:
		fmt.Println("too many arguments")
		return
	}

	file, err := os.Open(align)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()
	cds, err := aln.Read(file)
	if err != nil {
		fmt.Println(err)
		return
	}
	file, err = os.Open(split)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()
	seq, err := spl.Read(file)
	if err != nil {
		fmt.Println(err)
		return
	}

	l := len(cds)
	w := len(cds[0].Seq)

	img := paint.Image{Image: image.NewRGBA(image.Rect(0, 0, w+240, l*40+50)), FR: image.Black}
	draw.Draw(img, img.Bounds(), image.White, image.Point{0, 0}, draw.Src)
	con.SetSrc(image.Black)
	con.SetDst(img)
	con.SetClip(img.Bounds())

	std := make([]byte, w)
	for i := 0; i < w; i++ {
		s := map[byte]int{'-': 0, 'A': 0, 'G': 0, 'C': 0, 'T': 0}
		for j := 0; j < l; j++ {
			c := cds[j].Seq[i]
			if _, ok := s[c]; ok {
				s[c]++
			} else {
				s['-']++
			}
		}
		std[i] = '-'
		M := 0
		for k, v := range s {
			if M < v {
				std[i], M = k, v
			}
		}
	}

	for j := 0; j < l; j++ {
		pt := freetype.Pt(w+15, j*40+70)
		con.DrawString(cds[j].Name, pt)
		img.Line(10, j*40+49, 9+w, j*40+49)
		img.Line(10, j*40+80, 9+w, j*40+80)
	}
	pt := freetype.Pt(w+15, 25)
	con.DrawString("Average", pt)
	img.Line(10, 9, 9+w, 9)
	img.Line(10, 30, 9+w, 30)

	for i := 0; i < w; i++ {
		img.FR = image.Black
		if n, ok := gene.Dna[std[i]]; ok {
			img.FR = color.RGBA{uint8(n[0]*64) + 191, uint8(n[1]*64) + 191, uint8(n[2]*64) + 191, 255}
		}
		img.Line(i+10, 10, i+10, 29)

		for j := 0; j < l; j++ {
			img.FR = image.Black
			if c := cds[j].Seq[i]; c == std[i] && c != '-' {
				img.FR = image.White
			} else if n, ok := gene.Dna[c]; ok {
				img.FR = color.RGBA{uint8(n[0]*64) + 191, uint8(n[1]*64) + 191, uint8(n[2]*64) + 191, 255}
			}
			img.Line(i+10, j*40+50, i+10, j*40+69)
		}
	}

	for j := 0; j < l; j++ {
		t := 0
		for ; t < len(seq); t++ {
			if strings.Contains(seq[t].Name, cds[j].Name) {
				break
			}
		}
		if t >= len(seq) {
			continue
		}
		a, b := 0, seq[t].Seg[0][0]
		for i := 0; i < w; i++ {
			if cds[j].Seq[i] != '-' {
				if a%2 == 0 {
					img.FR = color.RGBA{60, 60, 60, 255}
					img.Line(i+10, j*40+70, i+10, j*40+79)
				} else {
					img.FR = color.RGBA{180, 180, 180, 255}
					img.Line(i+10, j*40+70, i+10, j*40+79)
				}
				b++
				if b == seq[t].Seg[a][1] {
					a++
					if a < len(seq[t].Seg) {
						b = seq[t].Seg[a][0]
					}
				}
			} else if a < len(seq[t].Seg) && b < seq[t].Seg[a][1] && b > seq[t].Seg[a][0] {
				if a%2 == 0 {
					img.FR = color.RGBA{60, 60, 60, 255}
					img.Line(i+10, j*40+70, i+10, j*40+79)
				} else {
					img.FR = color.RGBA{180, 180, 180, 255}
					img.Line(i+10, j*40+70, i+10, j*40+79)
				}
			}
		}
	}
	file, err = os.Create(chest + ".png")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()
	png.Encode(file, img)
}