func main() { file, err := os.Open(flag.Arg(0)) if err != nil { fmt.Println(err) return } defer file.Close() seq, err := spl.Read(file) if err != nil { fmt.Println(err) return } pic := strings.Split(flag.Arg(0), ".") if len(pic) > 1 { if *intron { pic[len(pic)-2] += "-intron" } else { pic[len(pic)-2] += "-cds" } pic[len(pic)-1] = "fas" } else { if *intron { pic[0] += "-intron" } else { pic[0] += "-cds" } pic = append(pic, "fas") } file, err = os.Create(strings.Join(pic, ".")) if err != nil { fmt.Println(err) return } defer file.Close() if !*intron { cds := make([]gene.Sequence, len(seq)) for i, s := range seq { cds[i] = gene.Sequence(s.CDS()) } fas.Write(file, cds) } else { for _, s := range seq { introns := make([]gene.Sequence, len(s.Seg)-1) for i, t := range s.Introns() { introns[i] = gene.Sequence(t) } fas.Write(file, introns) } } }
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) }