Example #1
0
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)
		}
	}
}
Example #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
	}
}
Example #3
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 := fas.Read(file)
	if err != nil {
		fmt.Println(err)
		return
	}
	if len(seq) == 0 {
		fmt.Println("File is empty")
		return
	}
	for i, _ := range seq {
		seq[i].Seq = gene.Complement(gene.Format(seq[i].Seq, "dna"), "dna")
		seq[i].Name += "_cpl"
	}
	n := strings.LastIndexByte(os.Args[1], '.')
	if n > 0 {
		os.Args[1] = os.Args[1][:n]
	}
	file, err = os.Create(os.Args[1] + ".rev-cpl.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
	}
}