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

Go to the SVN repository for this file.

1 /* $Id: showdefline.cpp 100359 2023-07-24 17:46:35Z vasilche $
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  * Author: Jian Ye
27  *
28  * File Description:
29  * Display blast defline
30  *
31  */
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbiexpt.hpp>
34 #include <corelib/ncbiutil.hpp>
35 #include <corelib/ncbistre.hpp>
36 #include <corelib/ncbireg.hpp>
37 
39 #include <objmgr/scope.hpp>
40 #include <objmgr/util/sequence.hpp>
41 #include <objects/seq/Bioseq.hpp>
43 #include <objects/seq/Seqdesc.hpp>
45 
54 
57 
58 
59 #include <stdio.h>
60 #include <html/htmlhelper.hpp>
61 
62 
65 USING_SCOPE(sequence);
66 BEGIN_SCOPE(align_format)
67 
68 //margins constant
69 
70 static string kOneSpaceMargin = " ";
71 static string kTwoSpaceMargin = " ";
72 
73 //const strings
74 static const string kHeader = "Sequences producing significant alignments:";
75 static const string kScore = "Score";
76 static const string kE = "E";
77 static const string kBits =
78  (getenv("CTOOLKIT_COMPATIBLE") ? "(bits)" : "(Bits)");
79 static const string kEvalue = "E value";
80 static const string kValue = "Value";
81 static const string kN = "N";
82 static const string kRepeatHeader = "Sequences used in model and found again:";
83 static const string kNewSeqHeader = "Sequences not found previously or not pr\
84 eviously below threshold:";
85 static const string kMaxScore = "Max score";
86 static const string kTotalScore = "Total score";
87 static const string kTotal = "Total";
88 static const string kIdentity = "Max ident";
89 static const string kPercent = "Percent";
90 static const string kHighest = "Highest";
91 static const string kQuery = "Query";
92 static const string kCoverage = "Query coverage";
93 static const string kEllipsis = "...";
94 
95 static const string kMax = "Max";
96 static const string kIdentLine2 = "Ident";
97 static const string kScoreLine2 = "Score";
98 static const string kQueryCov = "Query";
99 static const string kQueryCovLine2 = "cover";
100 static const string kPerc = "Per.";
101 static const string kAccession = "Accession";
102 static const string kDescription = "Description";
103 static const string kScientific = "Scientific";
104 static const string kCommon = "Common";
105 static const string kName = "Name";
106 static const string kAccAbbr = "Acc.";
108 static const string kTaxid = "Taxid";
109 static const string kClusterTitle = "Cluster Rep.";
110 static const string kCluster = "Cluster";
111 static const string kAncestor = "Ancestor";
112 static const string kMember = "Mem.";
113 static const string kTaxa = "Taxa";
114 static const string kNumOf = "#";
115 
116 
117 //psiblast related
118 static const string kPsiblastNewSeqGif = "<IMG SRC=\"images/new.gif\" \
119 WIDTH=30 HEIGHT=15 ALT=\"New sequence mark\">";
120 
121 static const string kPsiblastNewSeqBackgroundGif = "<IMG SRC=\"images/\
122 bg.gif\" WIDTH=30 HEIGHT=15 ALT=\" \">";
123 
124 static const string kPsiblastCheckedBackgroundGif = "<IMG SRC=\"images\
125 /bg.gif\" WIDTH=15 HEIGHT=15 ALT=\" \">";
126 
127 static const string kPsiblastCheckedGif = "<IMG SRC=\"images/checked.g\
128 if\" WIDTH=15 HEIGHT=15 ALT=\"Checked mark\">";
129 
130 static const string kPsiblastEvalueLink = "<a name = Evalue></a>";
131 
132 static const string kPsiblastCheckboxChecked = "<INPUT TYPE=\"checkbox\" NAME\
133 =\"checked_GI\" VALUE=\"%" NCBI_INT8_FORMAT_SPEC "\" CHECKED> <INPUT TYPE=\"hidden\" NAME =\"good_G\
134 I\" VALUE = \"%" NCBI_INT8_FORMAT_SPEC "\">";
135 
136 static const string kPsiblastCheckbox = "<INPUT TYPE=\"checkbox\" NAME=\"ch\
137 ecked_GI\" VALUE=\"%" NCBI_INT8_FORMAT_SPEC "\"> ";
138 
139 //Max length of title string for the the link
140 static const int kMaxDescrLength = 4096;
141 
142 static const int kMaxPercentIdentityLen = kIdentLine2.size() + 1;
143 static const int kMaxAccLength = 16;
144 static const int kMaxTaxonomyNameLength = 15;
145 static const int kMaxTaxonomyNameLengthExt = 30;
146 static const int kMaxDispNumberLength = 10;
147 
148 
149 
150 string
152  bool show_gi)
153 {
154  string id_string = NcbiEmptyString;
155  bool found_gi = false;
156 
158 
159  if (show_gi) {
160  ITERATE(list<CRef<CSeq_id> >, itr, id) {
161  if ((*itr)->IsGi()) {
162  id_string += (*itr)->AsFastaString();
163  found_gi = true;
164  break;
165  }
166  }
167  }
168 
169  if (best_id.NotEmpty() && !best_id->IsGi() ) {
170  if (found_gi)
171  id_string += "|";
172 
173  if (best_id->IsLocal()) {
174  string id_token;
175  best_id->GetLabel(&id_token, CSeq_id::eContent, 0);
176  id_string += id_token;
177  }
178  else
179  id_string += best_id->AsFastaString();
180  }
181 
182  return id_string;
183 }
184 
185 void
186 CShowBlastDefline::GetSeqIdList(const objects::CBioseq_Handle& bh,
187  list<CRef<objects::CSeq_id> >& ids)
188 {
189  ids.clear();
190 
191 
192  vector< CConstRef<CSeq_id> > original_seqids;
193 
194  ITERATE(CBioseq_Handle::TId, itr, bh.GetId()) {
195  original_seqids.push_back(itr->GetSeqId());
196  }
197 
198  // Check for ids of type "gnl|BL_ORD_ID". These are the artificial ids
199  // created in a BLAST database when it is formatted without indexing.
200  // For such ids, create new fake local Seq-ids, saving the first token of
201  // the Bioseq's title, if it's available.
202  GetSeqIdList(bh,original_seqids,ids);
203 }
204 
205 
206 
207 void
208 CShowBlastDefline::GetSeqIdList(const objects::CBioseq_Handle& bh,
209  vector< CConstRef<CSeq_id> > &original_seqids,
210  list<CRef<objects::CSeq_id> >& ids)
211 {
212  ids.clear();
213  ITERATE(vector< CConstRef<CSeq_id> >, itr, original_seqids) {
214  CRef<CSeq_id> next_seqid(new CSeq_id());
215  string id_token = NcbiEmptyString;
216 
217  if (((*itr)->IsGeneral() &&
218  (*itr)->AsFastaString().find("gnl|BL_ORD_ID")
219  != string::npos) ||
220  (*itr)->AsFastaString().find("lcl|Subject_") != string::npos) {
221  vector<string> title_tokens;
222  string defline = sequence::CDeflineGenerator().GenerateDefline(bh);
223  if (defline != NcbiEmptyString) {
224  id_token =
225  NStr::Split(defline, " ", title_tokens)[0];
226  }
227  }
228  if (id_token != NcbiEmptyString) {
229  // Create a new local id with a label containing the extracted
230  // token and save it in the next_seqid instead of the original
231  // id.
232  CObject_id* obj_id = new CObject_id();
233  obj_id->SetStr(id_token);
234  next_seqid->SetLocal(*obj_id);
235  } else {
236  next_seqid->Assign(**itr);
237  }
238  ids.push_back(next_seqid);
239  }
240 }
241 
242 void
244  list<TGi>& use_this_gi,
245  string& seqid, string& defline,
246  bool show_gi /* = true */,
247  TGi this_gi_first /* = -1 */)
248 {
249  // Retrieve the CBlast_def_line_set object and save in a CRef, preventing
250  // its destruction; then extract the list of CBlast_def_line objects.
251  if( !handle ) return; // No bioseq for this handle ( deleted accession ? )
254 
255  if(bdlRef.Empty()){
256  list<CRef<objects::CSeq_id> > ids;
257  GetSeqIdList(handle, ids);
258  seqid = GetSeqIdListString(ids, show_gi);
259  defline = sequence::CDeflineGenerator().GenerateDefline(handle);
260  } else {
261  bdlRef->PutTargetGiFirst(this_gi_first);
262  const list< CRef< CBlast_def_line > >& bdl = bdlRef->Get();
263  bool is_first = true;
264  ITERATE(list<CRef<CBlast_def_line> >, iter, bdl) {
265  const CBioseq::TId& cur_id = (*iter)->GetSeqid();
266  TGi cur_gi = FindGi(cur_id);
267  TGi gi_in_use_this_gi = ZERO_GI;
268  ITERATE(list<TGi>, iter_gi, use_this_gi){
269  if(cur_gi == *iter_gi){
270  gi_in_use_this_gi = *iter_gi;
271  break;
272  }
273  }
274  if(use_this_gi.empty() || gi_in_use_this_gi > ZERO_GI) {
275  if (is_first)
276  seqid = GetSeqIdListString(cur_id, show_gi);
277 
278  if((*iter)->IsSetTitle()){
279  if(is_first){
280  defline = (*iter)->GetTitle();
281  } else {
282  string concat_acc;
283  CConstRef<CSeq_id> wid =
285  wid->GetLabel(&concat_acc, CSeq_id::eFasta, 0);
286  if( show_gi && cur_gi > ZERO_GI){
287  defline = defline + " >" + "gi|" +
288  NStr::NumericToString(cur_gi) + "|" +
289  concat_acc + " " + (*iter)->GetTitle();
290  } else {
291  defline = defline + " >" + concat_acc + " " +
292  (*iter)->GetTitle();
293  }
294  }
295  is_first = false;
296  }
297  }
298  }
299  }
300 }
301 
302 static void s_LimitDescrLength(string &descr, size_t maxDescrLength = kMaxDescrLength)
303 {
304  if(descr.length() > maxDescrLength) {
305  descr = descr.substr(0,maxDescrLength);
306  size_t end = NStr::Find(descr," ",NStr::eNocase,NStr::eReverseSearch);
307 
308  if(end != NPOS) {
309  descr = descr.substr(0,end);
310  descr += "...";
311  }
312  }
313 
314 }
315 
317  CBioseq::TId& cur_id,
318  int blast_rank,
319  bool getIdentProteins)
320 {
321 
322  bool is_mixed_database = (m_IsDbNa == true && m_Ctx)? CAlignFormatUtil::IsMixedDatabase(*m_Ctx): false;
323  if (m_DeflineTemplates && m_DeflineTemplates->advancedView && !is_mixed_database) return;
324 
325 
326  string linkout_list;
327 
329  &m_LinkoutDB,
331  sdl->gi);
332  if(!m_LinkoutDB) {
333  m_Option &= ~eLinkout;
334  return;
335  }
336 
337 
338  if(m_LinkoutOrder.empty()) {
339  m_ConfigFile.reset(new CNcbiIfstream(".ncbirc"));
340  m_Reg.reset(new CNcbiRegistry(*m_ConfigFile));
341  if(!m_BlastType.empty()) m_LinkoutOrder = m_Reg->Get(m_BlastType,"LINKOUT_ORDER");
343  }
346  string user_url = m_Reg.get() ? m_Reg->Get(m_BlastType, "TOOL_URL") : kEmptyStr;
348  m_Rid,
349  m_CddRid,
350  m_EntrezTerm,
351  m_IsDbNa,
352  false,
353  true,
354  blast_rank,
356  sdl->taxid,
357  m_Database,
359  user_url,
361  m_LinkoutDB,
363  getIdentProteins);
364  }
365  else {
367  cur_id,
368  m_Rid,
369  m_CddRid,
370  m_EntrezTerm,
371  m_IsDbNa,
372  ZERO_GI,
373  true,
374  false,
375  blast_rank,
377  }
378  }
379 }
380 
381 
383  const CSeq_id& aln_id,
384  list<string> &use_this_seqid,
385  SDeflineInfo* sdl,
386  int blast_rank)
387 {
388  if( !handle ) return; // invalid handle.
389 
391  const list< CRef< CBlast_def_line > > &bdl = (bdlRef.Empty()) ? list< CRef< CBlast_def_line > >() : bdlRef->Get();
392 
393  CRef<CSeq_id> wid;
394  sdl->defline = NcbiEmptyString;
395 
396  sdl->gi = ZERO_GI;
397  sdl->id_url = NcbiEmptyString;
398  sdl->score_url = NcbiEmptyString;
399  sdl->linkout = 0;
400  sdl->is_new = false;
401  sdl->was_checked = false;
402  sdl->taxid = ZERO_TAX_ID;
403  sdl->clustAncTaxid = ZERO_TAX_ID;
404  //get psiblast stuff
405 
406  if(m_SeqStatus){
407  string aln_id_str;
408  aln_id.GetLabel(&aln_id_str, CSeq_id::eContent);
409  PsiblastSeqStatus seq_status = eUnknown;
410 
412  if ( itr != m_SeqStatus->end() ){
413  seq_status = itr->second;
414  }
415  if((m_PsiblastStatus == eFirstPass) ||
416  ((m_PsiblastStatus == eRepeatPass) && (seq_status & eRepeatSeq))
417  || ((m_PsiblastStatus == eNewPass) && (seq_status & eRepeatSeq))){
418  if(!(seq_status & eGoodSeq)){
419  sdl->is_new = true;
420  }
421  if(seq_status & eCheckedSeq){
422  sdl->was_checked = true;
423  }
424  }
425  }
426  //get id (sdl->id, sdl-gi)
427  sdl->id = CAlignFormatUtil::GetDisplayIds(handle,aln_id,use_this_seqid,&sdl->gi,&sdl->taxid,&sdl->textSeqID);
428  sdl->alnIDFasta = aln_id.AsFastaString();
429 
430  //get linkout****
431  if((m_Option & eLinkout)){
432  bool getIdentProteins = !m_IsDbNa && bdl.size() > 1;
433  for(list< CRef< CBlast_def_line > >::const_iterator iter = bdl.begin();
434  iter != bdl.end(); iter++){
435  CBioseq::TId& cur_id = (CBioseq::TId &)(*iter)->GetSeqid();
436  TGi cur_gi = FindGi(cur_id);
437  bool match = false;
438  if(!use_this_seqid.empty()){
439  wid = FindBestChoice(cur_id, CSeq_id::WorstRank);
440  match = CAlignFormatUtil::MatchSeqInSeqList(cur_gi, wid, use_this_seqid);
441  }
442  if((use_this_seqid.empty() && sdl->gi == cur_gi) || match) {
443  x_InitLinkOutInfo(sdl,cur_id,blast_rank,getIdentProteins); //only initialized if !(m_DeflineTemplates->advancedView && !is_mixed_database)
444  break;
445  }
446  }
447  //The following is the case when for whatever reason the seq is not found in Blast database (bdl list is empty) and is retrived from genbank
448  if(bdl.size() == 0) {
449  CBioseq::TId& cur_id = (CBioseq::TId &) handle.GetBioseqCore()->GetId();
450  x_InitLinkOutInfo(sdl,cur_id,blast_rank,getIdentProteins); //only initialized if !(m_DeflineTemplates->advancedView && !is_mixed_database)
451  }
452  }
453 
454  //get score and id url
455  if(m_Option & (eHtml | eShowCSVDescr)){
456  bool useTemplates = m_DeflineTemplates != NULL;
457  bool advancedView = (m_DeflineTemplates != NULL) ? m_DeflineTemplates->advancedView : false;
458  string accession;
459  sdl->id->GetLabel(&accession, CSeq_id::eContent);
460  sdl->score_url = !useTemplates ? "<a href=#" : "";
461  if (!useTemplates && m_PositionIndex >= 0) {
462  sdl->score_url += "_" + NStr::IntToString(m_PositionIndex) + "_";
463  }
464  sdl->score_url += sdl->gi == ZERO_GI ? accession :
466  sdl->score_url += !useTemplates ? ">" : "";
467 
468  string user_url = m_Reg.get() ? m_Reg->Get(m_BlastType, "TOOL_URL") : kEmptyStr;
469  //blast_rank = num_align + 1
470  CRange<TSeqPos> seqRange = ((int)m_ScoreList.size() >= blast_rank)? m_ScoreList[blast_rank - 1]->subjRange : CRange<TSeqPos>(0,0);
471  bool flip = ((int)m_ScoreList.size() >= blast_rank) ? m_ScoreList[blast_rank - 1]->flip : false;
473  m_QueryNumber,sdl->gi, accession, 0, //linkout = 0, not used any more
474  blast_rank,false,(m_Option & eNewTargetWindow) ? true : false,seqRange,flip);
475  seqUrlInfo.resourcesUrl = m_Reg.get() ? m_Reg->Get(m_BlastType, "RESOURCE_URL") : kEmptyStr;
476  seqUrlInfo.useTemplates = useTemplates;
477  seqUrlInfo.advancedView = advancedView;
478 
479  if(sdl->id->Which() == CSeq_id::e_Local && (m_Option & eHtml)){
480  //get taxid info for local blast db such as igblast db
481  ITERATE(list<CRef<CBlast_def_line> >, iter_bdl, bdl) {
482  if ((*iter_bdl)->IsSetTaxid() && (*iter_bdl)->CanGetTaxid()){
483  seqUrlInfo.taxid = (*iter_bdl)->GetTaxid();
484  break;
485  }
486  }
487  }
488  sdl->id_url = CAlignFormatUtil::GetIDUrl(&seqUrlInfo,aln_id,*m_ScopeRef);
489  }
490 
491  //get defline
492  sdl->defline = CDeflineGenerator().GenerateDefline(m_ScopeRef->GetBioseqHandle(*(sdl->id)));
493  sdl->fullDefline = sdl->defline;
494  if (!(bdl.empty())) {
495  for(list< CRef< CBlast_def_line > >::const_iterator iter = bdl.begin();
496  iter != bdl.end(); iter++){
497  const CBioseq::TId& cur_id = (*iter)->GetSeqid();
498  TGi cur_gi = FindGi(cur_id);
499  wid = FindBestChoice(cur_id, CSeq_id::WorstRank);
500  bool match = CAlignFormatUtil::MatchSeqInSeqList(cur_gi, wid, use_this_seqid);
501  if(use_this_seqid.empty() || match) {
502 
503  if((*iter)->IsSetTitle()){
504  bool id_used_already = false;
505  ITERATE(CBioseq::TId, iter_id, cur_id) {
506  if ((*iter_id)->Match(*(sdl->id))) {
507  id_used_already = true;
508  break;
509  }
510  }
511  if (!id_used_already) {
512  string concat_acc;
513  wid = FindBestChoice(cur_id, CSeq_id::WorstRank);
514  wid->GetLabel(&concat_acc, CSeq_id::eFasta, 0);
515  if( (m_Option & eShowGi) && cur_gi > ZERO_GI){
516  sdl->fullDefline = sdl->fullDefline + " >" + "gi|" +
517  NStr::NumericToString(cur_gi) + "|" +
518  concat_acc + " " + (*iter)->GetTitle();
519  } else {
520  sdl->fullDefline = sdl->fullDefline + " >" + concat_acc +
521  " " +
522  (*iter)->GetTitle();
523  }
524  if(sdl->fullDefline.length() > kMaxDescrLength) {
525  break;
526  }
527  }
528  }
529  }
530  }
531  }
532 }
533 
534 //Constructor
536  CScope& scope,
537  size_t line_length,
538  size_t num_defline_to_show,
539  bool translated_nuc_alignment,
540  CRange<TSeqPos>* master_range):
541 
542  m_AlnSetRef(&seqalign),
543  m_ScopeRef(&scope),
544  m_LineLen(line_length),
545  m_NumToShow(num_defline_to_show),
546  m_TranslatedNucAlignment(translated_nuc_alignment),
547  m_SkipFrom(-1),
548  m_SkipTo(-1),
549  m_MasterRange(master_range),
550  m_LinkoutDB(NULL)
551 {
552 
553  m_Option = 0;
555  m_QueryNumber = 0;
558  m_IsDbNa = true;
561  m_SeqStatus = NULL;
562  m_Ctx = NULL;
563  m_StructureLinkout = false;
564  if(m_MasterRange) {
567  }
568  }
570  m_StartIndex = 0;
571  m_PositionIndex = -1;
572  m_AppLogInfo = NULL;
573 }
574 
576 {
577  ITERATE(vector<SScoreInfo*>, iter, m_ScoreList){
578  delete *iter;
579  }
580 
581  ITERATE(vector<SDeflineFormattingInfo*>, iter, m_SdlFormatInfoVec){
582  delete *iter;
583  }
584 
585 }
586 
587 
589 {
590  if (m_DeflineTemplates != NULL) {
592  }
593  else {
594  x_InitDefline();
595  }
596 }
597 
598 
600 {
601  if (m_DeflineTemplates != NULL) {
602  if(m_Option & eHtml) {//text
604  }
605  else if(m_Option & eShowCSVDescr) {
607  }
608  else {//text
610  }
611  }
612  else {
614  }
615 }
616 
618 {
619  bool struct_linkout = false;
620  int count = 0;
621  const int k_CountMax = 200; // Max sequences to check.
622 
623  ITERATE(vector<SScoreInfo*>, iter, m_ScoreList) {
624  const CBioseq_Handle& handle = m_ScopeRef->GetBioseqHandle(*(*iter)->id);
625  if( !handle ) continue; // invalid handle.
627  const list< CRef< CBlast_def_line > > &bdl = (bdlRef.Empty()) ? list< CRef< CBlast_def_line > >() : bdlRef->Get();
628  for(list< CRef< CBlast_def_line > >::const_iterator bdl_iter = bdl.begin();
629  bdl_iter != bdl.end() && struct_linkout == false; bdl_iter++){
630  if ((*bdl_iter)->IsSetLinks())
631  {
632  for (list< int >::const_iterator link_iter = (*bdl_iter)->GetLinks().begin();
633  link_iter != (*bdl_iter)->GetLinks().end(); link_iter++)
634  {
635  if (*link_iter & eStructure) {
636  struct_linkout = true;
637  break;
638  }
639  }
640  }
641  }
642  if (struct_linkout == true || count > k_CountMax)
643  break;
644  count++;
645  }
646  return struct_linkout;
647 }
648 
649 //size_t max_score_len = kBits.size(), max_evalue_len = kValue.size();
650 //size_t max_sum_n_len =1;
651 //size_t m_MaxScoreLen , m_MaxEvalueLen,m_MaxSumNLen;
652 //bool m_StructureLinkout
654 {
655  /*Note we can't just show each alnment as we go because we will
656  need to show defline only once for all hsp's with the same id*/
657 
658  bool is_first_aln = true;
659  size_t num_align = 0;
660  CConstRef<CSeq_id> previous_id, subid;
661 
662  m_MaxScoreLen = kBits.size();
663  m_MaxEvalueLen = kValue.size();
664  m_MaxSumNLen =1;
665 
667  m_MaxQueryCoverLen = kCoverage.size();
668  m_MaxTotalScoreLen = kTotal.size();
669 
670 
671 
672  if(m_Option & eHtml){
673  m_ConfigFile.reset(new CNcbiIfstream(".ncbirc"));
674  m_Reg.reset(new CNcbiRegistry(*m_ConfigFile));
675  }
676  bool master_is_na = false;
677  //prepare defline
678 
679  int ialn = 0;
680  for (CSeq_align_set::Tdata::const_iterator
681  iter = m_AlnSetRef->Get().begin();
682  iter != m_AlnSetRef->Get().end() && num_align < m_NumToShow;
683  iter++, ialn++){
684  if (ialn < m_SkipTo && ialn >= m_SkipFrom) continue;
685 
686  if (is_first_aln) {
688  CBioseq_Handle bh = m_ScopeRef->GetBioseqHandle((*iter)->GetSeq_id(0));
689  _ASSERT(bh);
690  master_is_na = bh.GetBioseqCore()->IsNa();
691  }
692  subid = &((*iter)->GetSeq_id(1));
693  if(is_first_aln || (!is_first_aln && !subid->Match(*previous_id))) {
694  SScoreInfo* sci = x_GetScoreInfo(**iter, static_cast<int>(num_align));
695  if(sci){
696  m_ScoreList.push_back(sci);
697  if(m_MaxScoreLen < sci->bit_string.size()){
698  m_MaxScoreLen = sci->bit_string.size();
699  }
700  if(m_MaxEvalueLen < sci->evalue_string.size()){
701  m_MaxEvalueLen = sci->evalue_string.size();
702  }
703 
704  if(m_MaxTotalScoreLen < sci->total_bit_string.size()){
705  m_MaxTotalScoreLen = sci->total_bit_string.size();
706  }
707  int percent_identity = CAlignFormatUtil::GetPercentMatch(sci->match,sci->align_length);
708  if(m_MaxPercentIdentityLen < NStr::IntToString(percent_identity).size()) {
709  m_MaxPercentIdentityLen = NStr::IntToString(percent_identity).size();
710  }
711 
712  if( m_MaxSumNLen < NStr::IntToString(sci->sum_n).size()){
713  m_MaxSumNLen = NStr::IntToString(sci->sum_n).size();
714  }
715  }
716  num_align++;
717  }
718  is_first_aln = false;
719  previous_id = subid;
720 
721  }
722 
723 
724  if((m_Option & eLinkout) && (m_Option & eHtml) && !m_IsDbNa && !master_is_na)
726 }
727 
728 
730 {
731  char buf[256];
732  snprintf(buf, sizeof(buf), kPsiblastCheckboxChecked.c_str(), GI_TO(Int8, gi), GI_TO(Int8, gi));
733  buf[sizeof(buf)-1] = '\0';
734  out << buf;
735 }
736 
737 
739 {
740  char buf[256];
741  snprintf(buf, sizeof(buf), kPsiblastCheckbox.c_str(), GI_TO(Int8, gi));
742  buf[sizeof(buf)-1] = '\0';
743  out << buf;
744 }
745 
746 
748 {
749  bool use_long_seqids = (m_Option & eLongSeqId) != 0;
750 
751  if(!(m_Option & eNoShowHeader)) {
752  if((m_PsiblastStatus == eFirstPass) ||
755  if(m_Option & eHtml){
756  if((m_Option & eShowNewSeqGif)){
759  }
760  if (m_Option & eCheckbox) {
763  }
764  }
765  out << kScore;
768 
769 
770  if (m_Option & eShowTotalScore) {
771  out << kTotal;
774  }
776  out << kQueryCov;
778  }
779 
780  CAlignFormatUtil::AddSpace(out, 2); //E align to l of value
781  out << kE;
782 
783  if (m_Option & eShowPercentIdent) {
788  out << kMax;//"Max" - "ident" -second line
789  }
790 
791  out << "\n";
792  out << kHeader;
793  if(m_Option & eHtml){
794  if((m_Option & eShowNewSeqGif)){
797  }
798  if (m_Option & eCheckbox) {
801  }
802  }
805  out << kBits;
806  //in case m_MaxScoreLen > kBits.size()
809 
810 
811  if (m_Option & eShowTotalScore) {
813  out << kScoreLine2;//"score"
816  }
818  out << kQueryCovLine2;//"cov"
821  }
822 
823  out << kValue;
827  }
828  if(m_Option & eShowSumN){
829  out << kN;
830  }
831  if (m_Option & eShowPercentIdent) {
832  out << kIdentLine2;//"ident"
833  }
834  out << "\n";
835  }
837  out << kRepeatHeader << "\n";
838  }
839  if(m_PsiblastStatus == eNewPass){
840  out << kNewSeqHeader << "\n";
841  }
842  out << "\n";
843  }
844 
845  bool first_new =true;
846  ITERATE(vector<SScoreInfo*>, iter, m_ScoreList){
847  SDeflineInfo* sdl = x_GetDeflineInfo((*iter)->id, (*iter)->use_this_seqid, (*iter)->blast_rank);
848  size_t line_length = 0;
849  string line_component;
850  if ((m_Option & eHtml) && (sdl->gi > ZERO_GI)){
851  if((m_Option & eShowNewSeqGif)) {
852  if (sdl->is_new) {
853  if (first_new) {
854  first_new = false;
856  }
858 
859  } else {
861  }
862  if (sdl->was_checked) {
864 
865  } else {
867  }
868  }
869  if((m_Option & eCheckboxChecked)){
871  } else if (m_Option & eCheckbox) {
872  s_DisplayCheckbox(out, sdl->gi);
873  }
874  }
875 
876 
877  if((m_Option & eHtml) && (sdl->id_url != NcbiEmptyString)) {
878  out << sdl->id_url;
879  }
880  if(m_Option & eShowGi){
881  if(sdl->gi > ZERO_GI){
882  line_component = "gi|" + NStr::NumericToString(sdl->gi) + "|";
883  out << line_component;
884  line_length += line_component.size();
885  }
886  }
887  if(!sdl->id.Empty()){
888  if(!(sdl->id->AsFastaString().find("gnl|BL_ORD_ID") != string::npos ||
889  sdl->id->AsFastaString().find("lcl|Subject_") != string::npos)){
890  string idStr;
891  if (use_long_seqids || ((m_Option & eShowGi) && !sdl->id->IsGi())) {
892  idStr = sdl->id->AsFastaString();
893  }
894  else {
895  idStr = CAlignFormatUtil::GetBareId(*sdl->id) + " ";
896  }
897  if (strncmp(idStr.c_str(), "lcl|", 4) == 0) {
898  idStr = sdl->id->AsFastaString().substr(4);
899  }
900  out << idStr;
901  line_length += idStr.size();
902  }
903  }
904  if((m_Option & eHtml) && (sdl->id_url != NcbiEmptyString)) {
905  out << "</a>";
906  }
907  line_component = (line_component.empty() ? "" : " ") + sdl->defline;
908  string actual_line_component;
909  if(line_component.size()+line_length > m_LineLen){
910  actual_line_component = line_component.substr(0, m_LineLen -
911  line_length - 3);
912  actual_line_component += kEllipsis;
913  } else {
914  actual_line_component = line_component.substr(0, m_LineLen -
915  line_length);
916  }
917  if (m_Option & eHtml) {
918  out << CHTMLHelper::HTMLEncode(actual_line_component);
919  } else {
920  out << actual_line_component;
921  }
922  line_length += actual_line_component.size();
923  //pad the short lines
924  CAlignFormatUtil::AddSpace(out, m_LineLen - line_length);
925  out << kTwoSpaceMargin;
926 
927  if((m_Option & eHtml) && (sdl->score_url != NcbiEmptyString)) {
928  out << sdl->score_url;
929  }
930  out << (*iter)->bit_string;
931  if((m_Option & eHtml) && (sdl->score_url != NcbiEmptyString)) {
932  out << "</a>";
933  }
934  CAlignFormatUtil::AddSpace(out, m_MaxScoreLen - (*iter)->bit_string.size());
935  if (m_Option & eShowTotalScore) {
936  out << kTwoSpaceMargin << kOneSpaceMargin << (*iter)->total_bit_string;
938  (*iter)->total_bit_string.size());
939  }
940 
941  if (m_Option & eShowQueryCoverage) {
942  //int percent_coverage = 100*(*iter)->master_covered_length/m_QueryLength;
943  int percent_coverage = (*iter)->percent_coverage;
944 
945  out << kTwoSpaceMargin << percent_coverage << "%";
946  //minus one due to % sign
948  NStr::IntToString(percent_coverage).size() - 1);
949  }
950 
951 
952  out << kTwoSpaceMargin << (*iter)->evalue_string;
953  CAlignFormatUtil::AddSpace(out, m_MaxEvalueLen - (*iter)->evalue_string.size());
954 
955  if(m_Option & eShowSumN){
956  out << kTwoSpaceMargin << (*iter)->sum_n;
958  NStr::IntToString((*iter)->sum_n).size());
959  }
961  int percent_identity =(int) (0.5 + (*iter)->percent_identity);
962  if(percent_identity > 100) {
963  percent_identity = min(99, percent_identity);
964  }
965  out << kTwoSpaceMargin << percent_identity <<"%";
967  NStr::IntToString(percent_identity).size());
968  }
969  if((m_Option & eLinkout) && (m_Option & eHtml)){
970  bool is_first = true;
971  ITERATE(list<string>, iter_linkout, sdl->linkout_list){
972  if(is_first){
973  out << kOneSpaceMargin;
974  is_first = false;
975  }
976  out << *iter_linkout;
977  }
978  }
979  out <<"\n";
980  delete sdl;
981  }
982 }
983 
985  const string& rid,
986  const string& param,
987  const string& entrez_term)
988 {
989  char buf[512];
990  snprintf(buf, sizeof(buf), kStructure_Overview, rid.c_str(),
991  0, 0, param.c_str(), "overview",
992  (entrez_term.empty()? "none": entrez_term.c_str()));
993  buf[sizeof(buf)-1] = '\0';
994  out << ' ' << buf <<"\n\n";
995 }
996 
998 {
1000  if(m_StructureLinkout){
1001  string mapCDDParams = (NStr::Find(m_CddRid,"data_cache") != NPOS) ? "" : "blast_CD_RID=" + m_CddRid;
1003  }
1005 }
1006 
1008  int currDisplaySort,
1009  string query_buf,
1010  int columnDisplSort,
1011  int columnHspSort,
1012  string columnText,
1013  int max_data_len,
1014  bool html)
1015 
1016 
1017 {
1018  if (html) {
1019  if(currDisplaySort == columnDisplSort) {
1020  out << "<th class=\"sel\">";
1021  }
1022  else {
1023  out << "<th>";
1024  }
1025 
1026  out << "<a href=\"Blast.cgi?"
1027  << "CMD=Get&" << query_buf
1028  << "&DISPLAY_SORT=" << columnDisplSort
1029  << "&HSP_SORT=" << columnHspSort
1030  << "#sort_mark\">";
1031 
1032  }
1033  out << columnText;
1034  if (html) {
1035  out << "</a></th>\n";
1036  }
1037  else {
1038  CAlignFormatUtil::AddSpace(out, max_data_len - columnText.size());
1040  }
1041 
1042 }
1043 
1045 {
1046  /*Note we can't just show each alnment as we go because we will
1047  need to show defline only once for all hsp's with the same id*/
1048 
1049  bool is_first_aln = true;
1050  size_t num_align = 0;
1051  CConstRef<CSeq_id> previous_id, subid;
1052  m_MaxScoreLen = kBits.size();
1053  m_MaxEvalueLen = kValue.size();
1054  m_MaxSumNLen =1;
1055  m_MaxTotalScoreLen = kTotal.size();
1057  int percent_identity = 0;
1058  m_MaxQueryCoverLen = kQueryCov.size();
1059 
1060 
1061  if(m_Option & eHtml){
1062  m_ConfigFile.reset(new CNcbiIfstream(".ncbirc"));
1063  m_Reg.reset(new CNcbiRegistry(*m_ConfigFile));
1064  if(!m_BlastType.empty()) m_LinkoutOrder = m_Reg->Get(m_BlastType,"LINKOUT_ORDER");
1066  }
1067 
1068  CSeq_align_set hit;
1069  m_QueryLength = 1;
1070  bool master_is_na = false;
1071  //prepare defline
1072 
1073  int ialn = 0;
1074  for (CSeq_align_set::Tdata::const_iterator
1075  iter = m_AlnSetRef->Get().begin();
1076  iter != m_AlnSetRef->Get().end() && num_align < m_NumToShow;
1077  iter++, ialn++){
1078 
1079  if (ialn < m_SkipTo && ialn >= m_SkipFrom) continue;
1080  if (is_first_aln) {
1083  m_ScopeRef->GetBioseqHandle((*iter)->GetSeq_id(0)).GetBioseqLength();
1084  master_is_na = m_ScopeRef->GetBioseqHandle((*iter)->GetSeq_id(0)).
1085  GetBioseqCore()->IsNa();
1086  }
1087 
1088  subid = &((*iter)->GetSeq_id(1));
1089 
1090  // This if statement is working on the last CSeq_align_set, stored in "hit"
1091  // This is confusing and the loop should probably be restructured at some point.
1092  if(!is_first_aln && !(subid->Match(*previous_id))) {
1093  SScoreInfo* sci = x_GetScoreInfoForTable(hit, num_align);
1094  if(sci){
1095  m_ScoreList.push_back(sci);
1096  if(m_MaxScoreLen < sci->bit_string.size()){
1097  m_MaxScoreLen = sci->bit_string.size();
1098  }
1099  if(m_MaxTotalScoreLen < sci->total_bit_string.size()){
1100  m_MaxTotalScoreLen = sci->total_bit_string.size();
1101  }
1102  percent_identity = CAlignFormatUtil::GetPercentMatch(sci->match,sci->align_length);
1103  if(m_MaxPercentIdentityLen < NStr::IntToString(percent_identity).size()) {
1104  m_MaxPercentIdentityLen = NStr::IntToString(percent_identity).size();
1105  }
1106  if(m_MaxEvalueLen < sci->evalue_string.size()){
1107  m_MaxEvalueLen = sci->evalue_string.size();
1108  }
1109 
1110  if( m_MaxSumNLen < NStr::IntToString(sci->sum_n).size()){
1111  m_MaxSumNLen = NStr::IntToString(sci->sum_n).size();
1112  }
1113  hit.Set().clear();
1114  }
1115 
1116  num_align++; // Only increment if new subject ID found.
1117  }
1118  if (num_align < m_NumToShow) { //no adding if number to show already reached
1119  hit.Set().push_back(*iter);
1120  }
1121  is_first_aln = false;
1122  previous_id = subid;
1123  }
1124 
1125  //the last hit
1126  SScoreInfo* sci = x_GetScoreInfoForTable(hit, num_align);
1127  if(sci){
1128  m_ScoreList.push_back(sci);
1129  if(m_MaxScoreLen < sci->bit_string.size()){
1130  m_MaxScoreLen = sci->bit_string.size();
1131  }
1132  if(m_MaxTotalScoreLen < sci->total_bit_string.size()){
1133  m_MaxScoreLen = sci->total_bit_string.size();
1134  }
1135  percent_identity = CAlignFormatUtil::GetPercentMatch(sci->match,sci->align_length);
1136  if(m_MaxPercentIdentityLen < NStr::IntToString(percent_identity).size()) {
1137  m_MaxPercentIdentityLen = NStr::IntToString(percent_identity).size();
1138  }
1139  if(m_MaxEvalueLen < sci->evalue_string.size()){
1140  m_MaxEvalueLen = sci->evalue_string.size();
1141  }
1142 
1143  if( m_MaxSumNLen < NStr::IntToString(sci->sum_n).size()){
1144  m_MaxSumNLen = NStr::IntToString(sci->sum_n).size();
1145  }
1146  hit.Set().clear();
1147  }
1148 
1149  if((m_Option & eLinkout) && (m_Option & eHtml) && !m_IsDbNa && !master_is_na)
1151 
1152 }
1153 
1155 {
1156  //This is max number of columns in the table - later should be probably put in enum DisplayOption
1157  if((m_PsiblastStatus == eFirstPass) ||
1159 
1160  if(m_Option & eHtml){
1161  if((m_Option & eShowNewSeqGif)){
1164  }
1165  if (m_Option & eCheckbox) {
1168  }
1169  }
1170  //This is done instead of code displaying titles
1171  if(!(m_Option & eNoShowHeader)) {
1172 
1173  if(m_Option & eHtml){
1174 
1175  out << "<b>";
1176  }
1177  out << kHeader << "\n";
1178  if(m_Option & eHtml){
1179  out << "</b>";
1180  out << "(Click headers to sort columns)\n";
1181  }
1182  }
1183  if(m_Option & eHtml){
1184  out << "<div id=\"desctbl\">" << "<table id=\"descs\">" << "\n" << "<thead>" << "\n";
1185  out << "<tr class=\"first\">" << "\n" << "<th>Accession</th>" << "\n" << "<th>Description</th>" << "\n";
1186  }
1187 
1188  string query_buf;
1189  map< string, string> parameters_to_change;
1190  parameters_to_change.insert(map<string, string>::
1191  value_type("DISPLAY_SORT", ""));
1192  parameters_to_change.insert(map<string, string>::
1193  value_type("HSP_SORT", ""));
1195  parameters_to_change,
1196  query_buf);
1197 
1198  parameters_to_change.clear();
1199 
1200  string display_sort_value = m_Ctx->GetRequestValue("DISPLAY_SORT").
1201  GetValue();
1202  int display_sort = display_sort_value == NcbiEmptyString ?
1203  CAlignFormatUtil::eEvalue : NStr::StringToInt(display_sort_value);
1204 
1206 
1212  }else {
1213  }
1214 
1215  if(m_Option & eShowSumN){
1216  out << "<th>" << kN << "</th>" << "\n";
1217 
1218  }
1219  if (m_Option & eLinkout) {
1220  out << "<th>Links</th>\n";
1221  out << "</tr>\n";
1222  out << "</thead>\n";
1223  }
1224  }
1225 
1226  if (m_Option & eHtml) {
1227  out << "<tbody>\n";
1228  }
1229 
1231 
1232  if (m_Option & eHtml) {
1233  out << "</tbody>\n</table></div>\n";
1234  }
1235 }
1236 
1238 {
1239  int percent_identity = 0;
1240  int tableColNumber = (m_Option & eShowPercentIdent) ? 9 : 8;
1241  bool first_new =true;
1242  int prev_database_type = 0, cur_database_type = 0;
1243  bool is_first = true;
1244  // Mixed db is genomic + transcript and this does not apply to proteins.
1245  bool is_mixed_database = false;
1246  if (m_IsDbNa == true)
1247  is_mixed_database = CAlignFormatUtil::IsMixedDatabase(*m_Ctx);
1248 
1249  map< string, string> parameters_to_change;
1250  string query_buf;
1251  if (is_mixed_database && m_Option & eHtml) {
1252  parameters_to_change.insert(map<string, string>::
1253  value_type("DATABASE_SORT", ""));
1255  parameters_to_change,
1256  query_buf);
1257  }
1258  ITERATE(vector<SScoreInfo*>, iter, m_ScoreList){
1259  SDeflineInfo* sdl = x_GetDeflineInfo((*iter)->id, (*iter)->use_this_seqid, (*iter)->blast_rank);
1260  //size_t line_length = 0;
1261  string line_component;
1262  cur_database_type = (sdl->linkout & eGenomicSeq);
1263  if (is_mixed_database) {
1264  if (is_first) {
1265  if (m_Option & eHtml) {
1266  out << "<tr>\n<th colspan=\"" << tableColNumber<< "\" class=\"l sp\">";
1267  }
1268  if (cur_database_type) {
1269  out << "Genomic sequences";
1270  } else {
1271  out << "Transcripts";
1272  }
1273  if (!(m_Option & eHtml)) {
1274  out << ":\n";
1275  }
1276  if (m_Option & eHtml) {
1277  out << "</th></tr>\n";
1278  }
1279  } else if (prev_database_type != cur_database_type) {
1280  if (m_Option & eHtml) {
1281  out << "<tr>\n<th colspan=\"" << tableColNumber<< "\" class=\"l sp\">";
1282  }
1283  if (cur_database_type) {
1284  out << "Genomic sequences";
1285  } else {
1286  out << "Transcripts";
1287  }
1288  if (m_Option & eHtml) {
1289  out << "<span class=\"slink\">"
1290  << " [<a href=\"Blast.cgi?CMD=Get&"
1291  << query_buf
1292  << "&DATABASE_SORT=";
1293  if (cur_database_type) {
1295  } else {
1297  }
1298  out << "#sort_mark\">show first</a>]</span>";
1299  }
1300  else {
1301  out << ":\n";
1302  }
1303  if (m_Option & eHtml) {
1304  out << "</th></tr>\n";
1305  }
1306  }
1307  }
1308  prev_database_type = cur_database_type;
1309  is_first = false;
1310  if (m_Option & eHtml) {
1311  out << "<tr>\n";
1312  out << "<td class=\"l\">\n";
1313  }
1314  if ((m_Option & eHtml) && (sdl->gi > ZERO_GI)){
1315  if((m_Option & eShowNewSeqGif)) {
1316  if (sdl->is_new) {
1317  if (first_new) {
1318  first_new = false;
1320  }
1322 
1323  } else {
1325  }
1326  if (sdl->was_checked) {
1328 
1329  } else {
1331  }
1332  }
1333  if((m_Option & eCheckboxChecked)){
1335  } else if (m_Option & eCheckbox) {
1336  s_DisplayCheckbox(out, sdl->gi);
1337  }
1338  }
1339 
1340 
1341  if((m_Option & eHtml) && (sdl->id_url != NcbiEmptyString)) {
1342  out << sdl->id_url;
1343  }
1344  if(m_Option & eShowGi){
1345  if(sdl->gi > ZERO_GI){
1346  line_component = "gi|" + NStr::NumericToString(sdl->gi) + "|";
1347  out << line_component;
1348  //line_length += line_component.size();
1349  }
1350  }
1351  if(!sdl->id.Empty()){
1352  if(!(sdl->id->AsFastaString().find("gnl|BL_ORD_ID") != string::npos ||
1353  sdl->id->AsFastaString().find("lcl|Subject_") != string::npos)){
1354  string id_str;
1355  sdl->id->GetLabel(&id_str, CSeq_id::eContent);
1356  out << id_str;
1357  //line_length += id_str.size();
1358  }
1359  }
1360  if((m_Option & eHtml) && (sdl->id_url != NcbiEmptyString)) {
1361  out << "</a>";
1362  }
1363  if (m_Option & eHtml) {
1364  out << "</td><td class=\"lim l\"><div class=\"lim\">";
1365  }
1366  line_component = " " + sdl->defline;
1367  string actual_line_component;
1368  actual_line_component = line_component;
1369 
1370  if (m_Option & eHtml) {
1371  out << CHTMLHelper::HTMLEncode(actual_line_component);
1372  out << "</div></td><td>";
1373  } else {
1374  out << actual_line_component;
1375  }
1376 
1377  if((m_Option & eHtml) && (sdl->score_url != NcbiEmptyString)) {
1378  out << sdl->score_url;
1379  }
1380  out << (*iter)->bit_string;
1381  if((m_Option & eHtml) && (sdl->score_url != NcbiEmptyString)) {
1382  out << "</a>";
1383  }
1384  if(m_Option & eHtml) {
1385  out << "</td>";
1386  out << "<td>" << (*iter)->total_bit_string << "</td>";
1387  }
1388  if (!(m_Option & eHtml)) {
1389  CAlignFormatUtil::AddSpace(out, m_MaxScoreLen - (*iter)->bit_string.size());
1390 
1391  out << kTwoSpaceMargin << kOneSpaceMargin << (*iter)->total_bit_string;
1393  (*iter)->total_bit_string.size());
1394  }
1395 
1396  int percent_coverage = 100*(*iter)->master_covered_length/m_QueryLength;
1397  if (m_Option & eHtml) {
1398  out << "<td>" << percent_coverage << "%</td>";
1399  }
1400  else {
1401  out << kTwoSpaceMargin << percent_coverage << "%";
1402 
1403  //minus one due to % sign
1405  NStr::IntToString(percent_coverage).size() - 1);
1406  }
1407 
1408  if (m_Option & eHtml) {
1409  out << "<td>" << (*iter)->evalue_string << "</td>";
1410  }
1411  else {
1412  out << kTwoSpaceMargin << (*iter)->evalue_string;
1413  CAlignFormatUtil::AddSpace(out, m_MaxEvalueLen - (*iter)->evalue_string.size());
1414  }
1416  percent_identity = CAlignFormatUtil::GetPercentMatch((*iter)->match,(*iter)->align_length);
1417  if (m_Option & eHtml) {
1418  out << "<td>" << percent_identity << "%</td>";
1419  }
1420  else {
1421  out << kTwoSpaceMargin << percent_identity <<"%";
1422 
1424  NStr::IntToString(percent_identity).size());
1425  }
1426  }
1427  //???
1428  if(m_Option & eShowSumN){
1429  if (m_Option & eHtml) {
1430  out << "<td>";
1431  }
1432  out << kTwoSpaceMargin << (*iter)->sum_n;
1433  if (m_Option & eHtml) {
1434  out << "</td>";
1435  } else {
1437  NStr::IntToString((*iter)->sum_n).size());
1438  }
1439  }
1440 
1441  if((m_Option & eLinkout) && (m_Option & eHtml)){
1442 
1443  out << "<td>";
1444  bool first_time = true;
1445  ITERATE(list<string>, iter_linkout, sdl->linkout_list){
1446  if(first_time){
1447  out << kOneSpaceMargin;
1448  first_time = false;
1449  }
1450  out << *iter_linkout;
1451  }
1452  out << "</td>";
1453  }
1454  if (m_Option & eHtml) {
1455  out << "</tr>";
1456  }
1457  if (!(m_Option & eHtml)) {
1458  out <<"\n";
1459  }
1460  delete sdl;
1461  }
1462 }
1463 
1464 
1466 {
1468  if(m_StructureLinkout){
1470  }
1472 }
1473 
1476 {
1477  string evalue_buf, bit_score_buf, total_bit_score_buf, raw_score_buf;
1478  int score = 0;
1479  double bits = 0;
1480  double evalue = 0;
1481  int sum_n = 0;
1482  int num_ident = 0;
1483  list<string> use_this_seq;
1484 
1485  use_this_seq.clear();
1486  CAlignFormatUtil::GetAlnScores(aln, score, bits, evalue, sum_n,
1487  num_ident, use_this_seq);
1488 
1489  CAlignFormatUtil::GetScoreString(evalue, bits, 0, score,
1490  evalue_buf, bit_score_buf, total_bit_score_buf,
1491  raw_score_buf);
1492 
1493  unique_ptr<SScoreInfo> score_info(new SScoreInfo);
1494  score_info->sum_n = sum_n == -1 ? 1:sum_n ;
1495  score_info->id = &(aln.GetSeq_id(1));
1496 
1497  score_info->use_this_seqid = use_this_seq;
1498 
1499  score_info->bit_string = bit_score_buf;
1500  score_info->raw_score_string = raw_score_buf;
1501  score_info->evalue_string = evalue_buf;
1502  score_info->id = &(aln.GetSeq_id(1));
1503  score_info->blast_rank = blast_rank+1;
1504  score_info->subjRange = CRange<TSeqPos>(0,0);
1505  score_info->flip = false;
1506  return score_info.release();
1507 }
1508 
1511 {
1512  string evalue_buf, bit_score_buf, total_bit_score_buf, raw_score_buf;
1513 
1514  if(aln.Get().empty())
1515  return NULL;
1516 
1517  unique_ptr<SScoreInfo> score_info(new SScoreInfo);
1518 
1519  unique_ptr<CAlignFormatUtil::SSeqAlignSetCalcParams> seqSetInfo( CAlignFormatUtil::GetSeqAlignSetCalcParamsFromASN(aln));
1520  if(seqSetInfo->hspNum == 0) {//calulated params are not in ASN - calculate now
1522  }
1523 
1524  CAlignFormatUtil::GetScoreString(seqSetInfo->evalue, seqSetInfo->bit_score, seqSetInfo->total_bit_score, seqSetInfo->raw_score,
1525  evalue_buf, bit_score_buf, total_bit_score_buf,
1526  raw_score_buf);
1527  score_info->id = seqSetInfo->id;
1528 
1529  score_info->total_bit_string = total_bit_score_buf;
1530  score_info->bit_string = bit_score_buf;
1531  score_info->evalue_string = evalue_buf;
1532  score_info->percent_coverage = seqSetInfo->percent_coverage;
1533  score_info->percent_identity = seqSetInfo->percent_identity;
1534  score_info->hspNum = seqSetInfo->hspNum;
1535  score_info->totalLen = seqSetInfo->totalLen;
1536 
1537  score_info->use_this_seqid = seqSetInfo->use_this_seq;
1538  score_info->sum_n = seqSetInfo->sum_n == -1 ? 1:seqSetInfo->sum_n ;
1539 
1540  score_info->raw_score_string = raw_score_buf;//check if used
1541  score_info->match = seqSetInfo->match; //check if used
1542  score_info->align_length = seqSetInfo->align_length;//check if used
1543  score_info->master_covered_length = seqSetInfo->master_covered_length;//check if used
1544 
1545 
1546  score_info->subjRange = seqSetInfo->subjRange; //check if used
1547  score_info->flip = seqSetInfo->flip;//check if used
1548 
1549  score_info->blast_rank = blast_rank+1;
1550 
1551  return score_info.release();
1552 }
1553 
1554 vector <CShowBlastDefline::SDeflineInfo*>
1556 {
1557  vector <CShowBlastDefline::SDeflineInfo*> sdlVec;
1558  for(size_t i = 0; i < seqIds.size(); i++) {
1559  list<string> use_this_seq;
1560  CShowBlastDefline::SDeflineInfo* sdl = x_GetDeflineInfo(seqIds[i], use_this_seq, i + 1 );
1561  sdlVec.push_back(sdl);
1562  }
1563  return sdlVec;
1564 }
1565 
1566 
1567 
1569 CShowBlastDefline::x_GetDeflineInfo(CConstRef<CSeq_id> id, list<string> &use_this_seqid, int blast_rank)
1570 {
1571  SDeflineInfo* sdl = NULL;
1572  sdl = new SDeflineInfo;
1573  sdl->id = id;
1574  sdl->defline = "Unknown";
1575  sdl->clustMemberNum = 0;
1576  sdl->clustTaxaNum = 0;
1577  sdl->clustAncTaxid = ZERO_TAX_ID;
1578 
1579  try{
1580  const CBioseq_Handle& handle = m_ScopeRef->GetBioseqHandle(*id);
1581  x_FillDeflineAndId(handle, *id, use_this_seqid, sdl, blast_rank);
1582  } catch (const CException&){
1583  sdl->defline = "Unknown";
1584  sdl->is_new = false;
1585  sdl->was_checked = false;
1586  sdl->linkout = 0;
1587 
1588  if((*id).Which() == CSeq_id::e_Gi){
1589  sdl->gi = (*id).GetGi();
1590  } else {
1591  sdl->gi = ZERO_GI;
1592  }
1593  sdl->id = id;
1594  if(m_Option & eHtml){
1595  _ASSERT(m_Reg.get());
1596 
1597  string user_url= m_Reg->Get(m_BlastType, "TOOL_URL");
1598  string accession;
1599  sdl->id->GetLabel(&accession, CSeq_id::eContent);
1600  CRange<TSeqPos> seqRange(0,0);
1602  m_QueryNumber,sdl->gi,accession,0,blast_rank,false,(m_Option & eNewTargetWindow) ? true : false,seqRange,false,ZERO_TAX_ID);
1603  sdl->id_url = CAlignFormatUtil::GetIDUrl(&seqUrlInfo,*id,*m_ScopeRef);
1604  sdl->score_url = NcbiEmptyString;
1605  }
1606  }
1607 
1608  return sdl;
1609 }
1610 
1612 {
1613  bool first_new =true;
1614  int prev_database_type = 0, cur_database_type = 0;
1615  bool is_first = true;
1616 
1617  // Mixed db is genomic + transcript and this does not apply to proteins.
1618  bool is_mixed_database = (m_Ctx && m_IsDbNa == true)? CAlignFormatUtil::IsMixedDatabase(*m_Ctx): false;
1619  string rowType = "odd";
1620  string subHeaderID;
1621  ITERATE(vector<SScoreInfo*>, iter, m_ScoreList){
1622  SDeflineInfo* sdl = x_GetDeflineInfo((*iter)->id, (*iter)->use_this_seqid, (*iter)->blast_rank);
1623  cur_database_type = (sdl->linkout & eGenomicSeq);
1624  string subHeader;
1625  bool formatHeaderSort = !is_first && (prev_database_type != cur_database_type);
1626  if (is_mixed_database && (is_first || formatHeaderSort)) {
1627  subHeader = x_FormatSeqSetHeaders(cur_database_type, formatHeaderSort);
1628  subHeaderID = cur_database_type ? "GnmSeq" : "Transcr";
1629  //This is done for 508 complience
1630  subHeader = CAlignFormatUtil::MapTemplate(subHeader,"defl_header_id",subHeaderID);
1631  }
1632  prev_database_type = cur_database_type;
1633 
1634  string defLine = x_FormatDeflineTableLine(sdl,*iter,first_new);
1635 
1636  //This is done for 508 complience
1637  defLine = CAlignFormatUtil::MapTemplate(defLine,"defl_header_id",subHeaderID);
1638 
1639  string firstSeq = (is_first) ? "firstSeq" : "";
1640  defLine = CAlignFormatUtil::MapTemplate(defLine,"firstSeq",firstSeq);
1641  defLine = CAlignFormatUtil::MapTemplate(defLine,"trtp",rowType);
1642 
1643  rowType = (rowType == "odd") ? "even" : "odd";
1644 
1645  if(!subHeader.empty()) {
1646  defLine = subHeader + defLine;
1647  }
1648  is_first = false;
1649  out << defLine;
1650 
1651  delete sdl;
1652  }
1653 }
1654 
1655 
1657 {
1658  if(sdl->clustAncTaxid == 0) {
1659  if(sdl->taxid > 0) {
1660  try{
1661  CSeqDB::GetTaxInfo(sdl->taxid, taxInfo);
1662  taxInfo.common_name = (taxInfo.common_name == taxInfo.scientific_name || taxInfo.common_name.empty()) ? "NA" : taxInfo.common_name;
1663  taxInfo.taxid = sdl->taxid;
1664  } catch (const CException&){
1665  taxInfo.common_name = "Unknown";
1666  taxInfo.scientific_name = "Unknown";
1667  taxInfo.blast_name = "Unknown";
1668  }
1669  }
1670  }
1671  else {
1672  taxInfo.taxid = sdl->clustAncTaxid;
1673  taxInfo.common_name = sdl->clustAncCmnName;
1674  taxInfo.scientific_name = sdl->clustAncSciName;
1675  }
1676 }
1677 
1678 
1680 {
1681  if(!sdl->clustMemList.empty()) {
1682  string allClustRows;
1683  for (size_t i =0; i < sdl->clustMemList.size(); i++) {
1684  string clustRow;
1685  clustRow = CAlignFormatUtil::MapTemplate(m_DeflineTemplates->clusterMemTmpl,"clust_mem",sdl->clustMemList[i].memAcc);
1686  clustRow = CAlignFormatUtil::MapTemplate(clustRow,"clust_mem_sci_name",sdl->clustMemList[i].sciName);
1687  clustRow = CAlignFormatUtil::MapTemplate(clustRow,"clust_mem_cmn_name",sdl->clustMemList[i].commonName);
1688  clustRow = CAlignFormatUtil::MapTemplate(clustRow,"clust_mem_taxid",NStr::IntToString(sdl->clustMemList[i].taxid));
1689  allClustRows += clustRow;
1690  }
1691  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_mem_rows",allClustRows);
1692  int displClusterMemNum = sdl->clustMemList.size();
1693  string clustMemDiff, clustSizeShow;
1694  if(sdl->clustMemberNum > displClusterMemNum) {
1695  clustMemDiff = NStr::NumericToString(sdl->clustMemberNum - displClusterMemNum);
1696  clustSizeShow = "shown";
1697  }
1698  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_size_show",clustSizeShow);
1699  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_mem_diff",clustMemDiff);
1700  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_member_num_displ",displClusterMemNum);
1701  }
1702  return defLine;
1703 }
1704 
1706 {
1707  if(!sdl->clustMemList.empty()) {
1708  string allClustRows;
1709  for (size_t i =0; i < sdl->clustMemList.size(); i++) {
1710  if( i == 0) { //Format header
1712  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"sciname_hd",kScientific,kMaxTaxonomyNameLengthExt);
1713  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"comname_hd",kCommon,kMaxTaxonomyNameLengthExt);
1714  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"taxid_hd",kTaxid,kMaxDispNumberLength);
1715  allClustRows += descrHeader;
1716  }
1717 
1719  clustRow = CAlignFormatUtil::MapSpaceTemplate(clustRow,"clust_mem_cmn_name",sdl->clustMemList[i].commonName,kMaxTaxonomyNameLengthExt);
1720  clustRow = CAlignFormatUtil::MapSpaceTemplate(clustRow,"clust_mem_sci_name",sdl->clustMemList[i].sciName,kMaxTaxonomyNameLengthExt);
1721  clustRow = CAlignFormatUtil::MapSpaceTemplate(clustRow,"clust_mem_taxid",NStr::IntToString(sdl->clustMemList[i].taxid),kMaxDispNumberLength);
1722  allClustRows += clustRow;
1723  }
1724  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_mem_rows",allClustRows);
1725  }
1726  return defLine;
1727 }
1728 
1729 
1731 {
1732  bool first_new = true;
1733  string defLine;
1734 
1735 
1736  if(m_Option & eHtml) {
1737  defLine = x_FormatDeflineTableLine(sdl,iter,first_new);
1738  if(!sdl->clustMemList.empty()) {
1739  defLine = x_FormatClusterMemData(sdl, defLine);
1740  }
1741  string firstSeq = (is_first) ? "firstSeq" : "";
1742  defLine = CAlignFormatUtil::MapTemplate(defLine,"firstSeq",firstSeq);
1743  }
1744  else if(m_Option & eShowCSVDescr) {
1745  if(!sdl->clustMemList.empty()) {
1746  // Cluster members CSV downlaod
1748  }
1749  else {
1750  defLine = x_FormatDeflineTableLineCSV(sdl,iter);
1751  }
1752  }
1753  else { // text
1754  if(!sdl->clustMemList.empty()) { // Show cluster member infor
1755  defLine = x_FormatDeflineTableLine(sdl,iter,first_new);
1756  defLine = x_FormatClusterMemDataTxt(sdl, defLine);
1757  }
1758  else {//Format just deline table row
1759  defLine = x_FormatDeflineTableLineText(sdl,iter);
1760  //And header
1761  if(is_first) {
1762  string descrHeader = x_FormatDeflineTableHeaderText();
1763  defLine = descrHeader + defLine;
1764  }
1765  }
1766  }
1767 
1768  is_first = false;
1769  out << defLine;
1770  delete sdl;
1771 }
1772 
1773 
1775 {
1776 
1777  string defLine = m_DeflineTemplates->defLineTmpl;
1778  string seqid;
1779  if(!sdl->id.Empty()){
1780  if(!(sdl->id->AsFastaString().find("gnl|BL_ORD_ID") != string::npos ||sdl->id->AsFastaString().find("lcl|Subject_") != string::npos)) {
1781  sdl->id->GetLabel(&seqid, CSeq_id::eContent);
1782  }
1783  }
1784 
1785  if(sdl->id_url != NcbiEmptyString) {
1786  string seqInfo = CAlignFormatUtil::MapTemplate(m_DeflineTemplates->seqInfoTmpl,"dfln_url",sdl->id_url);
1787  seqInfo = CAlignFormatUtil::MapTemplate(seqInfo,"dfln_seqid",seqid);
1788  defLine = CAlignFormatUtil::MapTemplate(defLine,"seq_info",seqInfo);
1789  }
1790  else {
1791  defLine = CAlignFormatUtil::MapTemplate(defLine,"seq_info",seqid);
1792  }
1793 
1794  string descr = (!sdl->defline.empty()) ? sdl->defline : "None provided";
1795  s_LimitDescrLength(descr);
1796  if(NStr::Find(descr,",") != NPOS) {
1797  descr = "\"" + descr + "\"";
1798  }
1799  defLine = CAlignFormatUtil::MapTemplate(defLine,"dfln_defline",descr);
1800 
1801  SSeqDBTaxInfo taxInfo;
1802  x_GetTaxonomyInfoForTaxID(sdl, taxInfo);
1803  defLine = CAlignFormatUtil::MapTemplate(defLine,"common_name",taxInfo.common_name);
1804  defLine = CAlignFormatUtil::MapTemplate(defLine,"scientific_name",taxInfo.scientific_name);
1805  defLine = CAlignFormatUtil::MapTemplate(defLine,"taxid",NStr::IntToString(taxInfo.taxid));
1806 
1807 
1808  defLine = CAlignFormatUtil::MapTemplate(defLine,"score_info",iter->bit_string);
1809  defLine = CAlignFormatUtil::MapTemplate(defLine,"total_bit_string",iter->total_bit_string);
1810  defLine = CAlignFormatUtil::MapTemplate(defLine,"percent_coverage",NStr::IntToString(iter->percent_coverage) + "%");
1811  defLine = CAlignFormatUtil::MapTemplate(defLine,"evalue_string",iter->evalue_string);
1812 
1813  defLine = CAlignFormatUtil::MapTemplate(defLine,"percent_identity",NStr::DoubleToString(iter->percent_identity,2));
1814  int len = sequence::GetLength(*sdl->id, m_ScopeRef);
1815  defLine = CAlignFormatUtil::MapTemplate(defLine,"acclen",NStr::IntToString(len));
1816  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_member_num",sdl->clustMemberNum);
1817  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_taxa_num",sdl->clustTaxaNum);
1818 
1819  return defLine;
1820 }
1821 
1822 
1824 {
1825  ITERATE(vector<SScoreInfo*>, iter, m_ScoreList){
1826  SDeflineInfo* sdl = x_GetDeflineInfo((*iter)->id, (*iter)->use_this_seqid, (*iter)->blast_rank);
1827  string defLine = x_FormatDeflineTableLineCSV(sdl,*iter);
1828 
1829  out << defLine;
1830  delete sdl;
1831  }
1832 
1833 }
1834 
1835 
1837 {
1838  string defLine = m_DeflineTemplates->defLineTmpl;
1839  string seqid;
1840  if(!sdl->id.Empty()){
1841  if(!(sdl->id->AsFastaString().find("gnl|BL_ORD_ID") != string::npos ||sdl->id->AsFastaString().find("lcl|Subject_") != string::npos)) {
1842  sdl->id->GetLabel(&seqid, CSeq_id::eContent);
1843  }
1844  }
1845 
1846  string descr = (!sdl->defline.empty()) ? sdl->defline : "None provided";
1848  defLine = CAlignFormatUtil::MapSpaceTemplate(defLine,"dfln_defline",descr, m_LineLen);
1851  SSeqDBTaxInfo taxInfo;
1852  x_GetTaxonomyInfoForTaxID(sdl, taxInfo);
1853  defLine = CAlignFormatUtil::MapSpaceTemplate(defLine,"common_name",taxInfo.common_name,kMaxTaxonomyNameLength);
1854  defLine = CAlignFormatUtil::MapSpaceTemplate(defLine,"scientific_name",taxInfo.scientific_name,kMaxTaxonomyNameLength);
1856  defLine = CAlignFormatUtil::MapSpaceTemplate(defLine,"score_info",iter->bit_string,m_MaxScoreLen);
1857  defLine = CAlignFormatUtil::MapSpaceTemplate(defLine,"total_bit_string",iter->total_bit_string,m_MaxTotalScoreLen);
1858  defLine = CAlignFormatUtil::MapSpaceTemplate(defLine,"percent_coverage",NStr::IntToString(iter->percent_coverage) + "%",m_MaxQueryCoverLen);
1859  defLine = CAlignFormatUtil::MapSpaceTemplate(defLine,"evalue_string",iter->evalue_string,m_MaxEvalueLen);
1861 
1862  int len = sequence::GetLength(*sdl->id, m_ScopeRef);
1864  defLine = CAlignFormatUtil::MapSpaceTemplate(defLine,"seq_info",seqid,kMaxAccLength);
1865  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_member_num",sdl->clustMemberNum);
1866  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_taxa_num",sdl->clustTaxaNum);
1867  return defLine;
1868 }
1869 
1870 
1872 {
1873  string descrHeader = CAlignFormatUtil::MapSpaceTemplate(m_DeflineTemplates->deflineTxtHeader,"descr_hd1"," ",m_LineLen); //empty string
1874  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"clust_hd1"," ",m_LineLen); //only for cluster db
1875  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"clustmemnum_hd1",kNumOf,kMaxDispNumberLength);
1876  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"clusttaxanum_hd1",kNumOf,kMaxDispNumberLength);
1877  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"sciname_hd1",kScientific,kMaxTaxonomyNameLength);
1878  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"comname_hd1",kCommon,kMaxTaxonomyNameLength);
1879  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"clustancestor_hd1",kCluster,kMaxTaxonomyNameLength);
1880  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"taxid_hd1"," ",kMaxDispNumberLength);
1881  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"score_hd1",kMax,m_MaxScoreLen);
1882  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"total_hd1",kTotal,m_MaxTotalScoreLen);
1883  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"querycov_hd1",kQueryCov,m_MaxQueryCoverLen);
1884  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"evalue_hd1"," " + kE + " ",m_MaxEvalueLen);
1885  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"percident_hd1",kPerc,kMaxPercentIdentityLen);
1886  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"acclen_hd1",kAccAbbr,kMaxDispNumberLength);
1887  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"acc_hd1"," ",kMaxAccLength);
1888  //kBits kTotalLine2 kQueryCovLine2 kValue kIdentLine2
1889  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"descr_hd2",kDescription,m_LineLen);
1890  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"clust_hd2",kClusterTitle,m_LineLen); //only for cluster db
1891  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"clustmemnum_hd2",kMember,kMaxDispNumberLength);
1892  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"clusttaxanum_hd2",kTaxa,kMaxDispNumberLength);
1893 
1894  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"sciname_hd2",kName,kMaxTaxonomyNameLength);
1895  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"comname_hd2",kName,kMaxTaxonomyNameLength);
1896  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"clustancestor_hd2",kAncestor,kMaxTaxonomyNameLength);
1897  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"taxid_hd2",kTaxid,kMaxDispNumberLength);
1898  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"score_hd2",kScoreLine2,m_MaxScoreLen);
1899  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"total_hd2",kScoreLine2,m_MaxTotalScoreLen);
1900  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"querycov_hd2",kQueryCovLine2,m_MaxQueryCoverLen);
1901  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"evalue_hd2",kValue,m_MaxEvalueLen);
1902  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"percident_hd2",kIdentLine2,kMaxPercentIdentityLen);
1903  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"acclen_hd2",kLenAbbr,kMaxDispNumberLength);
1904  descrHeader = CAlignFormatUtil::MapSpaceTemplate(descrHeader,"acc_hd2",kAccession,kMaxAccLength);
1905  return descrHeader;
1906 }
1907 
1908 
1909 
1911 {
1912  string descrHeader = x_FormatDeflineTableHeaderText();
1913  out << descrHeader;
1914 
1915  ITERATE(vector<SScoreInfo*>, iter, m_ScoreList){
1916  SDeflineInfo* sdl = x_GetDeflineInfo((*iter)->id, (*iter)->use_this_seqid, (*iter)->blast_rank);
1917  string defLine = x_FormatDeflineTableLineText(sdl,*iter);
1918  out << defLine;
1919  delete sdl;
1920  }
1921 }
1922 
1923 
1924 string CShowBlastDefline::x_FormatSeqSetHeaders(int isGenomicSeq, bool formatHeaderSort)
1925 {
1926  string seqSetType = isGenomicSeq ? "Genomic sequences" : "Transcripts";
1927  string subHeader = CAlignFormatUtil::MapTemplate(m_DeflineTemplates->subHeaderTmpl,"defl_seqset_type",seqSetType);
1928  if (formatHeaderSort) {
1929  int database_sort = isGenomicSeq ? CAlignFormatUtil::eGenomicFirst : CAlignFormatUtil::eNonGenomicFirst;
1930  string deflnSubHeaderSort = CAlignFormatUtil::MapTemplate(m_DeflineTemplates->subHeaderSort,"database_sort",database_sort);
1931  subHeader = CAlignFormatUtil::MapTemplate(subHeader,"defl_header_sort",deflnSubHeaderSort);
1932  }
1933  else {
1934  subHeader = CAlignFormatUtil::MapTemplate(subHeader,"defl_header_sort","");
1935  }
1936  return subHeader;
1937 }
1938 
1939 
1941 {
1942  string defLine = (((m_Option & eCheckboxChecked) || (m_Option & eCheckbox))) ? x_FormatPsi(sdl, first_new) : m_DeflineTemplates->defLineTmpl;
1943  string dflGi = (m_Option & eShowGi) && (sdl->gi > ZERO_GI) ? "gi|" + NStr::NumericToString(sdl->gi) + "|" : "";
1944  string seqid;
1945  if(!sdl->id.Empty()){
1946  if(!(sdl->id->AsFastaString().find("gnl|BL_ORD_ID") != string::npos ||
1947  sdl->id->AsFastaString().find("lcl|Subject_") != string::npos)) {
1948  sdl->id->GetLabel(&seqid, CSeq_id::eContent);
1949  }
1950  }
1951 
1952  if(sdl->id_url != NcbiEmptyString) {
1953  string seqInfo = CAlignFormatUtil::MapTemplate(m_DeflineTemplates->seqInfoTmpl,"dfln_url",sdl->id_url);
1954  string trgt = (m_Option & eNewTargetWindow) ? "TARGET=\"EntrezView\"" : "";
1955  seqInfo = CAlignFormatUtil::MapTemplate(seqInfo,"dfln_target",trgt);
1956  defLine = CAlignFormatUtil::MapTemplate(defLine,"seq_info",seqInfo);
1957  defLine = CAlignFormatUtil::MapTemplate(defLine,"dfln_gi",dflGi);
1958  defLine = CAlignFormatUtil::MapTemplate(defLine,"dfln_seqid",seqid);
1959  }
1960  else {
1961  defLine = CAlignFormatUtil::MapTemplate(defLine,"seq_info",dflGi + seqid);
1962  }
1963 
1964  string descr = (!sdl->defline.empty()) ? sdl->defline : "None provided";
1965  s_LimitDescrLength(descr);
1966  defLine = CAlignFormatUtil::MapTemplate(defLine,"dfln_defline",CHTMLHelper::HTMLEncode(descr));
1967 
1968  descr = (!sdl->fullDefline.empty()) ? sdl->fullDefline : seqid;
1969  s_LimitDescrLength(descr);
1970  defLine = CAlignFormatUtil::MapTemplate(defLine,"full_dfln_defline",CHTMLHelper::HTMLEncode(descr));
1971  if(sdl->score_url != NcbiEmptyString) {
1972  string scoreInfo = CAlignFormatUtil::MapTemplate(m_DeflineTemplates->scoreInfoTmpl,"score_url",sdl->score_url);
1973  scoreInfo = CAlignFormatUtil::MapTemplate(scoreInfo,"bit_string",iter->bit_string);
1974  scoreInfo = CAlignFormatUtil::MapTemplate(scoreInfo,"score_seqid",seqid);
1975  defLine = CAlignFormatUtil::MapTemplate(defLine,"score_info",scoreInfo);
1976  }
1977  else {
1978  defLine = CAlignFormatUtil::MapTemplate(defLine,"score_info",iter->bit_string);
1979  }
1980 
1981  string deflId,deflFrmID,deflFastaSeq,deflAccs;
1982  if(sdl->gi == ZERO_GI) {
1983  sdl->id->GetLabel(& deflId, CSeq_id::eContent);
1984  deflFrmID = CAlignFormatUtil::GetLabel(sdl->id);//Just accession without db part like GNOMON: or ti:
1985  deflFastaSeq = NStr::TruncateSpaces(sdl->alnIDFasta);
1986  deflAccs = sdl->id->AsFastaString();
1987  }
1988  else {
1989  deflFrmID = deflId = NStr::NumericToString(sdl->gi);
1990  deflFastaSeq = "gi|" + NStr::NumericToString(sdl->gi);
1991  deflFastaSeq = NStr::TruncateSpaces(sdl->alnIDFasta);
1992  sdl->id->GetLabel(&deflAccs, CSeq_id::eContent);
1993  }
1994  string combinedSeqID = CAlignFormatUtil::GetBareId(*sdl->id); // for pir|, prf| will hav pri|acc| for others just acc
1995 
1996  SSeqDBTaxInfo taxInfo;
1997  x_GetTaxonomyInfoForTaxID(sdl, taxInfo);
1998  defLine = CAlignFormatUtil::MapTemplate(defLine,"common_name",taxInfo.common_name);
1999  defLine = CAlignFormatUtil::MapTemplate(defLine,"scientific_name",taxInfo.scientific_name);
2000  defLine = CAlignFormatUtil::MapTemplate(defLine,"blast_name",taxInfo.blast_name);
2001  defLine = CAlignFormatUtil::MapTemplate(defLine,"taxid",NStr::IntToString(taxInfo.taxid));
2002 
2003  int len = sequence::GetLength(*sdl->id, m_ScopeRef);
2004  defLine = CAlignFormatUtil::MapTemplate(defLine,"acclen",NStr::IntToString(len));
2005  //Setup applog info structure
2007  m_AppLogInfo->deflIdVec.push_back(deflId);
2008  m_AppLogInfo->accVec.push_back(deflAccs);
2009  m_AppLogInfo->taxidVec.push_back(NStr::NumericToString(taxInfo.taxid));
2012  m_AppLogInfo->currInd++;
2013  }
2014 
2015  //If gi - deflFrmID and deflId are the same and equal to gi "555",deflFastaSeq will have "gi|555"
2016  //If gnl - deflFrmID=number, deflId=ti:number,deflFastaSeq=gnl|xxx
2017  //like "268252125","ti:268252125","gnl|ti|961433.m" or "961433.m" and "GNOMON:961433.m" "gnl|GNOMON|961433.m"
2018  defLine = CAlignFormatUtil::MapTemplate(defLine,"dfln_id",deflId);
2019  defLine = CAlignFormatUtil::MapTemplate(defLine,"dflnComb_id",combinedSeqID);
2020  defLine = CAlignFormatUtil::MapTemplate(defLine,"dflnFrm_id",deflFrmID);
2021  defLine = CAlignFormatUtil::MapTemplate(defLine,"dflnFASTA_id",deflFastaSeq);
2022  defLine = CAlignFormatUtil::MapTemplate(defLine,"dflnAccs",deflAccs);
2023  defLine = CAlignFormatUtil::MapTemplate(defLine,"dfln_rid",m_Rid);
2024  defLine = CAlignFormatUtil::MapTemplate(defLine,"dfln_hspnum",iter->hspNum);
2025  defLine = CAlignFormatUtil::MapTemplate(defLine,"dfln_alnLen",iter->totalLen);
2026  defLine = CAlignFormatUtil::MapTemplate(defLine,"dfln_blast_rank",m_StartIndex + iter->blast_rank);
2027  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_member_num",sdl->clustMemberNum);
2028  defLine = CAlignFormatUtil::MapTemplate(defLine,"clust_taxa_num",sdl->clustTaxaNum);
2029 
2030 
2031  defLine = CAlignFormatUtil::MapTemplate(defLine,"total_bit_string",iter->total_bit_string);
2032 
2033 
2034  defLine = CAlignFormatUtil::MapTemplate(defLine,"percent_coverage",NStr::IntToString(iter->percent_coverage));
2035 
2036  defLine = CAlignFormatUtil::MapTemplate(defLine,"evalue_string",iter->evalue_string);
2037 
2039  defLine = CAlignFormatUtil::MapTemplate(defLine,"percent_identity",NStr::DoubleToString(iter->percent_identity,2));
2040  }
2041 
2042  if(m_Option & eShowSumN){
2043  defLine = CAlignFormatUtil::MapTemplate(defLine,"sum_n",NStr::IntToString(iter->sum_n));
2044  }
2045 
2046  string links;
2047  //sdl->linkout_list may contain linkouts + mapview link + seqview link
2048  ITERATE(list<string>, iter_linkout, sdl->linkout_list){
2049  links += *iter_linkout;
2050  }
2051  defLine = CAlignFormatUtil::MapTemplate(defLine,"linkout",links);
2052 
2053  return defLine;
2054 }
2055 
2056 string CShowBlastDefline::x_FormatPsi(SDeflineInfo* sdl, bool &first_new)
2057 {
2058  string defline = m_DeflineTemplates->defLineTmpl;
2059  string show_new,psi_new,psi_new_accesible,show_checked,replaceBy,psiNewSeq;
2060  if((m_Option & eShowNewSeqGif)) {
2061  replaceBy = (sdl->is_new && first_new) ? m_DeflineTemplates->psiFirstNewAnchorTmpl : "";
2062  first_new = (sdl->is_new && first_new) ? false : first_new;
2063  if (!sdl->is_new) {
2064  show_new = "hidden";
2065  }
2066  if (sdl->is_new && m_StepNumber > 1) {
2067  psi_new = "psi_new";
2068  psi_new_accesible = "psiNw";
2069  psiNewSeq = "on";
2070  }
2071  else {
2072  psiNewSeq = "off";
2073  }
2074 
2075  if(!sdl->was_checked) {
2076  show_checked = "hidden";
2077  }
2078  string psiUsedToBuildPssm = (sdl->was_checked) ? "on" : "off";
2079 
2080 
2081  defline = CAlignFormatUtil::MapTemplate(defline,"first_new",replaceBy);
2082  defline = CAlignFormatUtil::MapTemplate(defline,"psi_new_gi",show_new);
2083  defline = CAlignFormatUtil::MapTemplate(defline,"psi_new_gi_hl",psi_new);
2084  defline = CAlignFormatUtil::MapTemplate(defline,"psi_new_gi_accs",psi_new_accesible);//insert for accesibilty
2085  defline = CAlignFormatUtil::MapTemplate(defline,"psi_checked_gi",show_checked);
2086 
2087  defline = CAlignFormatUtil::MapTemplate(defline,"psi_new_seq",psiNewSeq);
2088  defline = CAlignFormatUtil::MapTemplate(defline,"psi_used_in_pssm",psiUsedToBuildPssm);
2089  }
2090 
2091  replaceBy = (m_Option & eCheckboxChecked) ? m_DeflineTemplates->psiGoodGiHiddenTmpl : "";//<@psi_good_gi@>
2092  defline = CAlignFormatUtil::MapTemplate(defline,"psi_good_gi",replaceBy);
2093 
2094  replaceBy = (m_Option & eCheckboxChecked) ? "checked=\"checked\"" : "";
2095  defline = CAlignFormatUtil::MapTemplate(defline,"gi_checked",replaceBy);
2096  if(sdl->gi > ZERO_GI) {
2097  defline = CAlignFormatUtil::MapTemplate(defline,"psiGi",NStr::NumericToString(sdl->gi));
2098  }
2099  else {
2100  defline = CAlignFormatUtil::MapTemplate(defline,"psiGi",sdl->textSeqID);
2101  }
2102 
2103  return defline;
2104 }
2105 
2106 
2107 
2108 
2110 {
2111  SDeflineFormattingInfo* sdlFormatInfo = new SDeflineFormattingInfo;
2112  SDeflineInfo* sdl = x_GetDeflineInfo(sci->id, sci->use_this_seqid, sci->blast_rank);
2113 
2114  string dflGi = (m_Option & eShowGi) && (sdl->gi > ZERO_GI) ? "gi|" + NStr::NumericToString(sdl->gi) + "|" : "";
2115  string seqid;
2116  if(!sdl->id.Empty()){
2117  if(!(sdl->id->AsFastaString().find("gnl|BL_ORD_ID") != string::npos || sdl->id->AsFastaString().find("lcl|Subject_") != string::npos)) {
2118  sdl->id->GetLabel(&seqid, CSeq_id::eContent);
2119  }
2120  }
2121 
2122  sdlFormatInfo->dfln_url = sdl->id_url;
2123 
2124  sdlFormatInfo->dfln_rid = m_Rid;
2125  sdlFormatInfo->dfln_gi = dflGi;
2126  sdlFormatInfo->dfln_seqid = seqid;
2127 
2128 
2129  string descr = (!sdl->defline.empty()) ? sdl->defline : "None provided";
2130  s_LimitDescrLength(descr);
2131 
2132  sdlFormatInfo->dfln_defline = CHTMLHelper::HTMLEncode(descr);
2133 
2134  descr = (!sdl->fullDefline.empty()) ? sdl->fullDefline : seqid;
2135  s_LimitDescrLength(descr);
2136  sdlFormatInfo->full_dfln_defline = CHTMLHelper::HTMLEncode(descr);
2137 
2138 
2139 
2140  string deflId,deflFrmID,deflFastaSeq,deflAccs;
2141  if(sdl->gi == ZERO_GI) {
2142  sdl->id->GetLabel(& deflId, CSeq_id::eContent);
2143  deflFrmID = CAlignFormatUtil::GetLabel(sdl->id);//Just accession without db part like GNOMON: or ti:
2144  deflFastaSeq = NStr::TruncateSpaces(sdl->alnIDFasta);
2145  deflAccs = sdl->id->AsFastaString();
2146  }
2147  else {
2148  deflFrmID = deflId = NStr::NumericToString(sdl->gi);
2149  deflFastaSeq = "gi|" + NStr::NumericToString(sdl->gi);
2150  deflFastaSeq = NStr::TruncateSpaces(sdl->alnIDFasta);
2151  sdl->id->GetLabel(&deflAccs, CSeq_id::eContent);
2152  }
2153 
2154  sdlFormatInfo->dfln_id = deflId;
2155  sdlFormatInfo->dflnFrm_id = deflFrmID;
2156  sdlFormatInfo->dflnFASTA_id = deflFastaSeq;
2157  sdlFormatInfo->dflnAccs =deflAccs;
2158 
2159  sdlFormatInfo->score_info = sci->bit_string;
2160  sdlFormatInfo->dfln_hspnum = NStr::IntToString(sci->hspNum);
2161  sdlFormatInfo->dfln_alnLen = NStr::NumericToString(sci->totalLen);
2162  sdlFormatInfo->dfln_blast_rank = NStr::IntToString(m_StartIndex + sci->blast_rank);
2163  sdlFormatInfo->total_bit_string = sci->total_bit_string;
2164  sdlFormatInfo->percent_coverage = NStr::IntToString(sci->percent_coverage);
2165  sdlFormatInfo->evalue_string = sci->evalue_string;
2167  m_SdlFormatInfoVec.push_back(sdlFormatInfo);
2168 }
2169 
2170 
2171 vector <CShowBlastDefline::SDeflineFormattingInfo *> CShowBlastDefline::GetFormattingInfo(void)
2172 {
2173  /*Note we can't just show each alnment as we go because we will
2174  need to show defline only once for all hsp's with the same id*/
2175 
2176  bool is_first_aln = true;
2177  size_t num_align = 0;
2178  CConstRef<CSeq_id> previous_id, subid;
2179 
2180  CSeq_align_set hit;
2181  m_QueryLength = 1;
2182 
2183  //prepare defline
2184 
2185 
2186  for (CSeq_align_set::Tdata::const_iterator iter = m_AlnSetRef->Get().begin();
2187  iter != m_AlnSetRef->Get().end() && num_align < m_NumToShow;
2188  iter++)
2189  {
2190 
2191  if (is_first_aln) {
2192  m_QueryLength = m_MasterRange ? m_MasterRange->GetLength() : m_ScopeRef->GetBioseqHandle((*iter)->GetSeq_id(0)).GetBioseqLength();
2193  }
2194 
2195  subid = &((*iter)->GetSeq_id(1));
2196 
2197  if(!is_first_aln && !(subid->Match(*previous_id))) {
2198 
2199  SScoreInfo* sci = x_GetScoreInfoForTable(hit, num_align);
2200  if(sci) {
2201  x_InitFormattingInfo(sci);
2202  hit.Set().clear();
2203  }
2204 
2205  num_align++; // Only increment if new subject ID found.
2206  }
2207  if (num_align < m_NumToShow) { //no adding if number to show already reached
2208  hit.Set().push_back(*iter);
2209  }
2210  is_first_aln = false;
2211  previous_id = subid;
2212  }
2213  //the last hit
2214  SScoreInfo* sci = x_GetScoreInfoForTable(hit, num_align);
2215 
2216  if(sci) {
2217  x_InitFormattingInfo(sci);
2218  hit.Set().clear();
2219  }
2220 
2221  return m_SdlFormatInfoVec;
2222 }
2223 
2224 
2225 END_SCOPE(align_format)
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
#define static
User-defined methods of the data storage class.
Declares class to display one-line descriptions at the top of the BLAST report.
static const char kLinkoutOrderStr[]
Default linkout order.
static const char kStructure_Overview[]
structure overview
static CAlignFormatUtil::SSeqAlignSetCalcParams * GetSeqAlignSetCalcParamsFromASN(const objects::CSeq_align_set &alnSet)
static string GetIDUrl(SSeqURLInfo *seqUrlInfo, const objects::CSeq_id &id, objects::CScope &scope)
Create URL for seqid.
static CAlignFormatUtil::SSeqAlignSetCalcParams * GetSeqAlignSetCalcParams(const objects::CSeq_align_set &aln, int queryLength, bool do_translation)
static bool IsMixedDatabase(const objects::CSeq_align_set &alnset, objects::CScope &scope, ILinkoutDB *linkoutdb, const string &mv_build_name)
static list< string > GetFullLinkoutUrl(const list< CRef< objects::CBlast_def_line > > &bdl, const string &rid, const string &cdd_rid, const string &entrez_term, bool is_na, bool structure_linkout_as_group, bool for_alignment, int cur_align, string &linkoutOrder, TTaxId taxid, string &database, int query_number, string &user_url, string &preComputedResID, ILinkoutDB *linkoutdb, const string &mv_build_name)
Get linkout membership for for the list of blast deflines.
static void GetAlnScores(const objects::CSeq_align &aln, int &score, double &bits, double &evalue, int &sum_n, int &num_ident, list< TGi > &use_this_gi)
Extract score info from blast alingment.
static void BuildFormatQueryString(CCgiContext &ctx, string &cgi_query)
static void GetScoreString(double evalue, double bit_score, double total_bit_score, int raw_score, string &evalue_str, string &bit_score_str, string &total_bit_score_str, string &raw_score_str)
format evalue and bit_score
static string GetBareId(const objects::CSeq_id &id)
Get sequence id with no database source (bare accession)
static string MapTemplate(string inpString, string tmplParamName, Int8 templParamVal)
Replace template tags by real data.
static bool MatchSeqInSeqList(TGi cur_gi, CRef< objects::CSeq_id > &seqID, list< string > &use_this_seq, bool *isGiList=NULL)
Matches text seqID or gi with the list of seqIds or gis.
static int GetSeqLinkoutInfo(objects::CBioseq::TId &cur_id, ILinkoutDB **linkoutdb, const string &mv_build_name, TGi gi=INVALID_GI)
static CRef< objects::CSeq_id > GetDisplayIds(const objects::CBioseq_Handle &handle, const objects::CSeq_id &aln_id, list< TGi > &use_this_gi, TGi &gi, TTaxId &taxid)
Scan the the list of blast deflines and find seqID to be use in display.
static list< string > GetLinkoutUrl(int linkout, const objects::CBioseq::TId &ids, const string &rid, const string &cdd_rid, const string &entrez_term, bool is_na, TGi first_gi, bool structure_linkout_as_group, bool for_alignment, int cur_align, string preComputedResID)
Get the list of urls for linkouts.
static int GetPercentMatch(int numerator, int denominator)
function for calculating percent match for an alignment.
static void AddSpace(CNcbiOstream &out, size_t number)
Add the specified white space.
static string MapSpaceTemplate(string inpString, string tmplParamName, string templParamVal, unsigned int maxParamLength, int spacesFormatFlag=eSpacePosAtLineEnd)
Replace template tags by real data and calculate and add spaces dependent on maxParamLength and space...
static string GetLabel(CConstRef< objects::CSeq_id > id, bool with_version=false)
Return a label for an ID Tries to recreate behavior of GetLabel before a change that prepends "ti|" t...
CBioseq_Handle –.
bool IsNa(void) const
Definition: Bioseq.cpp:345
void PutTargetGiFirst(TGi gi)
Place the CBlast_def_line object which contains the requested gi as the first in the list (if found)
Class for computing sequences' titles ("definitions").
CNcbiRegistry –.
Definition: ncbireg.hpp:913
CScope –.
Definition: scope.hpp:92
static void GetTaxInfo(TTaxId taxid, SSeqDBTaxInfo &info)
Get taxonomy information.
Definition: seqdb.cpp:1105
static CRef< CBlast_def_line_set > ExtractBlastDefline(const CBioseq &bioseq)
Extract a Blast-def-line-set object from a Bioseq retrieved by CSeqDB.
Definition: seqdbvol.cpp:1247
const CSeq_id & GetSeq_id(TDim row) const
Get seq-id (the first one if segments have different ids).
Definition: Seq_align.cpp:317
size_t m_MaxEvalueLen
Eval header size.
int m_StartIndex
The start index of defline for PSI blast description table.
void x_InitLinkOutInfo(SDeflineInfo *sdl, objects::CBioseq::TId &cur_id, int blast_rank, bool getIdentProteins)
string m_MapViewerBuildName
mapviewer build name associated with the sequences in the BLAST database out of which the results are...
void x_FillDeflineAndId(const objects::CBioseq_Handle &handle, const objects::CSeq_id &aln_id, list< string > &use_this_seqid, SDeflineInfo *sdl, int blast_rank)
Internal function to fill defline info.
CShowBlastDefline(const objects::CSeq_align_set &seqalign, objects::CScope &scope, size_t line_length=65, size_t deflines_to_show=kDfltArgNumDescriptions, bool translated_nuc_alignment=false, CRange< TSeqPos > *master_range=NULL)
Constructors.
CRef< objects::CScope > m_ScopeRef
Scope to fetch sequence.
string x_FormatClusterMemData(SDeflineInfo *sdl, string defline)
string x_FormatPsi(SDeflineInfo *sdl, bool &first_new)
Format PSI blat related data.
int m_Option
Display options.
bool x_CheckForStructureLink()
Checks the first X deflines (currently X is 200) for a structure link.
void x_DisplayDefline(CNcbiOstream &out)
Display defline for regular output.
SScoreInfo * x_GetScoreInfoForTable(const objects::CSeq_align_set &aln, int blast_rank)
Internal function to return score info.
static void GetBioseqHandleDeflineAndId(const objects::CBioseq_Handle &handle, list< TGi > &use_this_gi, string &seqid, string &defline, bool show_gi=true, TGi this_gi_first=INVALID_GI)
Returns sequence id and a BLAST defline as strings, given a Bioseq handle and a list of gis.
PsiblastStatus m_PsiblastStatus
string m_BlastType
Blast type.
SScoreInfo * x_GetScoreInfo(const objects::CSeq_align &aln, int blast_rank)
Internal function to return score info.
PsiblastSeqStatus
PSI-BLAST sequence status (applicable in HTML only)
@ eGoodSeq
above the threshold evalue
@ eUnknown
Uninitialized.
@ eCheckedSeq
user checked
@ eRepeatSeq
previously already found
SAppLogInfo * m_AppLogInfo
static void GetSeqIdList(const objects::CBioseq_Handle &bh, list< CRef< objects::CSeq_id > > &ids)
Converts a Bioseq handle's sequence id type into a list of objects::CSeq_id references,...
void DisplayBlastDefline(CNcbiOstream &out)
Display defline.
string m_Database
Database name.
bool m_TranslatedNucAlignment
used to calculate the alignment length
int m_SkipFrom
seq aligns to be skipped
vector< SDeflineFormattingInfo * > m_SdlFormatInfoVec
void DisplayOneDefline(CNcbiOstream &out, SDeflineInfo *sdl, SScoreInfo *iter, bool &is_first)
Display one defline.
SDeflineInfo * x_GetDeflineInfo(CConstRef< objects::CSeq_id > id, list< string > &use_this_seqid, int blast_rank)
Internal function to return defline info.
void x_DisplayDeflineTableBody(CNcbiOstream &out)
Display defline table contents for table output.
void x_DisplayDeflineTableTemplate(CNcbiOstream &out)
Display defline for table output using templates.
static string GetSeqIdListString(const list< CRef< objects::CSeq_id > > &id, bool show_gi)
Creates a '|' delimited string, corresponding to a list of Seq-ids.
string x_FormatDeflineTableLine(SDeflineInfo *sdl, SScoreInfo *iter, bool &first_new)
Format defline.
SDeflineInfo * GetDeflineInfo(CConstRef< objects::CSeq_id > id, list< string > &use_this_seqid, int blast_rank)
Get one defline info.
size_t m_MaxScoreLen
Score header size.
string x_FormatClusterMemDataTxt(SDeflineInfo *sdl, string defline)
ILinkoutDB * m_LinkoutDB
Reference to LinkoutDB implementation. Not owned by this class.
vector< SScoreInfo * > m_ScoreList
List containing score info for all seqalign.
CCgiContext * m_Ctx
void x_InitDefline(void)
Initialize defline params for regular output.
string m_PreComputedResID
CDD precomputed results ID.
string m_Rid
blast request id
int m_PositionIndex
result position index for multiple query case
void Init(void)
Initialize defline params.
string x_FormatDeflineTableLineCSV(SDeflineInfo *sdl, SScoreInfo *iter)
size_t m_MaxPercentIdentityLen
string m_LinkoutOrder
Linkout order for display.
size_t m_LineLen
Line length.
void DisplayBlastDeflineTable(CNcbiOstream &out)
string x_FormatDeflineTableLineText(SDeflineInfo *sdl, SScoreInfo *iter)
vector< CShowBlastDefline::SDeflineFormattingInfo * > GetFormattingInfo(void)
Get deflines formatting info.
size_t m_NumToShow
Number of seqalign hits to show.
void x_DisplayDeflineTableTemplateCSV(CNcbiOstream &out)
string m_EntrezTerm
entrez term
void Display(CNcbiOstream &out)
Display defline.
void x_DisplayDeflineTableTemplateText(CNcbiOstream &out)
void x_DisplayDeflineTable(CNcbiOstream &out)
Display defline for table output.
string x_FormatDeflineTableHeaderText(void)
string m_CddRid
cdd blast request id
SDeflineTemplates * m_DeflineTemplates
blast defline templates
void x_InitFormattingInfo(SScoreInfo *sci)
CConstRef< objects::CSeq_align_set > m_AlnSetRef
Internal data with score information for each defline.
unique_ptr< CNcbiIfstream > m_ConfigFile
Internal configure file, i.e. .ncbirc.
@ eNewPass
Sequences are newly found in current pass.
@ eFirstPass
First pass. Default.
@ eRepeatPass
Sequences were found in previous pass.
void x_InitDeflineTable(void)
Initialize defline params for table output.
size_t m_MaxTotalScoreLen
Total score header size.
int m_QueryNumber
query number
unique_ptr< CNcbiRegistry > m_Reg
bool m_StructureLinkout
Indicates if 'Related structures' link should show.
TIdString2SeqStatus * m_SeqStatus
hash table to track psiblast status for each sequence
string x_FormatSeqSetHeaders(int isGenomic, bool formatHeaderSort)
Format headers for Transcrit/Genomic seq set.
CRange< TSeqPos > * m_MasterRange
blast sub-sequnce query
void x_GetTaxonomyInfoForTaxID(SDeflineInfo *sdl, SSeqDBTaxInfo &taxInfo)
container_type::const_iterator const_iterator
Definition: map.hpp:53
const_iterator end() const
Definition: map.hpp:152
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
#define Len
Blast defline related defines.
@ eGenomicSeq
Is a genomic sequence.
@ eStructure
Add Linkout for structure.
std::ofstream out("events_result.xml")
main entry point for tests
#define false
Definition: bool.h:36
#define ZERO_TAX_ID
Definition: ncbimisc.hpp:1115
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define ZERO_GI
Definition: ncbimisc.hpp:1088
#define GI_TO(T, gi)
Definition: ncbimisc.hpp:1085
const CCgiEntry & GetRequestValue(const string &name, bool *is_found=0) const
Definition: cgictx.cpp:288
#define NULL
Definition: ncbistd.hpp:225
static string HTMLEncode(const string &str, THTMLEncodeFlags flags=fEncodeAll)
HTML encodes a string. E.g. <.
Definition: htmlhelper.cpp:146
const string AsFastaString(void) const
Definition: Seq_id.cpp:2266
TGi FindGi(const container &ids)
Return gi from id list if exists, return 0 otherwise.
Definition: Seq_id.hpp:1041
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Append a label for this Seq-id to the supplied string.
Definition: Seq_id.cpp:2040
bool Match(const CSeq_id &sid2) const
Match() - TRUE if SeqIds are equivalent.
Definition: Seq_id.hpp:1065
static int WorstRank(const CRef< CSeq_id > &id)
Definition: Seq_id.hpp:776
static int Score(const CRef< CSeq_id > &id)
Wrappers for use with FindBestChoice from <corelib/ncbiutil.hpp>
Definition: Seq_id.hpp:772
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:605
@ eFasta
Tagged ID in NCBI's traditional FASTA style.
Definition: Seq_id.hpp:607
TSeqPos GetLength(const CSeq_id &id, CScope *scope)
Get sequence length if scope not null, else return max possible TSeqPos.
string GenerateDefline(const CBioseq_Handle &bsh, TUserFlags flags=0)
Main method.
vector< CSeq_id_Handle > TId
TBioseqCore GetBioseqCore(void) const
Get bioseq core structure.
bool Empty(void) const THROWS_NONE
Check if CConstRef is empty – not pointing to any object which means having a null value.
Definition: ncbiobj.hpp:1385
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 Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
#define NCBI_INT8_FORMAT_SPEC
Definition: ncbitype.h:214
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
position_type GetLength(void) const
Definition: range.hpp:158
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
static string DoubleToString(double value, int precision=-1, TNumToStringFlags flags=0)
Convert double to string.
Definition: ncbistr.hpp:5189
#define kEmptyStr
Definition: ncbistr.hpp:123
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3452
#define NPOS
Definition: ncbistr.hpp:133
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5086
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
Definition: ncbistr.cpp:2882
#define NcbiEmptyString
Definition: ncbistr.hpp:122
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
static string TruncateSpaces(const string &str, ETrunc where=eTrunc_Both)
Truncate whitespace in a string.
Definition: ncbistr.cpp:3177
@ eReverseSearch
Search in a backward direction.
Definition: ncbistr.hpp:1947
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
C::value_type FindBestChoice(const C &container, F score_func)
Find the best choice (lowest score) for values in a container.
Definition: ncbiutil.hpp:250
const Tdata & Get(void) const
Get the member data.
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
TStr & SetStr(void)
Select the variant.
Definition: Object_id_.hpp:304
Tdata & Set(void)
Assign a value to data member.
const Tdata & Get(void) const
Get the member data.
bool IsLocal(void) const
Check if variant Local is selected.
Definition: Seq_id_.hpp:775
bool IsGi(void) const
Check if variant Gi is selected.
Definition: Seq_id_.hpp:883
@ e_Gi
GenInfo Integrated Database.
Definition: Seq_id_.hpp:106
@ e_Local
local use
Definition: Seq_id_.hpp:95
const TId & GetId(void) const
Get the Id member data.
Definition: Bioseq_.hpp:290
list< CRef< CSeq_id > > TId
Definition: Bioseq_.hpp:94
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
HTML library helper classes and functions.
char * buf
int i
int len
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2107
int strncmp(const char *str1, const char *str2, size_t count)
Definition: odbc_utils.hpp:133
Defines NCBI C++ exception handling.
Process information in the NCBI Registry, including working with configuration files.
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
Useful/utility classes and methods.
const double E
T min(T x_, T y_)
std::istream & in(std::istream &in_, double &x_)
The Object manager core.
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Definition: pcre_exec.c:513
USING_SCOPE(objects)
static const string kQueryCov
Definition: showdefline.cpp:98
static const string kEvalue
Definition: showdefline.cpp:79
static void s_DisplayStructureOverview(CNcbiOstream &out, const string &rid, const string &param, const string &entrez_term)
static const string kPsiblastCheckbox
static const string kLenAbbr
static const string kIdentLine2
Definition: showdefline.cpp:96
static const string kEllipsis
Definition: showdefline.cpp:93
static const int kMaxPercentIdentityLen
static const string kScoreLine2
Definition: showdefline.cpp:97
static const string kCoverage
Definition: showdefline.cpp:92
static const string kPercent
Definition: showdefline.cpp:89
static const string kCommon
static const string kPsiblastCheckedGif
static const int kMaxTaxonomyNameLengthExt
static const int kMaxTaxonomyNameLength
static string kOneSpaceMargin
Definition: showdefline.cpp:70
static const string kNewSeqHeader
Definition: showdefline.cpp:83
static const string kScore
Definition: showdefline.cpp:75
static const string kAccession
static const string kDescription
static const string kName
static const int kMaxAccLength
static const string kPsiblastNewSeqGif
static const string kAncestor
static const string kNumOf
static const string kQueryCovLine2
Definition: showdefline.cpp:99
static const string kBits
Definition: showdefline.cpp:77
static const string kPsiblastCheckedBackgroundGif
static void s_DisplayCheckboxChecked(CNcbiOstream &out, TGi gi)
static const string kClusterTitle
static void s_DisplayCheckbox(CNcbiOstream &out, TGi gi)
static const string kN
Definition: showdefline.cpp:81
static const string kPsiblastEvalueLink
static const string kHighest
Definition: showdefline.cpp:90
static const string kMaxScore
Definition: showdefline.cpp:85
static const int kMaxDispNumberLength
static const int kMaxDescrLength
static const string kAccAbbr
static const string kE
Definition: showdefline.cpp:76
static const string kValue
Definition: showdefline.cpp:80
static const string kTotalScore
Definition: showdefline.cpp:86
static const string kIdentity
Definition: showdefline.cpp:88
static const string kPerc
static string kTwoSpaceMargin
Definition: showdefline.cpp:71
static const string kTaxid
static const string kMax
Definition: showdefline.cpp:95
static const string kTotal
Definition: showdefline.cpp:87
static void s_DisplayDescrColumnHeader(CNcbiOstream &out, int currDisplaySort, string query_buf, int columnDisplSort, int columnHspSort, string columnText, int max_data_len, bool html)
static const string kMember
static const string kRepeatHeader
Definition: showdefline.cpp:82
static const string kHeader
Definition: showdefline.cpp:74
static void s_LimitDescrLength(string &descr, size_t maxDescrLength=kMaxDescrLength)
static const string kPsiblastCheckboxChecked
static const string kTaxa
static const string kCluster
static const string kPsiblastNewSeqBackgroundGif
static const string kQuery
Definition: showdefline.cpp:91
static const string kScientific
Structure that holds information needed for creation seqID URL in descriptions and alignments.
bool useTemplates
bool indicating that templates should be used when contsructing links
bool advancedView
bool indicating that advanced view design option should be used when contsructing links
string resourcesUrl
URL(s) to other resources from .ncbirc.
vector< string > queryCoverageVec
vector< string > percentIdentityVec
Data Representing each defline.
CConstRef< objects::CSeq_id > id
vector< SClusterMemberInfo > clustMemList
string psiFirstNewAnchorTmpl
first new seq anchor template (psi blast)
string scoreInfoTmpl
score info template
string seqInfoTmpl
sequence infor template
string psiGoodGiHiddenTmpl
good gi hidden field tewmplate (psi blast)
string defLineTmpl
whole defilne template
string subHeaderSort
subheader sort template for Transcript/Genomic case
string subHeaderTmpl
subheader templates for Transcript/Genomic case
CConstRef< objects::CSeq_id > id
SSeqDBTaxInfo.
string common_name
Common name, such as "noisy night monkey".
string blast_name
A simple category name, such as "birds".
string scientific_name
Scientific name, such as "Aotus vociferans".
TTaxId taxid
An identifier for this species or taxonomic group.
#define _ASSERT
#define const
Definition: zconf.h:232
#define N
Definition: crc32.c:57
Modified on Mon Jul 15 05:36:01 2024 by modify_doxy.py rev. 669887