Пример #1
0
			static bool readAlignmentGz(
				stream_type & GZ,
				::libmaus::bambam::BamAlignment & alignment,
				::libmaus::bambam::BamHeader const * bamheader = 0,
				bool const validate = true
			)
			{
				/* read alignment block size */
				int64_t const bs0 = GZ.get();
				int64_t const bs1 = GZ.get();
				int64_t const bs2 = GZ.get();
				int64_t const bs3 = GZ.get();
				if ( bs3 < 0 )
					// reached end of file
					return false;
				
				/* assemble block size as LE integer */
				alignment.blocksize = (bs0 << 0) | (bs1 << 8) | (bs2 << 16) | (bs3 << 24) ;

				/* read alignment block */
				if ( alignment.blocksize > alignment.D.size() )
					alignment.D = ::libmaus::bambam::BamAlignment::D_array_type(alignment.blocksize,false);
				GZ.read(reinterpret_cast<char *>(alignment.D.begin()),alignment.blocksize);

				if ( static_cast<int64_t>(GZ.gcount()) != static_cast<int64_t>(alignment.blocksize) )
				{
					::libmaus::exception::LibMausException se;
					se.getStream() << "Invalid alignment (EOF in alignment block of length " << alignment.blocksize  << ")" << std::endl;
					se.finish();
					throw se;
				}
				
				if ( validate )
				{
					libmaus_bambam_alignment_validity const validity = bamheader ? alignment.valid(*bamheader) : alignment.valid();
					if ( validity != ::libmaus::bambam::libmaus_bambam_alignment_validity_ok )
					{
						::libmaus::exception::LibMausException se;
						se.getStream() << "Invalid alignment: " << validity << std::endl;
						se.finish();
						throw se;					
					}
				}
				
				return true;
			}
Пример #2
0
			CompactFastQHeader(stream_type & stream)
			:
			  blocklen(::libmaus::util::NumberSerialisation::deserialiseNumber(stream)),
			  numreads(::libmaus::util::NumberSerialisation::deserialiseNumber(stream)),
			  qbits(stream.get()),
			  quant(stream)
			{
			
			}
Пример #3
0
			static uint8_t getByte(stream_type & in)
			{
				int const c = in.get();

				if ( c < 0 )
				{
					::libmaus2::exception::LibMausException se;
					se.getStream() << "Unexpected EOF in ::libmaus2::bambam::DecoderBase::getByte()" << std::endl;
					se.finish();
					throw se;
				}

				return c;
			}
Пример #4
0
			static value_type getLEInteger(stream_type & stream)
			{
				value_type v = 0;
				
				for ( uint64_t i = 0; i < length; ++i )
					if ( stream.peek() == stream_type::traits_type::eof() )
					{
						libmaus2::exception::LibMausException ex;
						ex.getStream() << "Failed to little endian number of length " << length << " in BamIndex::getLEInteger." << std::endl;
						ex.finish();
						throw ex;		
					}
					else
					{
						v |= static_cast<value_type>(stream.get()) << (8*i);
					}
									
				return v;
			}