Exemplo n.º 1
0
CTime
CSeqDB::GetDate(const string   & dbname,
                ESeqType         seqtype)
{
    vector<string> vols;
    CSeqDB::FindVolumePaths(dbname, seqtype, vols);
    string fmt = "b d, Y  H:m P";
    CTime retv;
    char date[128];
    ITERATE(vector<string>, vol, vols)
    {
        string fn = *vol + ((seqtype == CSeqDB::eProtein)? ".pin" : ".nin");
        ifstream f(fn.c_str(), ios::in|ios::binary);
        char s[4];   // size of next chunk
        if (f.is_open())
        {
            f.seekg(8, ios::beg);
            f.read(s, 4);
            Uint4 offset = SeqDB_GetStdOrd((Uint4 *) s);
            f.seekg(offset, ios::cur);
            f.read(s, 4);
            offset = SeqDB_GetStdOrd((Uint4 *) s);
            f.read(date, offset);
            CTime d(string(date), fmt);
            if (retv.IsEmpty() || d > retv)
            {
                retv = d;
            }
        }
    }
Exemplo n.º 2
0
TIndx CSeqDBRawFile::ReadSwapped(CSeqDBMemLease & lease,
                                 TIndx            offset,
                                 string         * value,
                                 CSeqDBLockHold & locked) const
{
    Uint4 len = 0;
    
    m_Atlas.Lock(locked);
    
    if (! lease.Contains(offset, offset + sizeof(len))) {
        m_Atlas.GetRegion(lease, m_FileName, offset, offset + sizeof(len));
    }
    
    len = SeqDB_GetStdOrd((Int4 *) lease.GetPtr(offset));
    
    offset += sizeof(len);
    
    if (! lease.Contains(offset, offset + len)) {
        m_Atlas.GetRegion(lease, m_FileName, offset, offset + sizeof(len));
    }
    
    value->assign(lease.GetPtr(offset), (int) len);
    
    return offset + len;
}
Exemplo n.º 3
0
TIndx CSeqDBRawFile::ReadSwapped(CSeqDBMemLease & lease,
                                 TIndx            offset,
                                 Uint4          * value,
                                 CSeqDBLockHold & locked) const
{
    m_Atlas.Lock(locked);
    
    if (! lease.Contains(offset, offset + sizeof(*value))) {
        m_Atlas.GetRegion(lease, m_FileName, offset, offset + sizeof(*value));
    }
    
    *value = SeqDB_GetStdOrd((Uint4 *) lease.GetPtr(offset));
    
    return offset + sizeof(*value);
}
Exemplo n.º 4
0
 /// Return the offset field (in host order)
 Int4 GetOffset() const
 {
     return SeqDB_GetStdOrd(& m_Offset);
 }
Exemplo n.º 5
0
 /// Return the taxonomic identifier field (in host order)
 Int4 GetTaxId()const
 {
     return SeqDB_GetStdOrd(& m_Taxid);
 }
Exemplo n.º 6
0
CTaxDBFileInfo::CTaxDBFileInfo()
    : m_AllTaxidCount(0),
      m_IndexPtr(NULL),
      m_DataPtr(NULL),
      m_DataFileSize(0),
      m_MissingDB(false)
{

    // It is reasonable for this database to not exist.
    m_IndexFN =  SeqDB_ResolveDbPath("taxdb.bti");

    if (m_IndexFN.size()) {
        m_DataFN = m_IndexFN;
        m_DataFN[m_DataFN.size()-1] = 'd';
    }
    
    if (! (m_IndexFN.size() &&
           m_DataFN.size()  &&
           CFile(m_IndexFN).Exists() &&
           CFile(m_DataFN).Exists())) {
        m_MissingDB = true;
        return;
    }
    
    // Size for header data plus one taxid object.
    
    Uint4 data_start = (4 +    // magic
                        4 +    // taxid count
                        16);   // 4 reserved fields
    
    Uint4 idx_file_len = (Uint4) CFile(m_IndexFN).GetLength();
    
    if (idx_file_len < (data_start + sizeof(CSeqDBTaxId))) {
        m_MissingDB = true;
        return;
    }
    
    m_IndexFileMap.reset(new CMemoryFile(m_IndexFN));
    
    m_IndexFileMap->Map();

    // Last check-up of the database validity
    
    
    Uint4 * magic_num_ptr = (Uint4 *)m_IndexFileMap->GetPtr();
    
    const unsigned TAX_DB_MAGIC_NUMBER = 0x8739;
    
    if (TAX_DB_MAGIC_NUMBER != SeqDB_GetStdOrd(magic_num_ptr ++)) {
        m_MissingDB = true;
        m_IndexFileMap.reset();
        ERR_POST("Error: Tax database file has wrong magic number.");
        return;
    }
    
    m_AllTaxidCount = SeqDB_GetStdOrd(magic_num_ptr ++);
    
    // Skip the four reserved fields
    magic_num_ptr += 4;
    
    int taxid_array_size = int((idx_file_len - data_start)/sizeof(CSeqDBTaxId));
    
    if (taxid_array_size != m_AllTaxidCount) {
        m_MissingDB = true;
        m_IndexFileMap.reset();
        ERR_POST("SeqDB: Taxid metadata indicates (" << m_AllTaxidCount
                   << ") entries but file has room for (" << taxid_array_size
                   << ").");
        
        if (taxid_array_size < m_AllTaxidCount) {
            m_AllTaxidCount = taxid_array_size;
        }
        return;
    }
    
    m_DataFileMap.reset(new CMemoryFile(m_DataFN));

    m_DataPtr = (char *) (m_DataFileMap->GetPtr());
    m_DataFileSize = m_DataFileMap->GetSize();
    m_IndexPtr = (CSeqDBTaxId*) magic_num_ptr;
    
}