Esempio n. 1
0
func ToFasta(in, out string) {
	if len(in) == 0 {
		log.Fatalln("Please provide an input file (.2bit)")
	}
	if len(out) == 0 {
		log.Fatalln("Please provide an output file (.fa)")
	}

	inFile, err := os.Open(in)
	if err != nil {
		log.Fatal(err)
	}

	defer inFile.Close()

	tb, err := twobit.NewReader(inFile)
	if err != nil {
		log.Fatal(err)
	}

	outFile, err := os.Create(out)
	if err != nil {
		log.Fatal(err)
	}

	defer outFile.Close()

	w := bufio.NewWriter(outFile)

	for _, n := range tb.Names() {
		w.WriteString(">")
		w.WriteString(n)
		w.WriteString("\n")
		seq, err := tb.Read(n)
		if err != nil {
			log.Fatal(err)
		}

		n := len(seq)
		cols := 50
		rows := n / cols
		if n%cols > 0 {
			rows++
		}

		for r := 0; r < rows; r++ {
			end := (r * cols) + cols
			if end > n {
				end = n
			}

			w.Write(seq[(r * cols):end])
			w.Write([]byte("\n"))
		}
	}

	w.Flush()
}
Esempio n. 2
0
func IndexInfo(in, out string) {
	if len(in) == 0 {
		log.Fatalln("Please provide an input file (.2bit)")
	}
	if len(out) == 0 {
		log.Fatalln("Please provide an output file (.fa)")
	}

	inFile, err := os.Open(in)
	if err != nil {
		log.Fatal(err)
	}

	defer inFile.Close()

	tb, err := twobit.NewReader(inFile)
	if err != nil {
		log.Fatal(err)
	}

	outFile, err := os.Create(out)
	if err != nil {
		log.Fatal(err)
	}

	defer outFile.Close()

	w := bufio.NewWriter(outFile)

	for name, index := range tb.Indexes() {
		w.WriteString(name)
		w.WriteString("\t")
		idx_str := fmt.Sprintf("%d", index)
		w.WriteString(idx_str)
		w.WriteString("\n")
	}

	w.Flush()

}