Exemple #1
0
func TestReader2(t *testing.T) {
	a, _ := fastqreader.OpenFastQ("./inputs/1.fq")

	set1, _ := a.ReadBarcodeSet(nil)

	Check(t, set1[0].ReadInfo == "@HWI-D00684:80:HFCKCADXX:2:2113:17628:14813 1:N:0:\n", "a")
	Check(t, string(set1[1].Read1) == "AGCTGCTGCTCTCTCCATGTTTTTCCTGCACTCCTTGCAGGGACCTGAATAGCATGAACTGACTTTTCCTTGACGTAGTTGCTTCGTAGGATACTTCT", "b")

	set2, _ := a.ReadBarcodeSet(&set1)

	Check(t, set2[0].ReadInfo == "@HWI-D00684:80:HFCKCADXX:2:2112:14227:100270 1:N:0:\n", "c")

	Check(t, string(set2[1].Read1) == "CGCGGGCAGCAGCCATGGGATGCAGGACCTGCAGTCCACACATGTCACATGAATCTCCATGGAGAGGCACACAGTTCTCCCCATCTCAGCACTCTCTC", "d")
}
Exemple #2
0
func TestReader(t *testing.T) {

	a, b := fastqreader.OpenFastQ("./inputs/1.fq")
	Check(t, a != nil, "1")
	Check(t, b == nil, "2")

	var ff fastqreader.FastQRecord

	a.ReadOneLine(&ff)
	a.ReadOneLine(&ff)
	a.ReadOneLine(&ff)
	Check(t, string(ff.Read1) == "CACCGCCCTAGCCAGGAGAGAAGCACTTCTTACCTGGGTTTCTTAGAGGCTTTGGCTGGCAATATTGTCAGCACCAGAGAGGACTTCTCGATGGCTGA", "a")
	Check(t, string(ff.ReadQual1) == "BBBFFFFFFFFFFIIIIIFFIIIIIIIIFIIIIIFIFIFFIIFIIIIIIIIIIIIIIIFFFFFFFFFFFFFFFFFFFBFFFFFFFFFFFFFFFFFFFF", "b")
	Check(t, string(ff.Read2) == "GTGGTAGTCTCCTGTTCAGCCATCGAGAAGTCCTCTCTGGTGCTGACAATATTGCCAGCCAAAGCCTCTAAGAAACCCAGGTAAGAAGTGCTTCTCTC", "c")
	Check(t, string(ff.ReadQual2) == "BBBFFFFFFFFFFIIFIIFIIIIIIIIIIIIIIIIFIIIFFFIIIIIIIIIIIIIIIIIIIIFIIIIIIIIIIFFFFFFFFBBFFFFFBBFFFFFFFF", "d")
	Check(t, string(ff.Barcode10X) == "AAACAGAGAAAGAT", "e")
	Check(t, string(ff.Barcode10XQual) == "BBBFFFFFFFFFFI", "f")
	Check(t, string(ff.Barcode) == "CCGAACGC", "g")
	Check(t, string(ff.BarcodeQual) == "BBBFFFFF", "h")
	Check(t, ff.ReadInfo == "@HWI-D00684:80:HFCKCADXX:2:2113:9410:56703 1:N:0:\n", "i")
}
Exemple #3
0
//TODO remove TODO's when fixing thing TODO's relate to, not long after lol
func main() {

	// Use worker thread count request on cmdline, or
	// all CPUs if -threads wasn't specified
	numCPU := runtime.NumCPU()
	if *threads < 0 {
		*threads = numCPU
	}
	runtime.GOMAXPROCS(*threads + 2)

	flag.Parse()

	if _, err := os.Stat(*reads); os.IsNotExist(err) {
		panic(fmt.Sprintf("File does not exist %s", *reads))
	}
	if _, err := os.Stat(*genome); os.IsNotExist(err) {
		panic(fmt.Sprintf("Fasta file not found %s", *genome))
	}
	if syscall.Access(*output, 2) != nil { //is output writable
		panic(fmt.Sprintf("Output directory not writable by this process %s", *output))
	}
	print(fmt.Sprintf("Starting lariat. Version: %s\n", __VERSION__))

	fastq, err := fastqreader.OpenFastQ(*reads)

	if err != nil {
		panic(err)
	}
	print(fmt.Sprintf("Loading reference genome: %s\n", *genome))

	ref := GoBwaLoadReference(*genome)
	print("Reference loaded\n")
	settings := GoBwaAllocSettings()
	config := &RFAConfig{}

	config.improper_penalty = float64(*improper_pair_penalty) * (*alignment_score_factor)

	var w *bufio.Writer

	barcode_num := 0
	bams, err := CreateBAMs(ref, *output, *read_group, *sample_id, *positionChunkSize, *debugTags)
	if err != nil {
		panic(err)
	}
	work_to_do := make(chan *WorkUnit, 2)
	//finished := make (chan bool);

	stats := &RFAStats{}
	stats.file = w

	/* This RW lock gets Rlocked by each worker thread. Worker threads
	 * unlock it when they are finished and have copied their data to the
	 * BAM writer
	 */
	var worker_lock sync.RWMutex

	barcode_reads = [][]fastqreader.FastQRecord{}

	/* Start some workers */
	for i := 0; i < *threads; i++ {
		go WorkerThread(work_to_do, bams, ref, settings, config, stats, &worker_lock)
	}

	/* Iterate over source file, giving work to the workers */
	for {
		barcode_num++
		if len(barcode_reads) == 0 {
			barcode_reads_lock.Lock()
			barcode_reads = append(barcode_reads, make([]fastqreader.FastQRecord, 0, 50000))
			barcode_reads_lock.Unlock()
		}
		barcode_reads_lock.Lock()
		bc_reads := barcode_reads[len(barcode_reads)-1]
		//fmt.Println(len(barcode_reads))
		barcode_reads = barcode_reads[0 : len(barcode_reads)-1]
		barcode_reads_lock.Unlock()
		bc_reads, err, full_barcode := fastq.ReadBarcodeSet(&bc_reads)
		if err != nil {
			break
		}

		// Max BCs to process
		if barcode_num == *max_bcs {
			break
		}

		work_to_do <- &WorkUnit{bc_reads, barcode_num, full_barcode}
	}

	/* Tell each worker to exit */
	for i := 0; i < *threads; i++ {
		work_to_do <- nil
	}

	/* Wait for each worker to finish any final tasks and exit */
	worker_lock.Lock()
	worker_lock.Unlock()

	/* Close and flush the BAM file */
	bams.Close()
	fmt.Println("Lariat completed successfully")
}