64 unsigned int uFlags) :
77 unsigned int uFlags) :
128 "Empty bioseq handle");
132 if (
range.IsWhole()) {
142 "Empty sequence string");
160 const auto num_rows = denseg.
GetDim();
161 const auto num_segs = denseg.
GetNumseg();
164 for (
int row=0; row<num_rows; ++row)
174 "Unable to fetch Bioseq");
186 for (
int seg=0; seg<num_segs; ++seg)
188 const auto start = denseg.
GetStarts()[seg*num_rows + row];
197 string defline =
">" + best_id;
248 if (start.
Which() != end.Which()) {
251 "Unable to determine product length");
257 "Unable to determine product length");
260 const int length = end.AsSeqPos() - start.
AsSeqPos();
262 return (length >= 0) ? length : -length;
274 string prev_genomic_id;
275 string prev_product_id;
279 exon->IsSetGenomic_id() ?
280 exon->GetGenomic_id() :
284 exon->IsSetProduct_id() ?
285 exon->GetProduct_id() :
290 exon->IsSetGenomic_strand() ?
291 exon->GetGenomic_strand() :
292 default_genomic_strand;
295 exon->IsSetProduct_strand() ?
296 exon->GetProduct_strand() :
297 default_product_strand;
299 const auto genomic_start = exon->GetGenomic_start();
300 const auto genomic_end = exon->GetGenomic_end();
302 if (genomic_end < genomic_start) {
305 "Bad genomic location: end < start");
307 const int genomic_length = genomic_end - genomic_start;
309 const int product_start = exon->GetProduct_start().AsSeqPos();
310 const int product_end = exon->GetProduct_end().AsSeqPos();
313 if (product_end < product_start) {
316 "Bad product location: end < start");
319 const int product_length = product_end - product_start;
328 "Unable to resolve genomic sequence");
332 GetSeqString(genomic_bsh, genomic_range, genomic_strand, genomic_seq);
341 "Unable to resolve product sequence");
345 GetSeqString(product_bsh, product_range, product_strand, product_seq);
347 if (exon->IsSetParts()) {
348 AddGaps(product_type, exon->GetParts(), genomic_seq, product_seq);
351 if (product_length != genomic_length) {
354 "Lengths of genomic and product sequences don't match");
373 if (exon_chunks.empty()) {
377 string genomic_string;
378 string product_string;
380 const unsigned int res_width =
388 unsigned int interval_width = 0;
390 auto chunk_type = exon_chunk->Which();
400 interval_width = exon_chunk->GetMatch();
403 interval_width = exon_chunk->GetMismatch();
406 interval_width = exon_chunk->GetDiag();
409 genomic_string.append(genomic_seq, genomic_pos, interval_width);
410 product_string.append(product_seq, product_pos, (interval_width + (res_width-1))/res_width);
411 genomic_pos += interval_width;
412 product_pos += interval_width/res_width;
416 interval_width = exon_chunk->GetGenomic_ins();
417 genomic_string.append(genomic_seq, genomic_pos, interval_width);
418 product_string.append(interval_width/res_width,
'-');
419 genomic_pos += interval_width;
423 interval_width = exon_chunk->GetProduct_ins();
424 genomic_string.append(interval_width,
'-');
425 product_string.append(product_seq, product_pos, interval_width/res_width);
426 product_pos += interval_width/res_width;
432 genomic_seq = genomic_string;
433 product_seq = product_string;
446 if (start >= seq_plus.size()) {
449 "Bad location: impossible start");
452 return seq_plus.substr(start,
len);
483 const auto num_segs = sparse_align.
GetNumseg();
504 for (
int seg=0; seg<num_segs; ++seg) {
533 for (
int seg=0; seg<num_segs; ++seg) {
548 if (defline.back() ==
'|' && defline.size() > 1)
550 const auto length = defline.size();
551 m_Os << defline.substr(0,length-1) <<
"\n";
554 m_Os << defline <<
"\n";
557 while (pos < seqdata.size()) {
563 "Processing terminated by user");
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
unsigned int s_ProductLength(const CProduct_pos &start, const CProduct_pos &end)
void ProcessSeqId(const CSeq_id &id, CBioseq_Handle &bsh, CRange< TSeqPos > &range)
bool WriteSparseAlign(const CSparse_align &sparse_aln)
void WriteContiguous(const string &defline, const string &seqdata)
bool WriteSplicedExons(const list< CRef< CSpliced_exon >> &exons, CSpliced_seg::TProduct_type product_type, CRef< CSeq_id > default_genomic_id, ENa_strand default_genomic_strand, CRef< CSeq_id > default_product_id, ENa_strand default_product_strand)
CAlnWriter(CScope &scope, CNcbiOstream &ostr, unsigned int uFlags)
void GetSeqString(CBioseq_Handle bsh, const CRange< TSeqPos > &range, ENa_strand strand, string &seq)
bool WriteAlignSparseSeg(const CSparse_seg &sparse_seg)
bool WriteAlign(const CSeq_align &align, const string &name="", const string &descr="") override
Write a raw Seq-align to the internal output stream.
string GetSegString(const string &seq_plus, CSeqUtil::ECoding coding, ENa_strand strand, int start, size_t len)
void AddGaps(CSpliced_seg::TProduct_type product_type, const CSpliced_exon::TParts &exon_chunks, string &genomic_seq, string &product_seq)
bool WriteAlignSplicedSeg(const CSpliced_seg &spliced_seg)
string GetBestId(const CSeq_id &)
bool WriteAlignDenseSeg(const CDense_seg &denseg)
const CSeq_id & GetSeq_id(TDim row) const
static CGenbankIdResolve & Get()
void SetLabelType(CSeq_id::ELabelType labelType)
bool GetBestId(CSeq_id_Handle, CScope &, string &)
static SIZE_TYPE ReverseComplement(const string &src, TCoding src_coding, TSeqPos pos, TSeqPos length, string &dst)
Defines and provides stubs for a general interface to a variety of file formatters.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
const string AsFastaString(void) const
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Optimized implementation of CSerialObject::Assign, which is not so efficient.
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
@ eFasta
Tagged ID in NCBI's traditional FASTA style.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
bool IsNucleotide(void) const
TSeqPos GetBioseqLength(void) const
CSeqVector GetSeqVector(EVectorCoding coding, ENa_strand strand=eNa_strand_plus) const
Get sequence: Iupacna or Iupacaa if use_iupac_coding is true.
@ eCoding_Iupac
Set coding to printable coding (Iupacna or Iupacaa)
void GetSeqData(TSeqPos start, TSeqPos stop, string &buffer) const
Fill the buffer string with the sequence data for the interval [start, stop).
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
void Reset(void)
Reset reference object.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
bool CanGetDim(void) const
Check if it is safe to call GetDim method.
const TDenseg & GetDenseg(void) const
Get the variant data.
E_Choice Which(void) const
Which variant is currently selected.
const TGenomic_id & GetGenomic_id(void) const
Get the Genomic_id member data.
E_Choice Which(void) const
Which variant is currently selected.
bool IsSetStrands(void) const
Check if a value has been assigned to Strands data member.
bool IsSetProduct_strand(void) const
should be 'plus' or 'minus' Check if a value has been assigned to Product_strand data member.
const TStarts & GetStarts(void) const
Get the Starts member data.
const TProduct_id & GetProduct_id(void) const
Get the Product_id member data.
const TLens & GetLens(void) const
Get the Lens member data.
bool CanGetNumseg(void) const
Check if it is safe to call GetNumseg method.
const TFirst_id & GetFirst_id(void) const
Get the First_id member data.
TProduct_type GetProduct_type(void) const
Get the Product_type member data.
TGenomic_strand GetGenomic_strand(void) const
Get the Genomic_strand member data.
bool CanGetIds(void) const
Check if it is safe to call GetIds method.
const TSpliced & GetSpliced(void) const
Get the variant data.
TDim GetDim(void) const
Get the Dim member data.
bool IsSetGenomic_strand(void) const
Check if a value has been assigned to Genomic_strand data member.
const TLens & GetLens(void) const
Get the Lens member data.
const TExons & GetExons(void) const
Get the Exons member data.
bool IsSetSecond_strands(void) const
Check if a value has been assigned to Second_strands data member.
const TFirst_starts & GetFirst_starts(void) const
Get the First_starts member data.
TNumseg GetNumseg(void) const
Get the Numseg member data.
bool IsSetExons(void) const
set of segments involved each segment corresponds to one exon exons are always in biological order Ch...
const TSecond_strands & GetSecond_strands(void) const
Get the Second_strands member data.
list< CRef< CSpliced_exon_chunk > > TParts
const TSecond_id & GetSecond_id(void) const
Get the Second_id member data.
bool CanGetStarts(void) const
Check if it is safe to call GetStarts method.
TNumseg GetNumseg(void) const
Get the Numseg member data.
TProduct_strand GetProduct_strand(void) const
Get the Product_strand member data.
const TSparse & GetSparse(void) const
Get the variant data.
const TRows & GetRows(void) const
Get the Rows member data.
const TStrands & GetStrands(void) const
Get the Strands member data.
const TSegs & GetSegs(void) const
Get the Segs member data.
bool CanGetLens(void) const
Check if it is safe to call GetLens method.
bool IsSetGenomic_id(void) const
Check if a value has been assigned to Genomic_id data member.
@ e_Product_ins
insertion in product sequence (i.e. gap in the genomic sequence)
@ e_Diag
both sequences are represented, there is sufficient similarity between product and genomic sequences....
@ e_Genomic_ins
insertion in genomic sequence (i.e. gap in the product sequence)
@ e_Match
both sequences represented, product and genomic sequences match
@ e_Mismatch
both sequences represented, product and genomic sequences do not match
@ e_not_set
No variant selected.
@ eProduct_type_transcript
ENa_strand
strand of nucleic acid
range(_Ty, _Ty) -> range< _Ty >