📄 seqdb_src.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: seqdb_src.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 18:06:22 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.11 * PRODUCTION * =========================================================================== *//* $Id: seqdb_src.cpp,v 1000.1 2004/06/01 18:06:22 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 seqdb_src.cpp/// Implementation of the BlastSeqSrc interface for a C++ BLAST databases API#include <ncbi_pch.hpp>#include <objects/seqloc/Seq_id.hpp>#include <objmgr/util/sequence.hpp>#include <algo/blast/api/seqdb_src.hpp>#include <algo/blast/core/blast_util.h>#include <objtools/readers/seqdb/seqdb.hpp>#include "blast_setup.hpp"/** @addtogroup AlgoBlast * * @{ */USING_NCBI_SCOPE;USING_SCOPE(objects);USING_SCOPE(blast);extern "C" {/* Function prototypes */static Int4 SeqDbGetMaxLength(void* seqdb_handle, void* ignoreme);static Int4 SeqDbGetNumSeqs(void* seqdb_handle, void* ignoreme);static Int8 SeqDbGetTotLen(void* seqdb_handle, void* ignoreme);static Int4 SeqDbGetAvgLength(void* seqdb_handle, void* ignoreme);static char* SeqDbGetName(void* seqdb_handle, void* ignoreme);static char* SeqDbGetDefinition(void* seqdb_handle, void* ignoreme);static char* SeqDbGetDate(void* seqdb_handle, void* ignoreme);static Boolean SeqDbGetIsProt(void* seqdb_handle, void* ignoreme);static ListNode* SeqDbGetSeqLoc(void* seqdb_handle, void* args);static ListNode* SeqDbGetError(void* seqdb_handle, void* args);/** Retrieves the length of the longest sequence in the BlastSeqSrc. * @param seqdb_handle Pointer to initialized CSeqDB object [in] * @param ignoreme Unused by this implementation [in] */static Int4 SeqDbGetMaxLength(void* seqdb_handle, void*){ CSeqDB* seqdb = (CSeqDB*) seqdb_handle; return seqdb->GetMaxLength();}/** Retrieves the number of sequences in the BlastSeqSrc. * @param seqdb_handle Pointer to initialized CSeqDB object [in] * @param ignoreme Unused by this implementation [in] */static Int4 SeqDbGetNumSeqs(void* seqdb_handle, void*){ CSeqDB* seqdb = (CSeqDB*) seqdb_handle; return seqdb->GetNumSeqs();}/** Retrieves the total length of all sequences in the BlastSeqSrc. * @param seqdb_handle Pointer to initialized CSeqDB object [in] * @param ignoreme Unused by this implementation [in] */static Int8 SeqDbGetTotLen(void* seqdb_handle, void*){ CSeqDB* seqdb = (CSeqDB*) seqdb_handle; return seqdb->GetTotalLength();}/** Retrieves the average length of sequences in the BlastSeqSrc. * @param seqdb_handle Pointer to initialized CSeqDB object [in] * @param ignoreme Unused by this implementation [in] */static Int4 SeqDbGetAvgLength(void* seqdb_handle, void* ignoreme){ Int8 total_length = SeqDbGetTotLen(seqdb_handle, ignoreme); Int4 num_seqs = MAX(1, SeqDbGetNumSeqs(seqdb_handle, ignoreme)); return (Int4) (total_length/num_seqs);}/** Retrieves the name of the BLAST database. * FIXME: RIGHT NOW THERE IS NO GETTER in CSeqDB for database name * @param seqdb_handle Pointer to initialized CSeqDB object [in] * @param ignoreme Unused by this implementation [in] */static char* SeqDbGetName(void* /*seqdb_handle*/, void*){#if 0 // FIXME: GetName method not implemented in CSeqDb!!! CSeqDB* seqdb = (CSeqDB*) seqdb_handle; return strdup(seqdb->GetName().c_str());#else return NULL;#endif}/** Retrieves the definition (title) of the BLAST database. * @param seqdb_handle Pointer to initialized CSeqDB object [in] * @param ignoreme Unused by this implementation [in] */static char* SeqDbGetDefinition(void* seqdb_handle, void*){ CSeqDB* seqdb = (CSeqDB*) seqdb_handle; return strdup(seqdb->GetTitle().c_str());}/** Retrieves the date of the BLAST database. * @param seqdb_handle Pointer to initialized CSeqDB object [in] * @param ignoreme Unused by this implementation [in] */static char* SeqDbGetDate(void* seqdb_handle, void*){ CSeqDB* seqdb = (CSeqDB*) seqdb_handle; return strdup(seqdb->GetDate().c_str());}/** Retrieves the date of the BLAST database. * @param seqdb_handle Pointer to initialized CSeqDB object [in] * @param ignoreme Unused by this implementation [in] */static Boolean SeqDbGetIsProt(void* seqdb_handle, void*){ CSeqDB* seqdb = (CSeqDB*) seqdb_handle; return (seqdb->GetSeqType() == 'p');}/** Retrieves the sequence meeting the criteria defined by its second argument. * @param seqdb_handle Pointer to initialized CSeqDB object [in] * @param args Pointer to GetSeqArg structure [in] * @return return codes defined in blast_seqsrc.h */static Int2 SeqDbGetSequence(void* seqdb_handle, void* args){ CSeqDB* seqdb = (CSeqDB*) seqdb_handle; GetSeqArg* seqdb_args = (GetSeqArg*) args; Int4 oid = -1, len = 0; Boolean has_sentinel_byte; Boolean buffer_allocated; if (!seqdb || !seqdb_args) return BLAST_SEQSRC_ERROR; oid = seqdb_args->oid; Uint1 encoding = seqdb_args->encoding; has_sentinel_byte = (encoding == BLASTNA_ENCODING); buffer_allocated = (encoding == BLASTNA_ENCODING || encoding == NCBI4NA_ENCODING); /* free buffers if necessary */ if (seqdb_args->seq) BlastSequenceBlkClean(seqdb_args->seq); const char *buf; if (!buffer_allocated) { len = seqdb->GetSequence(oid, &buf); } else { len = seqdb->GetAmbigSeq(oid, &buf, has_sentinel_byte); } if (len <= 0) return BLAST_SEQSRC_ERROR; BlastSetUp_SeqBlkNew((Uint1*)buf, len, 0, &seqdb_args->seq, buffer_allocated); /* If there is no sentinel byte, and buffer is allocated, i.e. this is the traceback stage of a translated search, set "sequence" to the same position as "sequence_start". */ if (buffer_allocated && !has_sentinel_byte) seqdb_args->seq->sequence = seqdb_args->seq->sequence_start; seqdb_args->seq->oid = oid; return BLAST_SEQSRC_SUCCESS;}/** Returns the memory allocated for the sequence buffer to the CSeqDB * interface. * @param seqdb_handle Pointer to initialized CSeqDB object [in] * @param args Pointer to the GetSeqArgs structure, containing sequence block * with the buffer that needs to be deallocated. [in] * @return return codes defined in blast_seqsrc.h */static Int2 SeqDbRetSequence(void* seqdb_handle, void* args){ CSeqDB* seqdb = (CSeqDB*) seqdb_handle; GetSeqArg* seqdb_args = (GetSeqArg*) args; if (!seqdb || !seqdb_args) return BLAST_SEQSRC_ERROR; if (seqdb_args->seq->sequence_start_allocated) { seqdb->RetSequence((const char**)&seqdb_args->seq->sequence_start); seqdb_args->seq->sequence_start_allocated = FALSE; seqdb_args->seq->sequence_start = NULL; } return 0;}/** Retrieves the sequence identifier meeting the criteria defined by its * second argument. Currently it is an ordinal id (integer value). * Client code is responsible for deallocating the return value. * @param seqdb_handle Pointer to initialized CSeqDB object [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* SeqDbGetSeqId(void* seqdb_handle, void* args){ CSeqDB* seqdb = (CSeqDB*) seqdb_handle; Uint4* oid = (Uint4*) args; ListNode* seqid_wrap; if (!seqdb || !oid) return NULL; list< CRef<CSeq_id> > seqid_list; seqid_list = seqdb->GetSeqIDs(*oid); CRef<CSeq_id>* seqid_ref = new CRef<CSeq_id>(seqid_list.front()); seqid_wrap = ListNodeAddPointer(NULL, BLAST_SEQSRC_CPP_SEQID_REF, (void*) seqid_ref); return seqid_wrap;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -