1
/* $Id: showalignwrap.cpp,v 1.2 2006/03/07 17:06:30 jianye Exp $
2
* ===========================================================================
5
* National Center for Biotechnology Information
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.
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
22
* Please cite the author in any work or product based on this material.
24
* ===========================================================================
29
* c adaptor to showalign.cpp
34
#include <corelib/ncbiapp.hpp>
35
#include <corelib/ncbiargs.hpp>
36
#include <corelib/ncbienv.hpp>
37
#include <corelib/ncbistre.hpp>
38
#include <serial/iterator.hpp>
39
#include <serial/objistr.hpp>
40
#include <serial/objostr.hpp>
41
#include <serial/serial.hpp>
42
#include <objtools/blast_format/showalign.hpp>
43
#include <showalignwrap.h>
44
#include <ctools/asn_converter.hpp>
45
#include <objtools/data_loaders/blastdb/bdbloader.hpp>
46
#include <objmgr/object_manager.hpp>
47
#include <objmgr/gbloader.hpp>
48
#include <algo/blast/api/blast_aux.hpp>
57
s_BlastFormat_ConvertToCppLoc(list <CRef<blast::CSeqLocInfo> >& target_mask,
58
ValNodePtr source_mask)
60
DECLARE_ASN_CONVERTER(CSeq_loc, SeqLoc, convertor_feat);
61
ValNodePtr mask_temp = source_mask;
64
switch(mask_temp->choice) {
65
case Blast_mask_frame_minus1: frame = -1; break;
66
case Blast_mask_frame_minus2: frame = -2; break;
67
case Blast_mask_frame_minus3: frame = -3; break;
68
case Blast_mask_frame_plus1: frame = 1; break;
69
case Blast_mask_frame_plus2: frame = 2; break;
70
case Blast_mask_frame_plus3: frame = 3; break;
71
default: frame = 0; break;
75
SeqLocPtr slp = (SeqLocPtr) mask_temp->data.ptrvalue;
77
if (slp->choice == SEQLOC_PACKED_INT){
78
for (ValNodePtr vnpTemp2 = (ValNodePtr) slp->data.ptrvalue; vnpTemp2; vnpTemp2 = vnpTemp2->next){
79
CRef<CSeq_loc> seqloc(new CSeq_loc());
80
convertor_feat.FromC((SeqLocPtr)vnpTemp2, &*seqloc);
81
CSeq_interval* interval = &seqloc->SetInt();
82
CRef<blast::CSeqLocInfo> seqlocinfo
83
(new blast::CSeqLocInfo(interval, frame));
85
target_mask.push_back(seqlocinfo);
87
} else if (slp->choice == SEQLOC_INT) {
88
CRef<CSeq_loc> seqloc(new CSeq_loc());
89
convertor_feat.FromC(slp, &*seqloc);
90
CRef<blast::CSeqLocInfo> seqlocinfo
91
(new blast::CSeqLocInfo(&seqloc->SetInt(), frame));
92
target_mask.push_back(seqlocinfo);
94
mask_temp=mask_temp->next;
99
void DisplayAlign(SeqAlignPtr align, Int4 line_len, BioseqPtr query,
100
BioseqPtr subject, CharPtr program, Int4Ptr PNTR matrix,
101
ValNodePtr mask, Int4 mask_char, Int4 mask_color,
102
Boolean cds_translation, Int4 view, FILE *fp)
105
CSeq_align_set seqalignSet;
106
DECLARE_ASN_CONVERTER(CSeq_align, SeqAlign, convertor_seqalign);
108
for (SeqAlignPtr salpTemp = align; salpTemp; salpTemp = salpTemp->next){
109
CRef<CSeq_align> csal(new CSeq_align());
110
convertor_seqalign.FromC(salpTemp, &*csal);
111
seqalignSet.Set().push_back(csal);
114
CRef<CObjectManager> obj;
115
obj = CObjectManager::GetInstance();
116
CGBDataLoader::RegisterInObjectManager(*obj);
117
CRef<CScope> scope (new CScope(*obj));
118
scope->AddDefaults();
121
DECLARE_ASN_CONVERTER(CBioseq, Bioseq, convertor2);
123
CRef<CBioseq> cbsp(new CBioseq());
124
convertor2.FromC(subject, &*cbsp);
125
CRef<CSeq_entry> entry(new CSeq_entry());
126
entry->SetSeq(*cbsp);
127
scope->AddTopLevelSeqEntry(*entry);
129
DECLARE_ASN_CONVERTER(CBioseq, Bioseq, convertor3);
130
CRef<CBioseq> cbsp2(new CBioseq());
131
convertor3.FromC(query, &*cbsp2);
132
CRef<CSeq_entry> entry2(new CSeq_entry());
133
entry2->SetSeq(*cbsp2);
134
scope->AddTopLevelSeqEntry(*entry2);
135
//auto_ptr<CObjectOStream> out2(CObjectOStream::Open(eSerial_AsnText, cout));
136
//*out2 << seqalignSet;
139
list <CRef<blast::CSeqLocInfo> > mask_loc;
141
s_BlastFormat_ConvertToCppLoc(mask_loc, mask);
143
int the_matrix[CDisplaySeqalign::ePMatrixSize][CDisplaySeqalign::ePMatrixSize];
145
for(int i = 0; i < CDisplaySeqalign::ePMatrixSize; i ++){
146
for(int j = 0; j < CDisplaySeqalign::ePMatrixSize; j ++){
147
the_matrix[i][j] = matrix[i][j];
151
CDisplaySeqalign cds(seqalignSet, *scope, &mask_loc, NULL,
152
matrix ? the_matrix : NULL);
154
if(strcmp(program, "tblastx") == 0){
155
option += CDisplaySeqalign::eTranslateNucToNucAlignment;
157
option += CDisplaySeqalign::eShowBlastStyleId;
158
if (cds_translation) {
159
option += CDisplaySeqalign::eShowCdsFeature;
161
option += CDisplaySeqalign::eShowBlastInfo;
162
option += CDisplaySeqalign::eShowNoDeflineInfo;
163
option += CDisplaySeqalign::eHtml;
165
option += CDisplaySeqalign::eColorDifferentBases;
166
option += CDisplaySeqalign::eShowIdentity;
168
option += CDisplaySeqalign::eShowMiddleLine;
172
cds.SetSeqLocChar(CDisplaySeqalign::eLowerCase);
173
} else if (mask_char == 0){
174
if(strcmp(program, "blastn") == 0){
175
cds.SetSeqLocChar (CDisplaySeqalign::eN);
177
cds.SetSeqLocChar (CDisplaySeqalign::eX);
181
if (mask_color == 2){
182
cds.SetSeqLocColor(CDisplaySeqalign::eGrey);
183
} else if (mask_color == 3){
184
cds.SetSeqLocColor(CDisplaySeqalign::eRed);
187
if(strcmp(program, "blastn") == 0){//blastn
188
cds.SetMiddleLineStyle (CDisplaySeqalign::eBar);
189
cds.SetAlignType(CDisplaySeqalign::eNuc);
191
cds.SetMiddleLineStyle (CDisplaySeqalign::eChar);
192
cds.SetAlignType(CDisplaySeqalign::eProt);
195
cds.SetAlignOption(option);
196
cds.DisplaySeqalign(oss);
197
string output = (string)(CNcbiOstrstreamToString(oss));
198
fprintf(fp, "%s", output.c_str());
204
*============================================================
205
*$Log: showalignwrap.cpp,v $
206
*Revision 1.2 2006/03/07 17:06:30 jianye
209
*Revision 1.1 2006/01/05 17:28:57 jianye
210
*for wblast2 to use new formatter