Beispiel #1
0
void scan_tags(SeqTagLib *lib, FileReader *fwd, FileReader *rev, int is_fq, int pdirs){
	Sequence *seq1, *seq2;
	uint64_t id;
	uint32_t i, len1, len2;
	uint8_t *buf1, *buf2, v;
	__n_seqs = lib->n_seq;
	id = 0;
	seq1 = seq2 = NULL;
	buf1 = malloc(lib->p1len);
	buf2 = malloc(lib->p2len);
	while(is_fq? (fread_fastq_adv(&seq1, fwd, FASTQ_FLAG_NO_NAME | FASTQ_FLAG_NO_QUAL) && 
		fread_fastq_adv(&seq2, rev, FASTQ_FLAG_NO_NAME | FASTQ_FLAG_NO_QUAL)) :
		(fread_fasta_adv(&seq1, fwd, FASTA_FLAG_NO_NAME) && fread_fasta_adv(&seq2, rev, FASTA_FLAG_NO_NAME))){
		id ++;
		__n_scan ++;
		len1 = seq1->seq.size;
		if(len1 > lib->p1len) len1 = lib->p1len;
		for(i=0;i<len1;i++){
			v = base_bit_table[(int)seq1->seq.string[i]];
			if(v == 4) v = lrand48() & 0x03;
			buf1[i] = v;
		}
		len2 = seq2->seq.size;
		if(len2 > lib->p2len) len2 = lib->p2len;
		for(i=0;i<len2;i++){
			v = base_bit_table[(int)seq2->seq.string[i]];
			if(v == 4) v = lrand48() & 0x03;
			buf2[i] = v;
		}
		if(pdirs & 0x01){ scan_tag_core(lib, id, buf1, len1, buf2, len2, 0); }
		if(pdirs & 0x02){ scan_tag_core(lib, id, buf1, len1, buf2, len2, 1); }
	}
	free(buf1);
	free(buf2);
	if(seq1) free_sequence(seq1);
	if(seq2) free_sequence(seq2);
}
Beispiel #2
0
SeqDB* load_seqdb(FileReader *fr, int is_fq, int fix_rd_len){
	SeqDB *sdb;
	Sequence *seq;
	u64list *seqs;
	uint64_t offset;
	uint8_t len;
	sdb = malloc(sizeof(SeqDB));
	sdb->n_rd = 0;
	sdb->rd_len = 0;
	sdb->max_rd_len = 0;
	if(!fix_rd_len){
		sdb->seqoffs = init_u64list(1024);
		sdb->seqlens = init_u8list(1024);
	} else {
		sdb->rd_len = fix_rd_len;
		sdb->max_rd_len = fix_rd_len;
		sdb->seqoffs = NULL;
		sdb->seqlens = NULL;
	}
	seq = NULL;
	seqs = init_u64list(1024);
	offset = 0;
	while(is_fq? fread_fastq_adv(&seq, fr, 5) : fread_fasta_adv(&seq, fr, 1)){
		sdb->n_rd ++;
		len = seq->seq.size;
		if(fix_rd_len){
			if(len < sdb->rd_len){
				continue;
			} else if(len > sdb->rd_len){
				len = sdb->rd_len;
			}
		} else {
			if(sdb->max_rd_len < len) sdb->max_rd_len = len;
			push_u64list(sdb->seqoffs, offset);
			push_u8list(sdb->seqlens, len);
		}
		encap_u64list(seqs, (offset + len + 31) / 32 + 2);
		seq2bits(seqs->buffer, offset, seq->seq.string, len);
		offset += len;
		if((sdb->n_rd & 0xFFF) == 0){ fprintf(stderr, "\r %u k reads  ", (sdb->n_rd >> 10)); fflush(stderr); }
	}