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

Go to the SVN repository for this file.

1 /* $Id: cuBlockFormater.cpp 33815 2007-05-04 17:18:18Z kazimird $
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: Charlie
27  *
28  * File Description:
29  *
30  * extend blocks
31  *
32  * ===========================================================================
33  */
34 #include <ncbi_pch.hpp>
36 
38 BEGIN_SCOPE(cd_utils)
39 
40 BlockFormater::BlockFormater(vector< CRef< CSeq_align > > & seqAlignVec, int masterSeqLen)
41 : m_seqAlignVec(seqAlignVec), m_masterLen(masterSeqLen), m_intersector(0)
42 {
43 }
44 
46 {
47  if (m_intersector)
48  delete m_intersector;
49 }
50 
52 {
53  m_refSeqAlign = sa;
54 }
55 
56 void BlockFormater::getOverlappingPercentages(vector<int>& percentages)
57 {
58  if (m_seqAlignVec.size() == 0)
59  return;
60  BlockIntersector intersector(m_masterLen);
61  int start = 0;
62  int refAlignmentLen = 0;
63  if (!m_refSeqAlign.Empty())
64  {
66  refAlignmentLen = bm.getTotalBlockLength();
67  intersector.addOneAlignment(bm);
68  }
69  else
70  {
71  BlockModel bm(m_seqAlignVec[0],false);
72  refAlignmentLen = bm.getTotalBlockLength();
73  intersector.addOneAlignment(bm);
74  percentages.push_back(100);
75  start = 1;
76  }
77  for (int i = start; i < m_seqAlignVec.size(); i++)
78  {
79  BlockModel bm(m_seqAlignVec[i], false);
80  intersector.addOneAlignment(bm);
81  BlockModel* intersectedBM = intersector.getIntersectedAlignment();
82  int score = (intersectedBM->getTotalBlockLength() * 100)/refAlignmentLen;
83  percentages.push_back(score);
84  delete intersectedBM;
85  intersector.removeOneAlignment(bm);
86  }
87 }
88 
89 //-1 find intersection for all the rows
90 //return the number of rows over the overlappingPercentage
91 int BlockFormater::findIntersectingBlocks(int overlappingPercentage)
92 {
93  if (m_seqAlignVec.size() == 0)
94  return 0;
95  if (m_intersector)
96  {
97  delete m_intersector;
98  }
100  int minAlignedLen = 0;
101  m_goodRows.clear();
102  m_badRows.clear();
103  int start = 0;
104  if (!m_refSeqAlign.Empty())
105  {
106  BlockModel bm(m_refSeqAlign,false);
107  minAlignedLen = bm.getTotalBlockLength() * overlappingPercentage/100;
109  }
110  else
111  {
112  BlockModel bm(m_seqAlignVec[0],false);
113  minAlignedLen = bm.getTotalBlockLength() * overlappingPercentage/100;
115  start = 1;
116  m_goodRows.push_back(0);
117  }
118  for (int i = start; i < m_seqAlignVec.size(); i++)
119  {
120  BlockModel bm(m_seqAlignVec[i], false);
123  if (intersectedBM->getTotalBlockLength() < minAlignedLen)
124  {
126  m_badRows.push_back(i);
127  }
128  else
129  m_goodRows.push_back(i);
130  delete intersectedBM;
131  }
132  return m_goodRows.size();
133 }
134 
135 int BlockFormater::getQualifiedRows(vector<int>& rows)
136 {
137  rows.assign(m_goodRows.begin(), m_goodRows.end());
138  return rows.size();
139 }
140 
142 {
143  rows.assign(m_badRows.begin(), m_badRows.end());
144  return rows.size();
145 }
146 
147 void BlockFormater::formatBlocksForQualifiedRows(list< CRef< CSeq_align > > & seqAlignList, const set<int>* forcedBreaks)
148 {
149  if (m_intersector == 0)
150  return;
151  cd_utils::BlockModel* finalBM = (forcedBreaks) ? m_intersector->getIntersectedAlignment(*forcedBreaks) : m_intersector->getIntersectedAlignment();
152  //format what's already in seqAlignList
153  list< CRef< CSeq_align > >::iterator lit = seqAlignList.begin();
154  for (; lit != seqAlignList.end(); lit++)
155  {
156  (*lit) = formatOneRow(*finalBM, *lit);
157  }
158  for (int i = 0; i < m_goodRows.size(); i++)
159  {
160  seqAlignList.push_back(formatOneRow(*finalBM, m_seqAlignVec[m_goodRows[i]]));
161  }
162  delete finalBM;
163 }
164 
165 //assume seqAlign.master and guide are on the same seq-loc
166 // and guide is a subset of seqAlign.master
168 {
169  BlockModelPair bmp(seqAlign);
170  pair<cd_utils::DeltaBlockModel*, bool> delta = guide - bmp.getMaster();
171  cd_utils::BlockModel& slave = bmp.getSlave();
172  pair<cd_utils::BlockModel*, bool> sum = slave + (*delta.first);
173  CRef< CSeq_align > result = sum.first->toSeqAlign(guide);
174  delete delta.first;
175  delete sum.first;
176  return result;
177 }
178 
179 END_SCOPE(cd_utils)
BlockIntersector * m_intersector
void setReferenceSeqAlign(const CRef< CSeq_align > sa)
int getQualifiedRows(vector< int > &rows)
void formatBlocksForQualifiedRows(list< CRef< CSeq_align > > &seqAlignVec, const set< int > *forcedBreaks=NULL)
vector< CRef< CSeq_align > > & m_seqAlignVec
int getDisqualifiedRows(vector< int > &rows)
vector< int > m_goodRows
CRef< CSeq_align > m_refSeqAlign
vector< int > m_badRows
int findIntersectingBlocks(int overlappinPercentage=-1)
CRef< CSeq_align > formatOneRow(const BlockModel &guide, CRef< CSeq_align > seqAlign)
void getOverlappingPercentages(vector< int > &percentages)
void addOneAlignment(const BlockModel &bm)
BlockModel * getIntersectedAlignment(double rowFraction=1.0)
void removeOneAlignment(const BlockModel &bm)
int getTotalBlockLength() const
Definition: cuBlock.cpp:608
CRef –.
Definition: ncbiobj.hpp:618
thread_local unique_ptr< FtaMsgPost > bmp
Definition: ftaerr.cpp:120
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 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
int i
#include<zmmintrin.h>
Definition: bm.h:78
Int4 delta(size_t dimension_, const Int4 *score_)
else result
Definition: token2.c:20
Modified on Wed Sep 04 14:58:56 2024 by modify_doxy.py rev. 669887