Example #1
0
func main() {
	var seq_file = flag.String("s", "", "Specify a file containing the sequence.")
	var rl = flag.Int("l", 100, "Read length.")
	var coverage = flag.Float64("c", 2.0, "Coverage")
	var error_rate = flag.Float64("e", 0.01, "Error rate.")
	flag.BoolVar(&Debug, "debug", false, "Turn on debug mode.")
	flag.Parse()
	read_len := int(*rl)
	if *seq_file != "" {
		if *coverage > 0 && read_len > 0 {
			idx := fmi.New(*seq_file)
			num_of_reads := int(*coverage * float64(idx.LEN) / float64(read_len))
			read_indices := make([]int, num_of_reads)
			the_read := make([]byte, read_len)
			var rand_pos int

			for i := 0; i < num_of_reads; i++ {
				rand_pos = int(rand_gen.Intn(int(idx.LEN - read_len)))
				if justN(rand_pos, int(read_len)) {
					i--
					continue
				}

				read_indices = idx.Repeat(rand_pos, read_len)
				var errors []int
				if int(rand_pos+read_len) >= len(fmi.SEQ) {
					panic("Read may be shorter than wanted.")
				}

				copy(the_read, fmi.SEQ[rand_pos:rand_pos+read_len])
				for k := 0; k < len(the_read); k++ {
					if rand_gen.Float64() < *error_rate {
						the_read[k] = random_error(the_read[k])
						errors = append(errors, k)
					}
				}
				if Debug {
					for j := 0; j < int(rand_pos); j++ {
						fmt.Printf(" ")
					}
				}
				fmt.Printf("%s %d ", the_read, len(read_indices))
				for j := 0; j < len(read_indices); j++ {
					fmt.Printf("%d ", read_indices[j])
				}
				fmt.Printf("%d", len(errors))
				for j := 0; j < len(errors); j++ {
					fmt.Printf(" %d", errors[j])
				}
				fmt.Println()
			}
		} else {
			idx := fmi.New(*seq_file)
			idx.Save(*seq_file)
		}
	} else {
		fmt.Println("Must provide sequence file")
	}
}
Example #2
0
//-----------------------------------------------------------------------------
func main() {
	idx := fmi.New(os.Args[1])
	memstats := new(runtime.MemStats)
	runtime.ReadMemStats(memstats)
	fmt.Printf("memstats before GC: bytes = %d footprint = %d\n", memstats.HeapAlloc, memstats.Sys)
	fmt.Println("Size\t", len(idx.SA))
}
Example #3
0
//-----------------------------------------------------------------------------
func main() {
	var build_file = flag.String("build", "", "Specify a file, from which to build FM index.")
	var index_file = flag.String("i", "", "index file")
	var queries_file = flag.String("q", "", "queries file")
	flag.BoolVar(&Debug, "debug", false, "Turn on debug mode.")
	flag.Parse()

	if *build_file != "" {
		idx := fmi.New(*build_file)
		idx.Save(*build_file)
	} else if *index_file != "" && *queries_file != "" {
		idx := fmi.Load(*index_file)

		f, err := os.Open(*queries_file)
		if err != nil {
			panic("error opening file " + *queries_file)
		}
		r := bufio.NewReader(f)
		for {
			line, err := r.ReadBytes('\n')
			if err != nil {
				break
			}
			if len(line) > 1 {
				line = line[0 : len(line)-1]
				result := idx.Search(line)
				if len(result) == 0 {
					fmt.Println("na")
				} else {
					for _, v := range result {
						fmt.Printf("%d ", v)
					}
					fmt.Println()
				}
			}
		}
	}

}