⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multiseq_src.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: multiseq_src.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 18:06:13  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.16 * PRODUCTION * =========================================================================== *//*  $Id: multiseq_src.cpp,v 1000.1 2004/06/01 18:06:13 gouriano Exp $* ===========================================================================**                            PUBLIC DOMAIN NOTICE*               National Center for Biotechnology Information**  This software/database is a "United States Government Work" under the*  terms of the United States Copyright Act.  It was written as part of*  the author's official duties as a United States Government employee and*  thus cannot be copyrighted.  This software/database is freely available*  to the public for use. The National Library of Medicine and the U.S.*  Government have not placed any restriction on its use or reproduction.**  Although all reasonable efforts have been taken to ensure the accuracy*  and reliability of the software and data, the NLM and the U.S.*  Government do not and cannot warrant the performance or results that*  may be obtained by using this software or data. The NLM and the U.S.*  Government disclaim all warranties, express or implied, including*  warranties of performance, merchantability or fitness for any particular*  purpose.**  Please cite the author in any work or product based on this material.** ===========================================================================** Author:  Ilya Dondoshansky**//// @file multiseq_src.cpp/// Implementation of the BlastSeqSrc interface for a vector of sequence /// locations.#include <ncbi_pch.hpp>#include <objects/seqloc/Seq_id.hpp>#include <objmgr/util/sequence.hpp>#include <algo/blast/api/multiseq_src.hpp>#include <algo/blast/core/blast_def.h>#include "blast_setup.hpp"#include <algo/blast/api/blast_exception.hpp>/** @addtogroup AlgoBlast * * @{ */BEGIN_NCBI_SCOPEUSING_SCOPE(objects);BEGIN_SCOPE(blast)CMultiSeqInfo::CMultiSeqInfo(const TSeqLocVector& seq_vector, EProgram program)    : m_vSeqVector(seq_vector){    m_ibIsProt = (program == eBlastp || program == eBlastx);        try {        SetupSubjects(seq_vector, program, &m_ivSeqBlkVec, &m_iMaxLength);    } catch (const CBlastException& exptn) {        Blast_MessageWrite(&m_icErrMsg, BLAST_SEV_ERROR, exptn.GetErrCode(),                           1, exptn.GetErrCodeString());    }    // Do not set right away    m_iAvgLength = 0;}CMultiSeqInfo::~CMultiSeqInfo(){    NON_CONST_ITERATE(vector<BLAST_SequenceBlk*>, itr, m_ivSeqBlkVec) {        *itr = BlastSequenceBlkFree(*itr);    }    m_ivSeqBlkVec.clear();}void* CMultiSeqInfo::GetSeqId(int index){    CSeq_id* seqid =         const_cast<CSeq_id*>(&sequence::GetId(*m_vSeqVector[index].seqloc,                                              m_vSeqVector[index].scope));    return (void*) seqid;}void* CMultiSeqInfo::GetSeqLoc(int index){    return (void*) &m_vSeqVector[index];}/** Retrieves the length of the longest sequence in the BlastSeqSrc. * @param multiseq_handle Pointer to the structure containing sequences [in] */extern "C" {static Int4 MultiSeqGetMaxLength(void* multiseq_handle, void*){    Int4 retval = 0;    Uint4 index;    CMultiSeqInfo* seq_info = (CMultiSeqInfo*) multiseq_handle;    ASSERT(seq_info);        if ((retval = seq_info->GetMaxLength()) > 0)        return retval;    for (index=0; index<seq_info->GetNumSeqs(); ++index)        retval = MAX(retval, seq_info->GetSeqBlk(index)->length);    seq_info->SetMaxLength(retval);    return retval;}/** Retrieves the length of the longest sequence in the BlastSeqSrc. * @param multiseq_handle Pointer to the structure containing sequences [in] */static Int4 MultiSeqGetAvgLength(void* multiseq_handle, void*){    Int8 total_length = 0;    Uint4 num_seqs = 0;    Uint4 avg_length;    Uint4 index;    CMultiSeqInfo* seq_info = (CMultiSeqInfo*) multiseq_handle;    ASSERT(seq_info);    if ((avg_length = seq_info->GetAvgLength()) > 0)        return avg_length;    if ((num_seqs = seq_info->GetNumSeqs()) == 0)        return 0;    for (index = 0; index < num_seqs; ++index)         total_length += (Int8) seq_info->GetSeqBlk(index)->length;    avg_length = (Uint4) (total_length / num_seqs);    seq_info->SetAvgLength(avg_length);    return avg_length;}/** Retrieves the number of sequences in the BlastSeqSrc. * @param multiseq_handle Pointer to the structure containing sequences [in] */static Int4 MultiSeqGetNumSeqs(void* multiseq_handle, void*){    CMultiSeqInfo* seq_info = (CMultiSeqInfo*) multiseq_handle;    ASSERT(seq_info);    return seq_info->GetNumSeqs();}/** Returns 0 as total length, indicating that this is NOT a database! */static Int8 MultiSeqGetTotLen(void* /*multiseq_handle*/, void*){    return 0;}/** Needed for completeness only. */static char* MultiSeqGetName(void* /*multiseq_handle*/, void*){    return NULL;}/** Needed for completeness only */static char* MultiSeqGetDefinition(void* /*multiseq_handle*/, void*){    return NULL;}/** Needed for completeness only. */static char* MultiSeqGetDate(void* /*multiseq_handle*/, void*){    return NULL;}/** Retrieves the date of the BLAST database. * @param multiseq_handle Pointer to the structure containing sequences [in] */static Boolean MultiSeqGetIsProt(void* multiseq_handle, void*){    CMultiSeqInfo* seq_info = (CMultiSeqInfo*) multiseq_handle;    ASSERT(seq_info);    return (Boolean) seq_info->GetIsProtein();}/** Retrieves the sequence meeting the criteria defined by its second argument. * @param multiseq_handle Pointer to the structure containing sequences [in] * @param args Pointer to GetSeqArg structure [in] * @return return codes defined in blast_seqsrc.h */static Int2 MultiSeqGetSequence(void* multiseq_handle, void* args){    CMultiSeqInfo* seq_info = (CMultiSeqInfo*) multiseq_handle;    GetSeqArg* seq_args = (GetSeqArg*) args;    Int4 index;    ASSERT(seq_info);    ASSERT(args);    if (seq_info->GetNumSeqs() == 0 || !seq_args)        return BLAST_SEQSRC_ERROR;    index = seq_args->oid;    if (index >= (Int4) seq_info->GetNumSeqs())        return BLAST_SEQSRC_EOF;    BlastSequenceBlkCopy(&seq_args->seq, seq_info->GetSeqBlk(index));    /* If this is a nucleotide sequence, and it is the traceback stage,        we need the uncompressed buffer, stored in the 'sequence_start'        pointer. That buffer has an extra sentinel byte for blastn, but       no sentinel byte for translated programs. */    if (seq_args->encoding == BLASTNA_ENCODING) {        seq_args->seq->sequence = seq_args->seq->sequence_start + 1;    } else if (seq_args->encoding == NCBI4NA_ENCODING) {        seq_args->seq->sequence = seq_args->seq->sequence_start;    }    seq_args->seq->oid = index;    return BLAST_SEQSRC_SUCCESS;}/** Deallocates the uncompressed sequence buffer if necessary. * @param multiseq_handle Pointer to the structure containing sequences [in] * @param args Pointer to GetSeqArg structure [in] * @return return codes defined in blast_seqsrc.h */static Int2 MultiSeqRetSequence(void* /*multiseq_handle*/, void* args){    GetSeqArg* seq_args = (GetSeqArg*) args;    ASSERT(seq_args);    if (seq_args->seq->sequence_start_allocated)        sfree(seq_args->seq->sequence_start);    return 0;}/** Retrieves the sequence identifier given its index into the sequence vector. * Client code is responsible for deallocating the return value.  * @param multiseq_handle Pointer to the structure containing sequences [in] * @param args Pointer to integer indicating ordinal id [in] * @return Sequence id structure generated from ASN.1 spec,  *         cast to a void pointer. */static ListNode* MultiSeqGetSeqId(void* multiseq_handle, void* args){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -