~ubuntu-branches/ubuntu/edgy/ncbi-tools6/edgy

« back to all changes in this revision

Viewing changes to network/wwwblast/Src/showalignwrap.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: showalignwrap.cpp,v 1.2 2006/03/07 17:06:30 jianye Exp $
 
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
 *   c adaptor to showalign.cpp
 
30
 *
 
31
 */
 
32
 
 
33
 
 
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>
 
49
 
 
50
 
 
51
 
 
52
USING_SCOPE(ncbi);
 
53
USING_SCOPE(objects);
 
54
 
 
55
 
 
56
static void  
 
57
s_BlastFormat_ConvertToCppLoc(list <CRef<blast::CSeqLocInfo> >& target_mask,
 
58
                              ValNodePtr source_mask)
 
59
{
 
60
    DECLARE_ASN_CONVERTER(CSeq_loc, SeqLoc, convertor_feat); 
 
61
    ValNodePtr  mask_temp = source_mask;
 
62
    while(mask_temp){
 
63
        int frame(0);
 
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;
 
72
        }
 
73
      
 
74
 
 
75
        SeqLocPtr slp = (SeqLocPtr) mask_temp->data.ptrvalue;
 
76
        
 
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));
 
84
                
 
85
                target_mask.push_back(seqlocinfo);
 
86
            }
 
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);
 
93
        }
 
94
        mask_temp=mask_temp->next;
 
95
        
 
96
    }
 
97
 
98
 
 
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)
 
103
{
 
104
   
 
105
    CSeq_align_set seqalignSet;
 
106
    DECLARE_ASN_CONVERTER(CSeq_align, SeqAlign, convertor_seqalign);
 
107
    
 
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);
 
112
    }
 
113
    
 
114
    CRef<CObjectManager> obj;
 
115
    obj = CObjectManager::GetInstance();
 
116
    CGBDataLoader::RegisterInObjectManager(*obj);       
 
117
    CRef<CScope> scope (new CScope(*obj));
 
118
    scope->AddDefaults();
 
119
    
 
120
  
 
121
    DECLARE_ASN_CONVERTER(CBioseq, Bioseq, convertor2);  
 
122
  
 
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);
 
128
    
 
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;
 
137
    int option = 0;
 
138
 
 
139
    list <CRef<blast::CSeqLocInfo> > mask_loc;
 
140
 
 
141
    s_BlastFormat_ConvertToCppLoc(mask_loc, mask);
 
142
  
 
143
    int the_matrix[CDisplaySeqalign::ePMatrixSize][CDisplaySeqalign::ePMatrixSize];
 
144
    if(matrix){
 
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];
 
148
            }
 
149
        }
 
150
    }
 
151
    CDisplaySeqalign cds(seqalignSet,  *scope, &mask_loc, NULL, 
 
152
                         matrix ? the_matrix : NULL);
 
153
    CNcbiOstrstream oss;
 
154
    if(strcmp(program, "tblastx") == 0){
 
155
        option += CDisplaySeqalign::eTranslateNucToNucAlignment;
 
156
    }
 
157
    option += CDisplaySeqalign::eShowBlastStyleId;
 
158
    if (cds_translation) {
 
159
        option += CDisplaySeqalign::eShowCdsFeature;
 
160
    }
 
161
    option += CDisplaySeqalign::eShowBlastInfo;
 
162
    option += CDisplaySeqalign::eShowNoDeflineInfo;
 
163
    option += CDisplaySeqalign::eHtml;
 
164
    if (view == 2){
 
165
        option += CDisplaySeqalign::eColorDifferentBases;
 
166
        option += CDisplaySeqalign::eShowIdentity;
 
167
    } else {
 
168
        option += CDisplaySeqalign::eShowMiddleLine;
 
169
    }
 
170
    
 
171
    if (mask_char == 2){
 
172
        cds.SetSeqLocChar(CDisplaySeqalign::eLowerCase);
 
173
    } else if (mask_char == 0){
 
174
        if(strcmp(program, "blastn") == 0){
 
175
            cds.SetSeqLocChar (CDisplaySeqalign::eN);
 
176
        }else {
 
177
            cds.SetSeqLocChar (CDisplaySeqalign::eX);
 
178
        }
 
179
    }
 
180
    
 
181
    if (mask_color == 2){
 
182
        cds.SetSeqLocColor(CDisplaySeqalign::eGrey);
 
183
    } else if (mask_color == 3){
 
184
        cds.SetSeqLocColor(CDisplaySeqalign::eRed);
 
185
    }
 
186
    
 
187
    if(strcmp(program, "blastn") == 0){//blastn
 
188
        cds.SetMiddleLineStyle (CDisplaySeqalign::eBar);
 
189
        cds.SetAlignType(CDisplaySeqalign::eNuc);
 
190
    } else {
 
191
        cds.SetMiddleLineStyle (CDisplaySeqalign::eChar);
 
192
        cds.SetAlignType(CDisplaySeqalign::eProt);
 
193
    }
 
194
   
 
195
    cds.SetAlignOption(option);
 
196
    cds.DisplaySeqalign(oss);
 
197
    string output = (string)(CNcbiOstrstreamToString(oss));
 
198
    fprintf(fp, "%s", output.c_str());
 
199
   
 
200
}
 
201
 
 
202
 
 
203
/* 
 
204
*============================================================
 
205
*$Log: showalignwrap.cpp,v $
 
206
*Revision 1.2  2006/03/07 17:06:30  jianye
 
207
*correct mask char
 
208
*
 
209
*Revision 1.1  2006/01/05 17:28:57  jianye
 
210
*for wblast2 to use new formatter
 
211
*
 
212
 
 
213
*/