NCBI C++ ToolKit
gff_writer.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: gff_writer.cpp 101758 2024-02-07 15:03:49Z foleyjp $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Frank Ludwig
27  *
28  * File Description: Write gff file
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
40 
41 #include <objmgr/feat_ci.hpp>
42 #include <objmgr/align_ci.hpp>
43 #include <objmgr/annot_ci.hpp>
44 #include <objmgr/seqdesc_ci.hpp>
45 #include <objmgr/bioseq_ci.hpp>
46 #include <objmgr/mapped_feat.hpp>
47 #include <objmgr/util/feature.hpp>
48 #include <objmgr/util/sequence.hpp>
50 
54 
57 
58 // ----------------------------------------------------------------------------
60  CScope& scope,
61  CNcbiOstream& ostr,
62  unsigned int uFlags ) :
63 // ----------------------------------------------------------------------------
64  CWriterBase( ostr, uFlags ),
65  m_bHeaderWritten(false)
66 {
67  m_pScope.Reset( &scope );
68  //SetAnnotSelector();
69 };
70 
71 // ----------------------------------------------------------------------------
73  CNcbiOstream& ostr,
74  unsigned int uFlags ) :
75 // ----------------------------------------------------------------------------
76  CWriterBase( ostr, uFlags ),
77  m_bHeaderWritten(false)
78 {
81  //SetAnnotSelector();
82 };
83 
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
87 {
88 };
89 
90 // ----------------------------------------------------------------------------
92  const CSeq_annot& annot,
93  const string& strAssemblyName,
94  const string& strAssemblyAccession )
95 // ----------------------------------------------------------------------------
96 {
97  if ( ! x_WriteAssemblyInfo( strAssemblyName, strAssemblyAccession ) ) {
98  return false;
99  }
100  if ( ! x_WriteAnnot( annot ) ) {
101  return false;
102  }
103  return true;
104 }
105 
106 // ----------------------------------------------------------------------------
108  const CSeq_annot& annot )
109 // ----------------------------------------------------------------------------
110 {
111  CSeq_annot_Handle sah = m_pScope->AddSeq_annot( annot );
112  bool bWrite = x_WriteSeqAnnotHandle( sah );
113  m_pScope->RemoveSeq_annot( sah );
114  return bWrite;
115 }
116 
117 // ----------------------------------------------------------------------------
119  CSeq_entry_Handle seh,
120  const string& strAssemblyName,
121  const string& strAssemblyAccession )
122 // ----------------------------------------------------------------------------
123 {
124  if ( ! x_WriteAssemblyInfo( strAssemblyName, strAssemblyAccession ) ) {
125  return false;
126  }
127  if ( ! x_WriteSeqEntryHandle( seh ) ) {
128  return false;
129  }
130  return true;
131 }
132 
133 // ----------------------------------------------------------------------------
135  CSeq_entry_Handle seh )
136 // ----------------------------------------------------------------------------
137 {
138  bool isNucProtSet = (seh.IsSet() && seh.GetSet().IsSetClass() &&
140  if (isNucProtSet) {
141  for (CBioseq_CI bci(seh); bci; ++bci) {
142  if (!x_WriteBioseqHandle(*bci)) {
143  return false;
144  }
145  }
146  return true;
147  }
148 
149  bool isGenbankSet = (seh.IsSet() && seh.GetSet().IsSetClass() &&
151  if (isGenbankSet) {
152  for (CSeq_entry_CI seci(seh); seci; ++seci) {
153 
154  if (!x_WriteSeqEntryHandle(*seci)) {
155  return false;
156  }
157  }
158  return true;
159  }
160 
161  if (seh.IsSeq()) {
162  CBioseq_Handle bsh = seh.GetSeq();
163  return x_WriteBioseqHandle(bsh);
164  }
165 
166  SAnnotSelector sel;
167  sel.SetMaxSize(1);
168  for (CAnnot_CI aci(seh, sel); aci; ++aci) {
169  CFeat_CI fit(*aci, SetAnnotSelector());
170  CSeq_id_Handle lastId;
171  for ( /*0*/; fit; ++fit ) {
172  CSeq_id_Handle currentId =fit->GetLocationId();
173  if (currentId != lastId) {
174  x_WriteSequenceHeader(currentId);
175  lastId = currentId;
176  }
177  if (!xWriteFeature(fit)) {
178  return false;
179  }
180  }
181  }
182 
183  for (CSeq_entry_CI eci(seh); eci; ++eci) {
184  if (!x_WriteSeqEntryHandle(*eci)) {
185  return false;
186  }
187  }
188  return true;
189 }
190 
191 // ----------------------------------------------------------------------------
193  CBioseq_Handle bsh,
194  const string& strAssemblyName,
195  const string& strAssemblyAccession )
196 // ----------------------------------------------------------------------------
197 {
198  if ( ! x_WriteAssemblyInfo( strAssemblyName, strAssemblyAccession ) ) {
199  return false;
200  }
201  if ( ! x_WriteBioseqHandle( bsh ) ) {
202  return false;
203  }
204  return true;
205 }
206 
207 // ----------------------------------------------------------------------------
209  CBioseq_Handle bsh )
210 // ----------------------------------------------------------------------------
211 {
213  const auto& display_range = GetRange();
214  CFeat_CI feat_iter(bsh, display_range, sel);
215  CGffFeatureContext fc(feat_iter, bsh);
216 
217  while (feat_iter) {
218  CMappedFeat mf = *feat_iter;
219  xWriteFeature(feat_iter);
220  ++feat_iter;
221  }
222  return true;
223 }
224 
225 // ----------------------------------------------------------------------------
228  const CMappedFeat& mf)
229 // ----------------------------------------------------------------------------
230 {
231  feature::CFeatTree& featTree = fc.FeatTree();
232  vector<CMappedFeat> vChildren;
233  featTree.GetChildrenTo(mf, vChildren);
234  for (auto cit = vChildren.begin(); cit != vChildren.end(); ++cit) {
235  CMappedFeat mChild = *cit;
236  if (!xWriteFeature(fc, mChild)) {
237  //error - but should have been handled elsewhere
238  continue;
239  }
240  xWriteAllChildren(fc, mChild);
241  }
242  return true;
243 }
244 
245 // ----------------------------------------------------------------------------
247  CSeq_annot_Handle sah,
248  const string& strAssemblyName,
249  const string& strAssemblyAccession )
250 // ----------------------------------------------------------------------------
251 {
252  if ( ! x_WriteAssemblyInfo( strAssemblyName, strAssemblyAccession ) ) {
253  return false;
254  }
255  if ( ! x_WriteSeqAnnotHandle( sah ) ) {
256  return false;
257  }
258  return true;
259 }
260 
261 // ----------------------------------------------------------------------------
263  CSeq_annot_Handle sah )
264 // ----------------------------------------------------------------------------
265 {
267 
268  if ( pAnnot->IsAlign() ) {
269  for ( CAlign_CI it( sah ); it; ++it ) {
270  if ( ! x_WriteAlign( *it ) ) {
271  return false;
272  }
273  }
274  return true;
275  }
276 
278  CFeat_CI feat_iter(sah, sel);
279  CGffFeatureContext fc(feat_iter, CBioseq_Handle(), sah);
280 
281  for (/*0*/; feat_iter; ++feat_iter) {
282  if (!xWriteFeature(fc,*feat_iter)) {
283  return false;
284  }
285  }
286  return true;
287 }
288 
289 // ----------------------------------------------------------------------------
291  CGffFeatureContext& context,
292  const CMappedFeat& mf )
293 // ----------------------------------------------------------------------------
294 {
295  return false;
296 }
297 
298 // ----------------------------------------------------------------------------
300  CFeat_CI feat_it)
301 // ----------------------------------------------------------------------------
302 {
303  if (!feat_it) {
304  return false;
305  }
306  CGffFeatureContext fc(feat_it, CBioseq_Handle(), feat_it->GetAnnot());
307  return xWriteFeature(fc, *feat_it);
308 }
309 
310 // ----------------------------------------------------------------------------
312  const CSeq_align& align,
313  const string& strAssName,
314  const string& strAssAcc )
315 // ----------------------------------------------------------------------------
316 {
317  if ( ! x_WriteAssemblyInfo( strAssName, strAssAcc ) ) {
318  return false;
319  }
320  if ( ! x_WriteAlign( align ) ) {
321  return false;
322  }
323  return true;
324 }
325 
326 // ----------------------------------------------------------------------------
328  const CSeq_align& align)
329 // ----------------------------------------------------------------------------
330 {
331  return false;
332 }
333 
334 // ----------------------------------------------------------------------------
336 // ----------------------------------------------------------------------------
337 {
338  if (!m_bHeaderWritten) {
339  m_Os << "##gff-version 2" << '\n';
340  m_bHeaderWritten = true;
341  }
342  return true;
343 }
344 
345 // ----------------------------------------------------------------------------
347 // ----------------------------------------------------------------------------
348 {
349  m_Os << "###" << '\n';
350  return true;
351 }
352 
353 // ----------------------------------------------------------------------------
355  const string& strName,
356  const string& strAccession )
357 // ----------------------------------------------------------------------------
358 {
359  if ( !strName.empty() ) {
360  m_Os << "##assembly name=" << strName << '\n';
361  }
362  if ( !strAccession.empty() ) {
363  m_Os << "##assembly accession=" << strAccession << '\n';
364  }
365  return true;
366 }
367 
368 // ----------------------------------------------------------------------------
370  CGffFeatureRecord& record,
372  const CMappedFeat& mf )
373  // ----------------------------------------------------------------------------
374 {
375  return xAssignFeatureBasic(record, fc, mf);
376 }
377 
378 // ----------------------------------------------------------------------------
380  CGffFeatureRecord& record,
382  const CMappedFeat& mf )
383  // ----------------------------------------------------------------------------
384 {
385  if (!xAssignFeatureType(record, fc, mf)) {
386  return false;
387  }
388  if (!xAssignFeatureSeqId(record, fc, mf)) {
389  return false;
390  }
391  if (!xAssignFeatureMethod(record, fc, mf)) {
392  return false;
393  }
394  if (!xAssignFeatureEndpoints(record, fc, mf)) {
395  return false;
396  }
397  if (!xAssignFeatureScore(record, fc, mf)) {
398  return false;
399  }
400  if (!xAssignFeatureStrand(record, fc, mf)) {
401  return false;
402  }
403  if (!xAssignFeaturePhase(record, fc, mf)) {
404  return false;
405  }
406  if (!xAssignFeatureAttributes(record, fc, mf)) {
407  return false;
408  }
409  return true;
410 }
411 
412 // ----------------------------------------------------------------------------
414  CGffFeatureRecord& record,
416  const CMappedFeat& mf )
417  // ----------------------------------------------------------------------------
418 {
419  string bestId;
420  if (!CGenbankIdResolve::Get().GetBestId(mf, bestId)) {
421  bestId = ".";
422  }
423  record.SetSeqId(bestId);
424  return true;
425 }
426 
427 // ----------------------------------------------------------------------------
429  CGffFeatureRecord& record,
431  const CMappedFeat& mf )
432  // ----------------------------------------------------------------------------
433 {
434  if ( !mf.IsSetQual() ) {
435  return true;
436  }
437  const vector< CRef< CGb_qual > >& quals = mf.GetQual();
438  vector< CRef< CGb_qual > >::const_iterator it = quals.begin();
439  for ( ; it != quals.end(); ++it ) {
440  if ( !(*it)->CanGetQual() || !(*it)->CanGetVal() ) {
441  continue;
442  }
443  if ( (*it)->GetQual() == "gff_score" ) {
444  record.SetScore((*it)->GetVal());
445  return true;
446  }
447  }
448  return true;
449  return true;
450 }
451 
452 // ----------------------------------------------------------------------------
454  CGffFeatureRecord& record,
456  const CMappedFeat& mf )
457  // ----------------------------------------------------------------------------
458 {
459  return true;
460 }
461 
462 // ----------------------------------------------------------------------------
464  CGffFeatureRecord& record,
466  const CMappedFeat& mf )
467  // ----------------------------------------------------------------------------
468 {
469  record.SetType(".");
470  return true;
471 }
472 
473 // ----------------------------------------------------------------------------
475  CGffFeatureRecord& record,
477  const CMappedFeat& mf )
478  // ----------------------------------------------------------------------------
479 {
480  const auto& location = mf.GetLocation();
481  record.SetStrand(
482  location.IsSetStrand() ? location.GetStrand() : eNa_strand_plus);
483  return true;
484 }
485 
486 // ----------------------------------------------------------------------------
488  CGffFeatureRecord& record,
490  const CMappedFeat& mf )
491  // ----------------------------------------------------------------------------
492 {
493  record.SetMethod(".");
494  return true;
495 }
496 
497 // ----------------------------------------------------------------------------
499  CGffFeatureRecord& record,
501  const CMappedFeat& mf )
502  // ----------------------------------------------------------------------------
503 {
504  unsigned int start(0);
505  unsigned int stop(0);
506  auto strand = mf.GetLocation().GetStrand();
507 
508  if (CWriteUtil::IsTransspliced(mf)) {
510  start, stop)) {
511  return false;
512  }
513  CGffBaseRecord& baseRecord = record;
514  baseRecord.SetLocation(start, stop, strand);
515  return true;
516  }
519  record.SetEndpoints(start, stop, strand);
520  return true;
521 }
522 
523 // ----------------------------------------------------------------------------
525  CGffFeatureRecord& record,
527  const CMappedFeat& mf )
528 // ----------------------------------------------------------------------------
529 {
530  if (!xAssignFeatureAttributesFormatIndependent(record, fc, mf)) {
531  return false;
532  }
533  return xAssignFeatureAttributesFormatSpecific(record, fc, mf);
534 }
535 
536 // ----------------------------------------------------------------------------
538  CGffFeatureRecord& record,
540  const CMappedFeat& mf )
541 // ----------------------------------------------------------------------------
542 {
543  record.SetGbKeyFrom(mf);
544  return(
545  xAssignFeatureAttributesQualifiers(record, fc, mf) &&
546  xAssignFeatureAttributeDbxref(record, fc, mf) &&
547  xAssignFeatureAttributeNote(record, fc, mf) &&
548  xAssignFeatureAttributeException(record, fc, mf) &&
549  xAssignFeatureAttributeExperiment(record, fc, mf) &&
550  xAssignFeatureAttributeProduct(record, fc, mf) &&
551  xAssignFeatureAttributesGene(record, fc, mf) &&
552  xAssignFeatureAttributeOldLocusTag(record, fc, mf) &&
553  xAssignFeatureAttributeGeneBiotype(record, fc, mf) &&
554  xAssignFeatureAttributeMapLoc(record, fc, mf) &&
555  //xAssignFeatureAttributeRibosomalSlippage(record, fc, mf) &&
556  xAssignFeatureAttributePseudoGene(record, fc, mf) &&
557  xAssignFeatureAttributeFunction(record, fc, mf) &&
558  xAssignFeatureAttributesGoMarkup(record, fc, mf) &&
559  xAssignFeatureAttributeProteinId(record, fc, mf) &&
561  xAssignFeatureAttributeCodeBreak(record, fc, mf) &&
563  xAssignFeatureAttributeRptFamily(record, fc, mf) &&
564  xAssignFeatureAttributeIsOrdered(record, fc, mf) &&
565  xAssignFeatureAttributeEcNumbers(record, fc, mf) &&
566  xAssignFeatureAttributeExonNumber(record, fc, mf) &&
567  xAssignFeatureAttributePartial(record, fc, mf) &&
568  xAssignFeatureAttributePseudo(record, fc, mf));
569 }
570 
571 // ----------------------------------------------------------------------------
573  CGffFeatureRecord& record,
575  const CMappedFeat& mf )
576 // ----------------------------------------------------------------------------
577 {
578  return true;
579 }
580 
581 
582 static string s_GetDbxrefFromProduct(const CMappedFeat& mf)
583 {
584  string dbxref;
585  if (!mf.IsSetProduct()) {
586  return dbxref;
587  }
588 
590  if (idh) {
591  idh.GetSeqId()->GetLabel(&dbxref, CSeq_id::eContent);
592  if (NPOS != dbxref.find('_')) { //nucleotide
593  dbxref = string("GenBank:") + dbxref;
594  }
595  else { //protein
596  dbxref = string("NCBI_GP:") + dbxref;
597  }
598  return dbxref;
599  }
600 
601  // else
603  if (idh) {
604  idh.GetSeqId()->GetLabel(&dbxref, CSeq_id::eContent);
605  dbxref = string("NCBI_gi:") + dbxref;
606  }
607 
608  return dbxref;
609 }
610 
611 
612 // ----------------------------------------------------------------------------
614  CGffFeatureRecord& record,
616  const string& label,
617  const CMappedFeat& mf )
618 // ----------------------------------------------------------------------------
619 {
620  if (mf.IsSetDbxref()) {
621  for (const auto& pDbxref : mf.GetDbxref()) {
622  string dbxref;
623  if (CWriteUtil::GetDbTag(*pDbxref, dbxref)) {
624  record.AddAttribute(label, dbxref);
625  }
626  }
627  }
628 
629  switch (mf.GetData().Which()) {
630  default: {
631  CMappedFeat parent;
632  try {
633  parent = fc.FeatTree().GetParent( mf );
634  }
635  catch(...) {
636  }
637  if (parent) {
638  if (parent.IsSetData() && parent.GetData().IsGene()) {
639  const auto& geneRef = mf.GetGeneXref();
640  if (geneRef && geneRef->IsSuppressed()) {
641  return true;
642  }
643  }
644  if (parent.IsSetDbxref()) {
645  for (const auto& pDbxref : parent.GetDbxref()) {
646  string dbxref;
647  if (CWriteUtil::GetDbTag(*pDbxref, dbxref)) {
648  record.AddAttribute(label, dbxref);
649  }
650  }
651  }
652  }
653  return true;
654  }
655 
658  auto dbxref = s_GetDbxrefFromProduct(mf);
659  if (!dbxref.empty()) {
660  record.AddAttribute(label, dbxref);
661  }
662  auto gene_feat = fc.FeatTree().GetParent(mf, CSeqFeatData::e_Gene);
663  if (gene_feat && gene_feat.IsSetDbxref() &&
664  gene_feat.IsSetData() && !gene_feat.GetData().GetGene().IsSuppressed()) {
665  for (const auto& pDbxref : gene_feat.GetDbxref() ) {
666  string dbxref;
667  if (CWriteUtil::GetDbTag(*pDbxref, dbxref)) {
668  record.AddAttribute(label, dbxref);
669  }
670  }
671  }
672  }
673  break;
674  }
675  return true;
676 }
677 
678 
679 // ----------------------------------------------------------------------------
681  CGffFeatureRecord& record,
683  const CMappedFeat& mf )
684  // ----------------------------------------------------------------------------
685 {
686  if (mf.IsSetPseudo() && mf.GetPseudo()) {
687  record.SetAttribute("pseudo", "true");
688  fc.AssignShouldInheritPseudo(true);
689  return true;
690  }
691  if (fc.ShouldInheritPseudo()) {
692  record.SetAttribute("pseudo", "true");
693  return true;
694  }
695  return true;
696 }
697 
698 // ----------------------------------------------------------------------------
700  CGffFeatureRecord& record,
702  const CMappedFeat& mf )
703 // ----------------------------------------------------------------------------
704 {
705  if (mf.IsMapped() && mf.IsSetPartial() && mf.GetPartial()) {
706  record.SetAttribute("partial", "true");
707  return true;
708  }
709 
710  if (!mf.IsMapped() && mf.GetSeq_feat()->IsSetPartial() &&
711  mf.GetSeq_feat()->GetPartial()) {
712  record.SetAttribute("partial", "true");
713  return true;
714  }
715 
716  const CRange<TSeqPos>& display_range = GetRange();
717  const CRange<TSeqPos>& feat_range = mf.GetLocation().GetTotalRange();
718  if (display_range.IntersectionWith(feat_range).NotEmpty() &&
719  (display_range.GetFrom() > feat_range.GetFrom() ||
720  display_range.GetTo() < feat_range.GetTo())) {
721  record.SetAttribute("partial", "true");
722  return true;
723  }
724  return true;
725 }
726 
727 // ----------------------------------------------------------------------------
729  CGffFeatureRecord& record,
731  const CMappedFeat& mf )
732 // ----------------------------------------------------------------------------
733 {
734  if (!mf.IsSetData() || !mf.GetData().IsCdregion()) {
735 
736  return true;
737  }
738  const CSeqFeatData::TCdregion& cds = mf.GetData().GetCdregion();
739  if (!cds.IsSetCode()) {
740  return true;
741  }
742  int id = cds.GetCode().GetId();
743  if (id != 1 && id != 255) {//former gff3 version
744  //if (true) {//former gtf version
745  record.SetAttribute("transl_table", NStr::IntToString(id));
746  return true;
747  }
748  return true;
749 }
750 
751 // ----------------------------------------------------------------------------
753  CGffFeatureRecord& record,
755  const CMappedFeat& mf )
756 // ----------------------------------------------------------------------------
757 {
758  auto featSubtype = mf.GetFeatSubtype();
759  if (featSubtype != CSeq_feat::TData::eSubtype_cdregion) {
760  return true;
761  }
762  if (mf.IsSetExcept_text()) {
763  if (mf.GetExcept_text() == "ribosomal slippage") {
764  record.AddAttribute("ribosomal_slippage", "");
765  }
766  }
767  return true;
768 }
769 
770 // ----------------------------------------------------------------------------
772  CGffFeatureRecord& record,
774  const CMappedFeat& mf )
775 // ----------------------------------------------------------------------------
776 {
777  auto featSubtype = mf.GetFeatSubtype();
778  if (featSubtype != CSeq_feat::TData::eSubtype_cdregion) {
779  return true;
780  }
781 
782  auto protein_id = mf.GetNamedQual("protein_id");
783  if (!protein_id.empty()) {
784  record.AddAttribute("protein_id", protein_id);
785  return true;
786  }
787  if (mf.IsSetProduct()) {
788  string product;
790  mf.GetProductId(), mf.GetScope(), product)) {
791  record.AddAttribute("protein_id", product);
792  return true;
793  }
794  record.AddAttribute(
795  "protein_id", mf.GetProduct().GetId()->GetSeqIdString(true));
796  return true;
797  }
798  return true;
799 }
800 
801 // ----------------------------------------------------------------------------
803  CGffFeatureRecord& record,
805  const CMappedFeat& mf )
806 // ----------------------------------------------------------------------------
807 {
808 
809  CSeqFeatData::ESubtype subtype = mf.GetFeatSubtype();
810  if (subtype == CSeqFeatData::eSubtype_cdregion) {
811 
812  // Possibility 1:
813  // Product name comes from a prot-ref which stored in the seqfeat's
814  // xrefs:
815  const CProt_ref* pProtRef = mf.GetProtXref();
816  if ( pProtRef && pProtRef->IsSetName() ) {
817  const list<string>& names = pProtRef->GetName();
818  record.SetAttribute("product", names.front());
819  return true;
820  }
821 
822  // Possibility 2:
823  // Product name is from the prot-ref refered to by the seqfeat's
824  // data.product:
825  if (mf.IsSetProduct()) {
826  const CSeq_id* pId = mf.GetProduct().GetId();
827  if (pId) {
828  CBioseq_Handle bsh = mf.GetScope().GetBioseqHandle(*pId);
829  if (bsh) {
832  CFeat_CI it(bsh, sel);
833  if (it && it->IsSetData()
834  && it->GetData().GetProt().IsSetName()
835  && !it->GetData().GetProt().GetName().empty()) {
836  record.SetAttribute("product",
837  it->GetData().GetProt().GetName().front());
838  return true;
839  }
840  }
841  }
842 
843  string product;
845  mf.GetProductId(), mf.GetScope(), product)) {
846  record.SetAttribute("product", product);
847  return true;
848  }
849  }
850  }
851 
853  if (type == CSeqFeatData::e_Rna) {
854  const CRNA_ref& rna = mf.GetData().GetRna();
855 
856  if (subtype == CSeqFeatData::eSubtype_tRNA) {
857  if (rna.IsSetExt() && rna.GetExt().IsTRNA()) {
858 
859  const CRange<TSeqPos>& display_range = GetRange();
860  const CTrna_ext& trna = display_range.IsWhole() ?
861  rna.GetExt().GetTRNA() :
862  *sequence::CFeatTrim::Apply(rna.GetExt().GetTRNA(), display_range);
863 
864  string anticodon;
865  if (CWriteUtil::GetTrnaAntiCodon(trna, anticodon)) {
866  record.SetAttribute("anticodon", anticodon);
867  }
868  string codons;
869  if (CWriteUtil::GetTrnaCodons(trna, codons)) {
870  record.SetAttribute("codons", codons);
871  }
872  string aa;
873  if (CWriteUtil::GetTrnaProductName(trna, aa)) {
874  record.SetAttribute("product", aa);
875  return true;
876  }
877  }
878  }
879 
880  if (rna.IsSetExt() && rna.GetExt().IsName()) {
881  record.SetAttribute("product", rna.GetExt().GetName());
882  return true;
883  }
884 
885  if (rna.IsSetExt() && rna.GetExt().IsGen() &&
886  rna.GetExt().GetGen().IsSetProduct() ) {
887  record.SetAttribute("product", rna.GetExt().GetGen().GetProduct());
888  return true;
889  }
890  }
891 
892  // finally, look for gb_qual
893  if (mf.IsSetQual()) {
894  const CSeq_feat::TQual& quals = mf.GetQual();
895  for ( CSeq_feat::TQual::const_iterator cit = quals.begin();
896  cit != quals.end(); ++cit) {
897  if ((*cit)->IsSetQual() && (*cit)->IsSetVal() &&
898  (*cit)->GetQual() == "product") {
899  record.SetAttribute("product", (*cit)->GetVal());
900  return true;
901  }
902  }
903  }
904  return true;
905 }
906 
907 // ----------------------------------------------------------------------------
909  CGffFeatureRecord& record,
911  const CMappedFeat& mf )
912 // ----------------------------------------------------------------------------
913 {
914  if (!mf.IsSetData() || !mf.GetData().IsCdregion()) {
915  return true;
916  }
917  const CSeqFeatData::TCdregion& cds = mf.GetData().GetCdregion();
918  if (!cds.IsSetCode_break()) {
919  return true;
920  }
921 
922  const list<CRef<CCode_break> >& code_breaks = cds.GetCode_break();
923 
924  const CRange<TSeqPos>& display_range = GetRange();
925  if (!display_range.IsWhole()) { // Trim the code breaks before writing
926  for (CRef<CCode_break> code_break : code_breaks) {
927  string cbString;
928  CRef<CCode_break> trimmed_cb = sequence::CFeatTrim::Apply(*code_break, display_range);
929  if (trimmed_cb.NotEmpty() &&
930  CWriteUtil::GetCodeBreak(*trimmed_cb, cbString)) {
931  record.AddAttribute("transl_except", cbString);
932  }
933  }
934  return true;
935  }
936 
937  list<CRef<CCode_break> >::const_iterator it = code_breaks.begin();
938  for (; it != code_breaks.end(); ++it) {
939  string cbString;
940  if (CWriteUtil::GetCodeBreak(**it, cbString)) {
941  record.AddAttribute("transl_except", cbString);
942  }
943  }
944  return true;
945 }
946 
947 // ----------------------------------------------------------------------------
948 const CGene_ref&
951  const CMappedFeat& mf)
952 // ----------------------------------------------------------------------------
953 {
954  static const CGene_ref noRef;
955  if (mf.GetData().IsGene()) {
956  return mf.GetData().GetGene();
957  }
958  // do not use xref gene ref directly !!!
959  CMappedFeat gene = fc.FindBestGeneParent(mf);
960  if (gene && gene.IsSetData() && gene.GetData().IsGene()) {
961  return gene.GetData().GetGene();
962  }
963  return noRef;
964 }
965 
966 // ----------------------------------------------------------------------------
968  CGffFeatureRecord& record,
970  const CMappedFeat& mf )
971 // ----------------------------------------------------------------------------
972 {
973  const auto& geneRef = sGetClosestGeneRef(fc, mf);
974  if (geneRef.IsSetLocus()) {
975  record.SetAttribute("gene", geneRef.GetLocus());
976  }
977  if (geneRef.IsSetLocus_tag()) {
978  record.SetAttribute("locus_tag", geneRef.GetLocus_tag());
979  }
980  if (mf.GetData().IsGene()) {
981  if (geneRef.IsSetDesc()) {
982  record.SetAttribute("description", geneRef.GetDesc());
983  }
984  if (geneRef.IsSetSyn()) {
985  const auto& syns = geneRef.GetSyn();
986  auto it = syns.begin();
987  while (it != syns.end()) {
988  record.AddAttribute("gene_synonym", *(it++));
989  }
990  }
991  }
992  return true;
993 
994 }
995 
996 // ----------------------------------------------------------------------------
998  CGffFeatureRecord& record,
1000  const CMappedFeat& mf)
1001 // ----------------------------------------------------------------------------
1002 {
1003  if (!mf.GetData().IsGene()) {
1004  return true;
1005  }
1006  if (!mf.IsSetQual()) {
1007  return true;
1008  }
1009  string old_locus_tags;
1010  vector<CRef<CGb_qual> > quals = mf.GetQual();
1011  for (vector<CRef<CGb_qual> >::const_iterator it = quals.begin();
1012  it != quals.end(); ++it) {
1013  if ((**it).IsSetQual() && (**it).IsSetVal()) {
1014  string qual = (**it).GetQual();
1015  if (qual != "old_locus_tag") {
1016  continue;
1017  }
1018  if (!old_locus_tags.empty()) {
1019  old_locus_tags += ",";
1020  }
1021  old_locus_tags += (**it).GetVal();
1022  }
1023  }
1024  if (!old_locus_tags.empty()) {
1025  record.SetAttribute("old_locus_tag", old_locus_tags);
1026  }
1027  return true;
1028 }
1029 
1030 // ----------------------------------------------------------------------------
1032  CGffFeatureRecord& record,
1034  const CMappedFeat& mf)
1035 // ----------------------------------------------------------------------------
1036 {
1037  // if a biosource is present then only compute if also is genomic record
1038  // if a biosource is not present then always compute
1039  if (!mf.GetData().IsGene()) {
1040  return true;
1041  }
1042  if (fc.HasSequenceBioSource() && !fc.IsSequenceGenomicRecord()) {
1043  return true;
1044  }
1045 
1046  string biotype;
1047  if (!feature::GetFeatureGeneBiotypeFaster(fc.FeatTree(), mf, biotype)) {
1048  return true;
1049  }
1050  record.SetAttribute("gene_biotype", biotype);
1051  return true;
1052 }
1053 
1054 
1055 // ----------------------------------------------------------------------------
1057  CGffFeatureRecord& record,
1059  const CMappedFeat& mf )
1060 // ----------------------------------------------------------------------------
1061 {
1062  if (!mf.GetData().IsGene()) {
1063  return true;
1064  }
1065  const CGene_ref& gene_ref = mf.GetData().GetGene();
1066  if (!gene_ref.IsSetMaploc()) {
1067  return true;
1068  }
1069  record.SetAttribute("map", gene_ref.GetMaploc());
1070  return true;
1071 }
1072 
1073 
1074 // ----------------------------------------------------------------------------
1076  CGffFeatureRecord& record,
1078  const CMappedFeat& mf )
1079 // ----------------------------------------------------------------------------
1080 {
1081  if (mf.IsSetExcept_text()) {
1082  record.SetAttribute("exception", mf.GetExcept_text());
1083  return true;
1084  }
1085  if (mf.IsSetExcept()) {
1086  // what should I do?
1087  return true;
1088  }
1089  return true;
1090 }
1091 
1092 
1093 // ----------------------------------------------------------------------------
1095  CGffFeatureRecord& record,
1097  const CMappedFeat& mf )
1098 // ----------------------------------------------------------------------------
1099 {
1100  vector<string> experiments;
1101  const auto& quals = mf.GetQual();
1102  for (const auto& qual: quals) {
1103  if (qual->GetQual() == "experiment") {
1104  experiments.push_back(qual->GetVal());
1105  }
1106  }
1107  if (!experiments.empty()) {
1108  record.SetAttributes("experiment", experiments);
1109  }
1110  return true;
1111 }
1112 
1113 // ----------------------------------------------------------------------------
1115  CGffFeatureRecord& record,
1117  const CMappedFeat& mf)
1118 // ----------------------------------------------------------------------------
1119 {
1120  string modelEvidence;
1121  if (!CWriteUtil::GetStringForModelEvidence(mf, modelEvidence)) {
1122  return true;
1123  }
1124  if (!modelEvidence.empty()) {
1125  record.SetAttribute("model_evidence", modelEvidence);
1126  }
1127  return true;
1128 }
1129 
1130 // ----------------------------------------------------------------------------
1132  CGffFeatureRecord& record,
1134  const CMappedFeat& mf)
1135 // -----------------------------------------------------------------------------
1136 {
1138  switch (s) {
1139  default:
1140  return true;
1143  const CSeq_feat::TQual& quals = mf.GetQual();
1144  if (quals.empty()) {
1145  return true;
1146  }
1147  for (CSeq_feat::TQual::const_iterator cit = quals.begin();
1148  cit != quals.end(); ++cit) {
1149  if ((*cit)->GetQual() == "rpt_family") {
1150  record.SetAttribute("rpt_family", (*cit)->GetVal());
1151  return true;
1152  }
1153  }
1154  }
1155  }
1156  return true;
1157 }
1158 
1159 // ----------------------------------------------------------------------------
1161  CGffFeatureRecord& record,
1163  const CMappedFeat& mf )
1164 // ----------------------------------------------------------------------------
1165 {
1166  string pseudoGene = mf.GetNamedQual("pseudogene");
1167  if (!pseudoGene.empty()) {
1168  record.SetAttribute("pseudogene", pseudoGene);
1169  return true;
1170  }
1173  return true;
1174  }
1175  CMappedFeat gene = fc.FindBestGeneParent(mf);
1176  if (!gene) {
1177  return true;
1178  }
1179  pseudoGene = gene.GetNamedQual("pseudogene");
1180  if (!pseudoGene.empty()) {
1181  record.SetAttribute("pseudogene", pseudoGene);
1182  return true;
1183  }
1184  return true;
1185 }
1186 
1187 // ----------------------------------------------------------------------------
1189  CGffFeatureRecord& record,
1191  const CMappedFeat& mf )
1192 // ----------------------------------------------------------------------------
1193 {
1195  record.SetAttribute("is_ordered", "true");
1196  }
1197  return true;
1198 }
1199 
1200 // ----------------------------------------------------------------------------
1202  CGffFeatureRecord& record,
1204  const CMappedFeat& mf )
1205 // ----------------------------------------------------------------------------
1206 {
1207  const string& function = mf.GetNamedQual("function");
1208  if (!function.empty()) {
1209  record.SetAttribute("function", function);
1210  return true;
1211  }
1212  if (CSeqFeatData::e_Prot != mf.GetFeatType()) {
1213  return true;
1214  }
1215  const CProt_ref& prot = mf.GetData().GetProt();
1216  if (prot.CanGetActivity() && !prot.GetActivity().empty()) {
1217  record.SetAttribute("function", prot.GetActivity().front());
1218  return true;
1219  }
1220  return true;
1221 }
1222 
1223 // ----------------------------------------------------------------------------
1225  CGffFeatureRecord& record,
1227  const CMappedFeat& mf )
1228 // ----------------------------------------------------------------------------
1229 {
1230  const string& go_component = mf.GetNamedQual("go_component");
1231  if (!go_component.empty()) {
1232  record.SetAttribute("go_component", go_component);
1233  return true;
1234  }
1235  if (!mf.IsSetExt()) {
1236  return true;
1237  }
1238 
1239  const auto& ext = mf.GetExt();
1240  if (!ext.IsSetType() || !ext.GetType().IsStr()) {
1241  return true;
1242  }
1243  if (ext.GetType().GetStr() == "GeneOntology") {
1244  list<string> goIds;
1245  const auto& goFields = ext.GetData();
1246  for (const auto& goField: goFields) {
1247  if (!goField->IsSetLabel() || !goField->GetLabel().IsStr()) {
1248  continue;
1249  }
1250  const auto& goLabel = goField->GetLabel().GetStr();
1251  if (goLabel == "Component" && goField->IsSetData()
1252  && goField->GetData().IsFields()) {
1253  const auto& fields = goField->GetData().GetFields();
1254  vector<string> goStrings;
1255  if (CWriteUtil::GetStringsForGoMarkup(fields, goStrings)) {
1256  record.SetAttributes("go_component", goStrings);
1257  }
1258  CWriteUtil::GetListOfGoIds(fields, goIds);
1259  continue;
1260  }
1261  if (goLabel == "Process" && goField->IsSetData()
1262  && goField->GetData().IsFields()) {
1263  const auto& fields = goField->GetData().GetFields();
1264  vector<string> goStrings;
1265  if (CWriteUtil::GetStringsForGoMarkup(fields, goStrings)) {
1266  record.SetAttributes("go_process", goStrings);
1267  }
1268  CWriteUtil::GetListOfGoIds(fields, goIds);
1269  continue;
1270  }
1271  if (goLabel == "Function" && goField->IsSetData()
1272  && goField->GetData().IsFields()) {
1273  const auto& fields = goField->GetData().GetFields();
1274  vector<string> goStrings;
1275  if (CWriteUtil::GetStringsForGoMarkup(fields, goStrings)) {
1276  record.SetAttributes("go_function", goStrings);
1277  }
1278  CWriteUtil::GetListOfGoIds(fields, goIds);
1279  continue;
1280  }
1281  }
1282  if (!goIds.empty()) {
1283  record.SetAttributes("Ontology_term", vector<string>(goIds.begin(), goIds.end()));
1284  }
1285  } else if (ext.GetType().GetStr() == "CombinedFeatureUserObjects") {
1286  const CUser_object::TData & ext_data = ext.GetData();
1287  ITERATE (CSeq_feat::TExt::TData, it, ext_data) {
1288  const CUser_field & field = **it;
1289  if( ! field.IsSetLabel() || ! field.IsSetData() ) {
1290  continue;
1291  }
1292  const CUser_field::TLabel & field_label = field.GetLabel();
1293  const CUser_field::TData & field_data = field.GetData();
1294  if (field_label.IsStr() && field_label.GetStr() == "GeneOntology") {
1295  if (field_data.IsFields()) {
1296  list<string> goIds;
1297  const auto& goFields = field.GetData().GetFields();
1298  for (const auto& goField: goFields) {
1299  if (!goField->IsSetLabel() || !goField->GetLabel().IsStr()) {
1300  continue;
1301  }
1302  const auto& goLabel = goField->GetLabel().GetStr();
1303  if (goLabel == "Component" && goField->IsSetData()
1304  && goField->GetData().IsFields()) {
1305  const auto& fields = goField->GetData().GetFields();
1306  vector<string> goStrings;
1307  if (CWriteUtil::GetStringsForGoMarkup(fields, goStrings, true)) {
1308  record.SetAttributes("go_component", goStrings);
1309  }
1310  CWriteUtil::GetListOfGoIds(fields, goIds, true);
1311  continue;
1312  }
1313  if (goLabel == "Process" && goField->IsSetData()
1314  && goField->GetData().IsFields()) {
1315  const auto& fields = goField->GetData().GetFields();
1316  vector<string> goStrings;
1317  if (CWriteUtil::GetStringsForGoMarkup(fields, goStrings, true)) {
1318  record.SetAttributes("go_process", goStrings);
1319  }
1320  CWriteUtil::GetListOfGoIds(fields, goIds, true);
1321  continue;
1322  }
1323  if (goLabel == "Function" && goField->IsSetData()
1324  && goField->GetData().IsFields()) {
1325  const auto& fields = goField->GetData().GetFields();
1326  vector<string> goStrings;
1327  if (CWriteUtil::GetStringsForGoMarkup(fields, goStrings, true)) {
1328  record.SetAttributes("go_function", goStrings);
1329  }
1330  CWriteUtil::GetListOfGoIds(fields, goIds, true);
1331  continue;
1332  }
1333  }
1334  if (!goIds.empty()) {
1335  record.SetAttributes("Ontology_term", vector<string>(goIds.begin(), goIds.end()));
1336  }
1337  }
1338  }
1339  }
1340  }
1341 
1342  return true;
1343 }
1344 
1345 // ----------------------------------------------------------------------------
1347  CGffFeatureRecord& record,
1349  const CMappedFeat& mf )
1350 // ----------------------------------------------------------------------------
1351 {
1352  if (CSeqFeatData::e_Prot != mf.GetFeatType()) {
1353  return true;
1354  }
1355  const CProt_ref& prot = mf.GetData().GetProt();
1356  if (prot.CanGetEc()) {
1357  const list<string> ec = prot.GetEc();
1358  if (!ec.empty()) {
1359  record.SetAttributes(
1360  "ec_number", vector<string>(ec.begin(), ec.end()));
1361  }
1362  return true;
1363  }
1364  return true;
1365 }
1366 
1367 // ----------------------------------------------------------------------------
1369  CGffFeatureRecord& record,
1371  const CMappedFeat& mf )
1372 // ----------------------------------------------------------------------------
1373 {
1374  if (!mf.IsSetQual()) {
1375  return true;
1376  }
1377  const CSeq_feat::TQual& quals = mf.GetQual();
1378  for ( CSeq_feat::TQual::const_iterator cit = quals.begin();
1379  cit != quals.end();
1380  ++cit ) {
1381  const CGb_qual& qual = **cit;
1382  if (qual.IsSetQual() && qual.GetQual() == "number") {
1383  record.SetAttribute("exon_number", qual.GetVal());
1384  return true;
1385  }
1386  }
1387  return true;
1388 }
1389 
1390 // ----------------------------------------------------------------------------
1392  const CMappedFeat& mf)
1393 // ----------------------------------------------------------------------------
1394 {
1395  static list<CSeqFeatData::ESubtype> acceptableTranscriptTypes = {
1402  };
1403  auto itType = std::find(
1404  acceptableTranscriptTypes.begin(), acceptableTranscriptTypes.end(),
1405  mf.GetFeatSubtype());
1406  return (itType != acceptableTranscriptTypes.end());
1407 }
1408 
1409 // ----------------------------------------------------------------------------
1411  CGffFeatureContext& context,
1412  const CMappedFeat& mf)
1413 // ----------------------------------------------------------------------------
1414 {
1415  CMappedFeat parent = context.FeatTree().GetParent(mf);
1416  if (!parent) {
1417  return false;
1418  }
1419  return IsTranscriptType(parent);
1420 }
1421 
1422 // ----------------------------------------------------------------------------
1424  CGffFeatureContext& context,
1425  const CMappedFeat& mf )
1426 // ----------------------------------------------------------------------------
1427 {
1429  return CMappedFeat();
1430  }
1431  if (HasAccaptableTranscriptParent(context, mf)) {
1432  return CMappedFeat();
1433  }
1434 
1435  CRef<CSeq_feat> pMissingTranscript(new CSeq_feat);
1436  pMissingTranscript.Reset(new CSeq_feat);
1437  pMissingTranscript->SetData().SetRna().SetType(CRNA_ref::eType_mRNA);
1438  pMissingTranscript->SetLocation().Assign(mf.GetLocation());
1439  pMissingTranscript->SetLocation().SetPartialStart(false, eExtreme_Positional);
1440  pMissingTranscript->SetLocation().SetPartialStop(false, eExtreme_Positional);
1441  pMissingTranscript->ResetPartial();
1442 
1443  // rw-1921
1444  if (mf.IsSetExcept() && mf.GetExcept()) {
1445  pMissingTranscript->SetExcept(true);
1446  if (mf.IsSetExcept_text()) {
1447  pMissingTranscript->SetExcept_text(mf.GetExcept_text());
1448  }
1449  }
1450  CScope& scope = mf.GetScope();
1451  CSeq_annot_Handle sah = mf.GetAnnot();
1452  CSeq_annot_EditHandle saeh = sah.GetEditHandle();
1453  saeh.AddFeat(*pMissingTranscript);
1454  CMappedFeat tf = scope.GetObjectHandle(*pMissingTranscript);
1455  context.FeatTree().AddFeature(tf);
1456  return tf;
1457 }
1458 
1459 // ----------------------------------------------------------------------------
1461  const list<CRef<CSeq_interval>>& sublocs)
1462 // ----------------------------------------------------------------------------
1463 {
1464  _ASSERT(sublocs.size());
1465  if (sublocs.size() == 1) { // most common
1466  return false;
1467  }
1468 
1469  const auto& front = *sublocs.front();
1470  auto frontStrand = CWriteUtil::GetEffectiveStrand(front);
1471  auto lastStart = front.GetFrom();
1472  for (auto itComp = sublocs.begin()++; itComp != sublocs.end(); itComp++) {
1473  const auto& comp = **itComp;
1474  if (frontStrand != CWriteUtil::GetEffectiveStrand(comp)) {
1475  return true;
1476  }
1477  auto compStart = comp.GetFrom();
1478  if (frontStrand == eNa_strand_plus && lastStart > compStart) {
1479  return true;
1480  }
1481  if (frontStrand == eNa_strand_minus && lastStart < compStart) {
1482  return true;
1483  }
1484  lastStart = compStart;
1485  }
1486  return false;
1487 }
1488 
1489 
User-defined methods of the data storage class.
@ eExtreme_Positional
numerical value
Definition: Na_strand.hpp:63
User-defined methods of the data storage class.
#define false
Definition: bool.h:36
CAlign_CI –.
Definition: align_ci.hpp:63
CAnnot_CI –.
Definition: annot_ci.hpp:59
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
CCdregion –.
Definition: Cdregion.hpp:66
CFeat_CI –.
Definition: feat_ci.hpp:64
@Gb_qual.hpp User-defined methods of the data storage class.
Definition: Gb_qual.hpp:61
static CGenbankIdResolve & Get()
int GetId(void) const
virtual bool xAssignFeatureAttributeProduct(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:802
static bool IsTranscriptType(const CMappedFeat &)
bool xAssignFeatureAttributeIsOrdered(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
bool WriteAlign(const CSeq_align &, const string &asmblyName="", const string &asmblyAccession="") override
Write a Seq-align object.
Definition: gff_writer.cpp:311
virtual bool xAssignFeatureAttributeNote(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.hpp:267
virtual bool xAssignFeatureType(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:463
bool xAssignFeatureAttributeFunction(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
virtual bool xAssignFeatureAttributeProteinId(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:771
virtual bool xAssignFeatureAttributeDbxref(CGffFeatureRecord &, CGffFeatureContext &, const string &label, const CMappedFeat &)
Definition: gff_writer.cpp:613
bool xAssignFeatureAttributeMapLoc(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
virtual bool xAssignFeature(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:369
bool WriteFooter() override
Write a trailer marking the end of a parsing context.
Definition: gff_writer.cpp:346
bool m_bHeaderWritten
Definition: gff_writer.hpp:406
bool xAssignFeatureAttributeRptFamily(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
bool xAssignFeatureAttributeCodeBreak(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:908
bool WriteAnnot(const CSeq_annot &annot, const string &asmblyName="", const string &asmblyAccession="") override
Convenience function to render a "naked" Seq-annot.
Definition: gff_writer.cpp:91
static bool HasAccaptableTranscriptParent(CGffFeatureContext &, const CMappedFeat &)
virtual ~CGff2Writer()
Definition: gff_writer.cpp:85
virtual bool xAssignFeatureAttributePseudo(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:680
virtual bool x_WriteAssemblyInfo(const string &, const string &)
Definition: gff_writer.cpp:354
virtual bool xAssignFeatureStrand(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:474
virtual bool xWriteAllChildren(CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:226
virtual bool xAssignFeatureAttributesFormatIndependent(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:537
virtual bool x_WriteAnnot(const CSeq_annot &)
Definition: gff_writer.cpp:107
CGff2Writer(CScope &scope, CNcbiOstream &ostr, unsigned int flags=fNormal)
Constructor.
Definition: gff_writer.cpp:59
bool WriteBioseqHandle(CBioseq_Handle bsh, const string &asmblyName="", const string &asmblyAccession="") override
Write Bioseq contained in given handle Essentially, will write all features that live on the given Bi...
Definition: gff_writer.cpp:192
virtual bool x_WriteAlign(const CSeq_align &)
Definition: gff_writer.cpp:327
CRef< CScope > m_pScope
Definition: gff_writer.hpp:405
virtual bool xAssignFeatureAttributeRibosomalSlippage(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:752
bool xAssignFeatureAttributeGeneBiotype(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
virtual bool xGeneratingMissingTranscripts() const
Definition: gff_writer.hpp:386
virtual bool xWriteFeature(CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:290
bool xAssignFeatureAttributePseudoGene(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
virtual bool x_WriteSeqAnnotHandle(CSeq_annot_Handle)
Definition: gff_writer.cpp:262
bool xAssignFeatureAttributeEcNumbers(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
bool xAssignFeatureAttributesGoMarkup(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
virtual bool x_WriteSeqEntryHandle(CSeq_entry_Handle)
Definition: gff_writer.cpp:134
virtual bool xAssignFeatureSeqId(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:413
bool xAssignFeatureAttributeModelEvidence(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
virtual bool xAssignFeatureEndpoints(CGffFeatureRecord &record, CGffFeatureContext &, const CMappedFeat &mapped_feat)
Definition: gff_writer.cpp:498
virtual bool xAssignFeatureAttributePartial(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:699
bool WriteSeqAnnotHandle(CSeq_annot_Handle sah, const string &asmblyName="", const string &asmblyAccession="") override
Write Seq-annot contained in given handle Essentially, write out embedded feature table.
Definition: gff_writer.cpp:246
virtual bool xAssignFeatureMethod(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:487
virtual bool xAssignFeatureAttributesQualifiers(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.hpp:247
bool WriteHeader() override
Write a file header identifying the file content as GFF version 2.
Definition: gff_writer.cpp:335
virtual bool xAssignFeatureAttributes(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:524
virtual bool xAssignFeatureAttributesFormatSpecific(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:572
bool WriteSeqEntryHandle(CSeq_entry_Handle seh, const string &asmblyName="", const string &asmblyAccession="") override
Write Seq-entry contained in a given handle.
Definition: gff_writer.cpp:118
virtual bool xAssignFeatureAttributesGene(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:967
bool xAssignFeatureAttributeOldLocusTag(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:997
virtual bool xAssignFeatureAttributeTranslationTable(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:728
virtual bool x_WriteBioseqHandle(CBioseq_Handle)
Definition: gff_writer.cpp:208
bool xAssignFeatureAttributeExonNumber(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
bool xAssignFeatureAttributeExperiment(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
virtual bool x_WriteSequenceHeader(CBioseq_Handle)
Definition: gff_writer.hpp:352
virtual bool xAssignFeatureBasic(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:379
virtual bool xAssignFeatureScore(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:428
virtual bool xAssignFeaturePhase(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:453
static bool xIntervalsNeedPartNumbers(const list< CRef< CSeq_interval >> &)
CMappedFeat xGenerateMissingTranscript(CGffFeatureContext &, const CMappedFeat &)
bool xAssignFeatureAttributeException(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
void SetSeqId(const string &)
void SetLocation(unsigned int, unsigned int, ENa_strand=objects::eNa_strand_unknown)
void SetType(const string &)
void SetMethod(const string &)
void SetStrand(ENa_strand)
bool SetAttribute(const string &, const string &)
void SetScore(const CScore &)
bool SetAttributes(const string &, const vector< string > &)
bool AddAttribute(const string &, const string &)
feature::CFeatTree & FeatTree()
void SetGbKeyFrom(CMappedFeat)
void SetEndpoints(unsigned int start, unsigned int stop, ENa_strand strand)
CMappedFeat –.
Definition: mapped_feat.hpp:59
@RNA_ref.hpp User-defined methods of the data storage class.
Definition: RNA_ref.hpp:54
CScope –.
Definition: scope.hpp:92
bool IsLegalQualifier(EQualifier qual) const
Test wheather a certain qualifier is legal for the feature.
CSeq_annot_Handle –.
bool IsAlign(void) const
Definition: Seq_annot.cpp:182
CSeq_entry_CI –.
CSeq_entry_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
static bool IsTransspliced(const CSeq_feat &feature)
static bool GetTrnaAntiCodon(const CTrna_ext &, string &)
Definition: write_util.cpp:428
static bool GetStringsForGoMarkup(const vector< CRef< CUser_field > > &fields, vector< string > &goMarkup, bool relaxed=false)
static bool IsLocationOrdered(const CSeq_loc &)
Definition: write_util.cpp:569
static bool GetDbTag(const CDbtag &, string &)
Definition: write_util.cpp:461
static bool GetStringForModelEvidence(CMappedFeat mf, string &mestr)
Definition: write_util.cpp:889
static bool GetCodeBreak(const CCode_break &, string &)
Definition: write_util.cpp:266
static bool GetListOfGoIds(const vector< CRef< CUser_field > > &fields, list< std::string > &goIds, bool relaxed=false)
static ENa_strand GetEffectiveStrand(const CSeq_interval &)
static bool GetTranssplicedEndpoints(const CSeq_loc &loc, unsigned int &inPoint, unsigned int &outPoint)
static bool GetTrnaCodons(const CTrna_ext &, string &)
Definition: write_util.cpp:374
static bool GetTrnaProductName(const CTrna_ext &, string &)
Definition: write_util.cpp:404
Defines and provides stubs for a general interface to a variety of file formatters.
Definition: writer.hpp:81
virtual const CRange< TSeqPos > & GetRange(void) const
Definition: writer.hpp:262
virtual SAnnotSelector & SetAnnotSelector(void)
Definition: writer.hpp:246
CNcbiOstream & m_Os
Definition: writer.hpp:267
static const char location[]
Definition: config.c:97
static const struct name_t names[]
USING_SCOPE(objects)
static string s_GetDbxrefFromProduct(const CMappedFeat &mf)
Definition: gff_writer.cpp:582
const CGene_ref & sGetClosestGeneRef(CGffFeatureContext &fc, const CMappedFeat &mf)
Definition: gff_writer.cpp:949
const TResidue codons[4][4]
Definition: gnomon_seq.cpp:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
string
Definition: cgiapp.hpp:687
string GetSeqIdString(bool with_version=false) const
Return seqid string with optional version for text seqid type.
Definition: Seq_id.cpp:2144
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:573
ENa_strand GetStrand(void) const
Get the location's strand.
Definition: Seq_loc.cpp:882
TRange GetTotalRange(void) const
Definition: Seq_loc.hpp:913
TSeqPos GetStart(ESeqLocExtremes ext) const
Return start and stop positions of the seq-loc.
Definition: Seq_loc.cpp:915
const CSeq_id * GetId(void) const
Get the id of the location return NULL if has multiple ids or no id at all.
Definition: Seq_loc.hpp:941
TSeqPos GetStop(ESeqLocExtremes ext) const
Definition: Seq_loc.cpp:963
bool GetFeatureGeneBiotypeFaster(feature::CFeatTree &ft, CMappedFeat mf, string &biotype)
Definition: feature.cpp:4485
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
@ eGetId_ForceAcc
return only an accession based seq-id
Definition: sequence.hpp:100
@ eGetId_ForceGi
return only a gi-based seq-id
Definition: sequence.hpp:99
void RemoveSeq_annot(const CSeq_annot_Handle &annot)
Revoke Seq-annot previously added using AddSeq_annot().
Definition: scope.cpp:388
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
CSeq_annot_Handle AddSeq_annot(CSeq_annot &annot, TPriority pri=kPriority_Default, EExist action=eExist_Throw)
Add Seq-annot, return its CSeq_annot_Handle.
Definition: scope.cpp:538
CBioseq_Handle GetObjectHandle(const CBioseq &bioseq, EMissing action=eMissing_Default)
Definition: scope.hpp:726
const string & GetNamedQual(const CTempString &qual_name) const
Return a named qualifier.
bool IsSetExcept(void) const
bool GetExcept(void) const
bool GetPseudo(void) const
TClass GetClass(void) const
const CSeq_annot_Handle & GetAnnot(void) const
Get handle to seq-annot for this feature.
bool IsSetDbxref(void) const
const CSeqFeatData & GetData(void) const
TSet GetSet(void) const
const CProt_ref * GetProtXref(void) const
get protein (if present) from Seq-feat.xref list
bool IsSetExcept_text(void) const
CConstRef< CSeq_annot > GetCompleteSeq_annot(void) const
Complete and return const reference to the current seq-annot.
CSeq_feat_EditHandle AddFeat(const CSeq_feat &new_obj) const
bool IsSetProduct(void) const
TSeq GetSeq(void) const
const CUser_object & GetExt(void) const
const string & GetExcept_text(void) const
bool IsSetClass(void) const
CSeq_annot_EditHandle GetEditHandle(void) const
Get 'edit' version of handle.
CScope & GetScope(void) const
Get scope this handle belongs to.
bool IsSet(void) const
const CSeq_feat::TDbxref & GetDbxref(void) const
bool IsSetQual(void) const
CSeqFeatData::ESubtype GetFeatSubtype(void) const
CSeqFeatData::E_Choice GetFeatType(void) const
const CGene_ref * GetGeneXref(void) const
get gene (if present) from Seq-feat.xref list
bool IsSetPseudo(void) const
const CSeq_feat::TQual & GetQual(void) const
bool IsSetExt(void) const
bool IsSetData(void) const
bool IsSeq(void) const
CSeq_id_Handle GetProductId(void) const
bool IsSetPartial(void) const
const CSeq_loc & GetLocation(void) const
bool GetPartial(void) const
bool IsMapped(void) const
Fast way to check if mapped feature is different from the original one.
Definition: mapped_feat.hpp:75
const CSeq_loc & GetProduct(void) const
SAnnotSelector & SetMaxSize(TMaxSize max_size)
Set maximum number of annotations to find.
SAnnotSelector & SetSortOrder(ESortOrder sort_order)
Set sort order of annotations.
CConstRef< CSeq_feat > GetSeq_feat(void) const
Get current seq-feat.
CSeq_id_Handle GetLocationId(void) const
@ eSortOrder_Normal
default - increasing start, decreasing length
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool NotEmpty(void) const THROWS_NONE
Check if CRef is not empty – pointing to an object and has a non-null value.
Definition: ncbiobj.hpp:726
bool NotEmpty(void) const
Definition: range.hpp:152
TThisType IntersectionWith(const TThisType &r) const
Definition: range.hpp:312
bool IsWhole(void) const
Definition: range.hpp:284
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NPOS
Definition: ncbistr.hpp:133
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static const char label[]
TTo GetTo(void) const
Get the To member data.
Definition: Range_.hpp:269
TFrom GetFrom(void) const
Get the From member data.
Definition: Range_.hpp:222
bool IsSetMaploc(void) const
descriptive map location Check if a value has been assigned to Maploc data member.
Definition: Gene_ref_.hpp:634
const TMaploc & GetMaploc(void) const
Get the Maploc member data.
Definition: Gene_ref_.hpp:646
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
const TData & GetData(void) const
Get the Data member data.
const TFields & GetFields(void) const
Get the variant data.
bool IsFields(void) const
Check if variant Fields is selected.
bool IsSetLabel(void) const
field label Check if a value has been assigned to Label data member.
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
const TData & GetData(void) const
Get the Data member data.
const TLabel & GetLabel(void) const
Get the Label member data.
bool IsSetData(void) const
Check if a value has been assigned to Data data member.
vector< CRef< CUser_field > > TData
const TName & GetName(void) const
Get the Name member data.
Definition: Prot_ref_.hpp:378
bool IsSetName(void) const
protein name Check if a value has been assigned to Name data member.
Definition: Prot_ref_.hpp:366
const TVal & GetVal(void) const
Get the Val member data.
Definition: Gb_qual_.hpp:259
void ResetPartial(void)
Reset Partial data member.
Definition: Seq_feat_.hpp:955
E_Choice Which(void) const
Which variant is currently selected.
bool IsSetCode(void) const
genetic code used Check if a value has been assigned to Code data member.
Definition: Cdregion_.hpp:700
void SetLocation(TLocation &value)
Assign a value to Location data member.
Definition: Seq_feat_.cpp:131
bool IsCdregion(void) const
Check if variant Cdregion is selected.
bool IsSetPartial(void) const
incomplete in some way? Check if a value has been assigned to Partial data member.
Definition: Seq_feat_.hpp:943
E_Choice
Choice variants.
void SetExcept(TExcept value)
Assign a value to Except data member.
Definition: Seq_feat_.hpp:1018
bool IsGene(void) const
Check if variant Gene is selected.
const TCode & GetCode(void) const
Get the Code member data.
Definition: Cdregion_.hpp:712
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
const TCdregion & GetCdregion(void) const
Get the variant data.
bool IsSetQual(void) const
Check if a value has been assigned to Qual data member.
Definition: Gb_qual_.hpp:200
const TGene & GetGene(void) const
Get the variant data.
TPartial GetPartial(void) const
Get the Partial member data.
Definition: Seq_feat_.hpp:962
void SetExcept_text(const TExcept_text &value)
Assign a value to Except_text data member.
Definition: Seq_feat_.hpp:1414
const TProt & GetProt(void) const
Get the variant data.
vector< CRef< CGb_qual > > TQual
Definition: Seq_feat_.hpp:117
const TQual & GetQual(void) const
Get the Qual member data.
Definition: Gb_qual_.hpp:212
const TRna & GetRna(void) const
Get the variant data.
const TCode_break & GetCode_break(void) const
Get the Code_break member data.
Definition: Cdregion_.hpp:733
bool IsSetCode_break(void) const
individual exceptions Check if a value has been assigned to Code_break data member.
Definition: Cdregion_.hpp:721
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
@ eClass_genbank
converted genbank
constexpr auto front(list< Head, As... >, T=T()) noexcept -> Head
constexpr bool empty(list< Ts... >) noexcept
#define fc
CConstRef< CSeq_id > GetBestId(const CBioseq &bioseq)
SAnnotSelector –.
Definition: type.c:6
#define _ASSERT
Modified on Wed Mar 27 11:21:57 2024 by modify_doxy.py rev. 669887