Ejemplo n.º 1
0
Archivo: gobwa.go Proyecto: dkj/lariat
/*
 * This attempts to align "seq", which is a string of ACGTacgt letters. It returns
 * an array of EasyAlignment objects.
 * TODO: Actually return that list.
 */
func GoBwaAlign(ref *GoBwaReference, settings *GoBwaSettings, seq string, arena *Arena) []EasyAlignment {

	converted_seq := SequenceConvert(seq)
	typed_ref := (*C.bwaidx_t)(ref.BWTData)

	//results := C.mem_chain((*C.mem_opt_t)(settings.Settings), typed_ref.bwt, typed_ref.bns, len(converted_seq), &(converted_seq[0]), unsafe.Pointer(uintptr(0)));

	results := C.mem_align1_core((*C.mem_opt_t)(settings.Settings),
		typed_ref.bwt,
		typed_ref.bns,
		typed_ref.pac,
		(C.int)(len(converted_seq)),
		(*C.char)(unsafe.Pointer((&(converted_seq[0])))),
		unsafe.Pointer(uintptr(0)))
	//algns := make([]*C.mem_alnreg_t, (int)(results.n))
	algns := make([]EasyAlignment, (int)(results.n))

	arena.Push(uintptr(unsafe.Pointer(results.a)))
	for i := (uintptr(0)); i < (uintptr)(results.n); i++ {
		a := ((*C.mem_alnreg_t)(unsafe.Pointer(uintptr(unsafe.Pointer(results.a)) + i*(unsafe.Sizeof(*results.a)))))
		//arena.Push(uintptr(unsafe.Pointer(a)));
		p := InterpretAlign(ref, a)
		algns[i] = p
		//log.Printf("%v", p)
		//log.Printf("%v", *((*C.mem_alnreg_t)(unsafe.Pointer(uintptr(unsafe.Pointer(results.a)) + i*(unsafe.Sizeof(*results.a))))))
	}

	return algns
	//log.Printf("%v", results);
}
Ejemplo n.º 2
0
Archivo: gobwa.go Proyecto: dkj/lariat
func GoBwaMemMateSW(ref *GoBwaReference, settings *GoBwaSettings, read1 *[]byte, read2 *[]byte, arena *Arena, score_delta int) ([]EasyAlignment, []EasyAlignment) {

	typed_ref := (*C.bwaidx_t)(ref.BWTData)
	var Pes [4]C.mem_pestat_t
	Pes[0].failed = 1
	Pes[1].low = -35
	Pes[1].high = 500
	Pes[1].failed = 0
	Pes[1].avg = 200.0
	Pes[1].std = 100.0
	Pes[2].failed = 1
	Pes[3].failed = 1
	converted_seq_read1 := SequenceConvert(string(*read1))
	converted_seq_read2 := SequenceConvert(string(*read2))
	// get mapping for each read
	read1_results := C.mem_align1_core((*C.mem_opt_t)(settings.Settings),
		typed_ref.bwt,
		typed_ref.bns,
		typed_ref.pac,
		(C.int)(len(converted_seq_read1)),
		(*C.char)(unsafe.Pointer((&(converted_seq_read1[0])))),
		unsafe.Pointer(uintptr(0)))

	read2_results := C.mem_align1_core((*C.mem_opt_t)(settings.Settings),
		typed_ref.bwt,
		typed_ref.bns,
		typed_ref.pac,
		(C.int)(len(converted_seq_read2)),
		(*C.char)(unsafe.Pointer((&(converted_seq_read2[0])))),
		unsafe.Pointer(uintptr(0)))

	algns_read1 := make([]EasyAlignment, (int)(read1_results.n))
	algns_read2 := make([]EasyAlignment, (int)(read2_results.n))
	best_read1_score := 0
	best_read2_score := 0
	//get some interpretation of these alignments and note the best score for each
	for i := (uintptr(0)); i < (uintptr)(read1_results.n); i++ {
		a := ((*C.mem_alnreg_t)(unsafe.Pointer(uintptr(unsafe.Pointer(read1_results.a)) + i*(unsafe.Sizeof(*read1_results.a)))))
		p := InterpretAlign(ref, a)
		algns_read1[i] = p
		if p.Score > best_read1_score {
			best_read1_score = p.Score
		}
	}

	for i := (uintptr(0)); i < (uintptr)(read2_results.n); i++ {
		a := ((*C.mem_alnreg_t)(unsafe.Pointer(uintptr(unsafe.Pointer(read2_results.a)) + i*(unsafe.Sizeof(*read2_results.a)))))
		p := InterpretAlign(ref, a)
		algns_read2[i] = p
		if p.Score > best_read2_score {
			best_read2_score = p.Score
		}
	}

	//rescue alignments for read1 by looping through read2's hits and doing mem_matesw
	num := 0
	for i := 0; i < len(algns_read2) && num < 50; i++ {
		if algns_read2[i].Score >= best_read2_score-score_delta {
			// attempt to rescue the read1 alignment here
			num++
			C.mem_matesw((*C.mem_opt_t)(settings.Settings),
				typed_ref.bns,
				typed_ref.pac,
				&Pes[0],
				algns_read2[i].ChainedHit,
				(C.int)(len(*read1)),
				(*C.uint8_t)(&(converted_seq_read1[0])),
				&read1_results)
		}
	}

	algns_read1 = make([]EasyAlignment, (int)(read1_results.n))
	for i := (uintptr(0)); i < (uintptr)(read1_results.n); i++ {
		a := ((*C.mem_alnreg_t)(unsafe.Pointer(uintptr(unsafe.Pointer(read1_results.a)) + i*(unsafe.Sizeof(*read1_results.a)))))
		p := InterpretAlign(ref, a)
		algns_read1[i] = p
	}

	//rescue alignments for read2 by looping through read1's hits and doing mem_matesw
	num = 0
	for i := 0; i < len(algns_read1) && num < 50; i++ {
		if algns_read1[i].Score >= best_read1_score-score_delta {
			// attempt to rescue the read2 alignment here
			num++
			C.mem_matesw((*C.mem_opt_t)(settings.Settings),
				typed_ref.bns,
				typed_ref.pac,
				&Pes[0],
				algns_read1[i].ChainedHit,
				(C.int)(len(*read2)),
				(*C.uint8_t)(&(converted_seq_read2[0])),
				&read2_results)
		}
	}

	arena.Push(uintptr(unsafe.Pointer(read1_results.a)))
	arena.Push(uintptr(unsafe.Pointer(read2_results.a)))

	algns_read2 = make([]EasyAlignment, (int)(read2_results.n))

	for i := (uintptr(0)); i < (uintptr)(read2_results.n); i++ {
		a := ((*C.mem_alnreg_t)(unsafe.Pointer(uintptr(unsafe.Pointer(read2_results.a)) + i*(unsafe.Sizeof(*read2_results.a)))))
		p := InterpretAlign(ref, a)
		algns_read2[i] = p
	}
	return algns_read1, algns_read2
}