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

Go to the SVN repository for this file.

1 /* $Id: cuPssmScorer.cpp 63265 2014-06-12 15:02:18Z lanczyck $
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 Liu
27  *
28  * File Description:
29  *
30  * Score an seq-align by PSSM
31  *
32  * ===========================================================================
33  */
34 
35 #include <ncbi_pch.hpp>
41 
43 BEGIN_SCOPE(cd_utils)
44 
46 :m_pssm(pssm),
47 m_scoresFromPssm(pssm->GetPssm().GetNumColumns(), vector<int>(pssm->GetPssm().GetNumRows()))
48 {
49  if (m_pssm->GetPssm().GetByRow()) //deal with byColumn for now
50  {
51  m_scoresFromPssm.clear();
52  }
53  else
54  {
55  if (m_pssm->GetPssm().CanGetFinalData())
56  {
57  const list< int >& scoreList = m_pssm->GetPssm().GetFinalData().GetScores();
58  list<int>::const_iterator lit = scoreList.begin();
59  int nCol = m_pssm->GetPssm().GetNumColumns();
60  int nRow = pssm->GetPssm().GetNumRows();
61  for (int col = 0; col < nCol; col++)
62  {
63  for (int row = 0; row < nRow; row++)
64  {
65  m_scoresFromPssm[col][row] = *lit;
66  lit++;
67  }
68  }
69  }
70  else
71  m_scoresFromPssm.clear();
72  }
73 }
74 
75 //assume the master is the query/consensus in pssm
76 int PssmScorer::score(const CRef<CSeq_align> align, const CRef<CBioseq> bioseq)
77 {
78  BlockModelPair bmp(align);
79  return score(bmp, bioseq);
80 }
82 {
83  int score = -1;
84  const BlockModel& master = bmp.getMaster();
85  const BlockModel& slave = bmp.getSlave();
86  int masterLen = m_pssm->GetPssm().GetQuery().GetSeq().GetInst().GetLength();
87  vector<char> slaveSeq;
88  GetNcbistdSeq(*bioseq, slaveSeq);
89  if ((master.getLastAlignedPosition() >= masterLen)
90  || (slave.getLastAlignedPosition() >= (int) slaveSeq.size()))
91  return score;
92  if (m_scoresFromPssm.size() == 0)
93  return score;
94  int nBlocks = master.getBlocks().size();
95  for (int b = 0; b < nBlocks; b++)
96  {
97  const Block& mb = master.getBlocks()[b];
98  const Block& sb = slave.getBlocks()[b];
99  for (int cb = 0; cb < mb.getLen(); cb++)
100  {
101  score += scoreOneColumn(mb.getStart() + cb, slaveSeq[sb.getStart()+cb]);
102  }
103  }
104  return score;
105 }
106 
107 int PssmScorer::scoreOneColumn(int col, char aa)
108 {
109  return m_scoresFromPssm[col][aa];
110 }
111 
112 
113 END_SCOPE(cd_utils)
115 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
int getLastAlignedPosition() const
Definition: cuBlock.cpp:596
vector< Block > & getBlocks()
Definition: cuBlock.hpp:97
int getLen() const
Definition: cuBlock.hpp:41
int getStart() const
Definition: cuBlock.hpp:42
CRef –.
Definition: ncbiobj.hpp:618
CRef< CPssmWithParameters > m_pssm
int score(const CRef< CSeq_align > align, const CRef< CBioseq > bioseq)
vector< vector< int > > m_scoresFromPssm
int scoreOneColumn(int col, char aa)
bool GetNcbistdSeq(const CBioseq &bioseq, vector< char > &seqData)
Definition: cuSequence.cpp:315
thread_local unique_ptr< FtaMsgPost > bmp
Definition: ftaerr.cpp:120
#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
const TQuery & GetQuery(void) const
Get the Query member data.
Definition: Pssm_.hpp:772
const TPssm & GetPssm(void) const
Get the Pssm member data.
const TSeq & GetSeq(void) const
Get the variant data.
Definition: Seq_entry_.cpp:102
const TInst & GetInst(void) const
Get the Inst member data.
Definition: Bioseq_.hpp:336
TLength GetLength(void) const
Get the Length member data.
Definition: Seq_inst_.hpp:659
Modified on Sun Mar 03 03:10:50 2024 by modify_doxy.py rev. 669887