Exemple #1
0
/**
 * Reads next record, hides the random access of different regions from the user.
 */
bool BCFOrderedReader::read(bcf1_t *v)
{
    if (random_access_enabled)
    {
        if (ftype.format==bcf)
        {
            while(true)
            {
                if (itr && bcf_itr_next(file, itr, v)>=0)
                {
                    return true;
                }
                else if (!initialize_next_interval())
                {
                    return false;
                }
            }
        }
        else
        {
            while(true)
            {
                if (itr && tbx_itr_next(file, tbx, itr, &s)>=0)
                {
                    vcf_parse1(&s, hdr, v);
                    return true;
                }
                else if (!initialize_next_interval())
                {
                    return false;
                }
            }
        }
    }
    else
    {
        if (bcf_read(file, hdr, v)==0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    return false;
};
Exemple #2
0
/**
 * Reads next record, hides the random access of different regions from the user.
 */
bool BAMOrderedReader::read(bam1_t *s)
{
    if (random_access_enabled)
    {
        while(true)
        {
            if (itr && bam_itr_next(sam, itr, s)>=0)
            {
                return true;
            }
            else if (!initialize_next_interval())
            {
                return false;
            }
        }
    }
    else
    {
        if (bam_read1(sam->fp.bgzf, s)>=0)
        {
            //todo: filter via interval tree
            //if found in tree, return true else false
            return true;
        }
        else
        {
            return false;
        }
    }

    return false;
};
Exemple #3
0
/**
 * Reads next record, hides the random access of different regions from the user.
 */
bool TBXOrderedReader::read(kstring_t *s)
{
    if (random_access_enabled)
    {
        while(true)
        {
            if (itr && tbx_itr_next(hts, tbx, itr, s)>=0)
            {
                return true;
            }
            else if (!initialize_next_interval())
            {
                return false;
            }
        }
    }
    else
    {
        if (hts_getline(hts, '\n', s) >= 0)
		{
		    return true;
		}
		else
	    {
	        return false;    
	    }
    }

    return false;
};
/**
 * Ensures that buffer for each file contains at least records of 2 different positions
 * Updates the latest position.  [store latest and second latest]
 * returns false when all files are read through.
 * Note that these bcf1_t memory allocation are handled by BCFSyncedStreamReader.
 */
bool BCFSyncedStreamReader::read_next_position(std::vector<bcfptr*>& current_recs)
{
    //put records in pool
    for (uint32_t i=0; i<current_recs.size(); ++i)
    {
        store_bcf1_into_pool(current_recs[i]->v);
        delete(current_recs[i]);
    }
    current_recs.clear();

    //process records in priority queue or initialize next interval if pq is empty
    //initialize_next_interval tops up the pq
    if (pq.size()!=0 || initialize_next_interval())
    {
        //dequeue pqueue most recent position and return it
        bcfptr* variant = pq.top();
        bcfptr* cvariant = variant;

        while (bcfptr_scmp(cvariant, variant)==0)
        {
            bcfptr *b = pq.top();
            current_recs.push_back(b);

            buffer[b->file_index].remove(b->v);
            fill_buffer(b->file_index);
            pq.pop();

            if (pq.size()==0)
            {
                break;
            }
            else
            {
                cvariant = pq.top();
            }
        }

        //current_pos1 = current_recs.front().pos1;

        return true;
    }
    else //end of contig or eof for all files
    {
        return false;
    }
}