Esempio n. 1
0
int readerToMeth(BamTools::BamReader & reader1, 
                 BamTools::BamReader & reader2, 
                 std::map<std::string, std::vector<std::string> > & lociMeth1, 
                 std::map<std::string, std::vector<std::string> > & lociMeth2, 
                 BamTools::RefVector::const_iterator i, 
                 int d, 
                 const BamTools::RefVector refs,
                 std::string sample)
{
    const int r1=reader1.GetReferenceID(i->RefName);
    const int r2=reader2.GetReferenceID(i->RefName);
    const int rl=i->RefLength;
    if(reader1.SetRegion(r1,0, r1, rl) & reader2.SetRegion(r2,0, r2, rl))
    {
        std::cerr << "Processing " << i->RefName << std::endl;
        BamTools::BamAlignment al;            
        while (reader1.GetNextAlignment(al)){
            //std::cout << al.RefID << std::endl;
            byread(al, d, lociMeth1, refs, sample);
        }
        while (reader2.GetNextAlignment(al)){
            //std::cout << al.RefID << std::endl;
            byread(al, d, lociMeth2, refs, sample);
        }
    }
    reader1.Rewind();
    reader2.Rewind();            
    return 0;
}
	position BamAlignmentReader::GetLastPositionInBam(const std::string& bamPath, Region::SharedPtr regionPtr)
	{
		BamTools::BamReader bamReader;
		if (!bamReader.Open(bamPath))
		{
			throw "Unable to open bam file";
		}

		bamReader.LocateIndex();
		int refID = bamReader.GetReferenceID(regionPtr->getReferenceID());
		auto referenceData = bamReader.GetReferenceData();
		bamReader.Close();
		return referenceData[refID].RefLength;
	}