Beispiel #1
0
void CRequestContext::x_UpdateStdContextProp(CTempString name) const
{
    CRequestContext& ctx = const_cast<CRequestContext&>(*this);

    bool match = NStr::EqualNocase(name, kPassThrough_Sid);
    if (name.empty()  ||  match) {
        if (x_IsSetPassThroughProp(kPassThrough_Sid, false)) {
            ctx.SetSessionID(x_GetPassThroughProp(kPassThrough_Sid, false));
        }
        // Reset property only if explicit name is provided
        else if ( match ) {
            ctx.UnsetSessionID();
        }
        // Explicit name provided - skip other checks.
        if ( match ) return;
    }

    match = NStr::EqualNocase(name, kPassThrough_Phid);
    if (name.empty()  ||  match) {
        if (x_IsSetPassThroughProp(kPassThrough_Phid, false)) {
            ctx.SetHitID(x_GetPassThroughProp(kPassThrough_Phid, false));
        }
        // Reset property only if explicit name is provided
        else if ( match ) {
            ctx.UnsetHitID();
        }
        // Explicit name provided - skip other checks.
        if ( match ) return;
    }

    match = NStr::EqualNocase(name, kPassThrough_ClientIp);
    if (name.empty()  ||  match) {
        if (x_IsSetPassThroughProp(kPassThrough_ClientIp, false)) {
            ctx.SetClientIP(x_GetPassThroughProp(kPassThrough_ClientIp, false));
        }
        // Reset property only if explicit name is provided
        else if ( match ) {
            ctx.UnsetClientIP();
        }
        // Explicit name provided - skip other checks.
        if ( match ) return;
    }

    match = NStr::EqualNocase(name, kPassThrough_Dtab);
    if (name.empty()  ||  match) {
        if (x_IsSetPassThroughProp(kPassThrough_Dtab, false)) {
            ctx.SetDtab(x_GetPassThroughProp(kPassThrough_Dtab, false));
        }
        // Reset property only if explicit name is provided
        else if ( match ) {
            ctx.UnsetDtab();
        }
        // Explicit name provided - skip other checks.
        if ( match ) return;
    }
}
CRef<CSeq_entry>
CShortReadFastaInputSource::x_ReadFastaOneSeq(CRef<ILineReader> line_reader)
{
    int start = 0;
    // parse the last read defline
    CTempString line = **line_reader;
    CTempString id = x_ParseDefline(line);
    CRef<CSeq_id> seqid(new CSeq_id);
    seqid->Set(CSeq_id::e_Local, id);
    ++(*line_reader);
    line = **line_reader;
    while (line[0] != '>') {

        // ignore empty lines
        if (line.empty() && !line_reader->AtEOF()) {
            ++(*line_reader);
            line = **line_reader;
            continue;
        }

        // copy the sequence
        // increase the sequence buffer if necessary
        if (start + line.length() + 1 > m_SeqBuffLen) {
            string tmp;
            m_SeqBuffLen = 2 * (start + line.length() + 1);
            tmp.reserve(m_SeqBuffLen);
            memcpy(&tmp[0], &m_Sequence[0], start);
            m_Sequence.swap(tmp);
        }
        memcpy(&m_Sequence[start], line.data(), line.length());
        start += line.length();

        if (line_reader->AtEOF()) {
            break;
        }

        // read next line
        ++(*line_reader);
        line = **line_reader;
    }

    // set up sequence
    if (start > 0) {
        CRef<CSeq_entry> seq_entry(new CSeq_entry);
        CBioseq& bioseq = seq_entry->SetSeq();
        bioseq.SetInst().SetMol(CSeq_inst::eMol_na);
        bioseq.SetInst().SetRepr(CSeq_inst::eRepr_raw);
        bioseq.SetId().clear();
        bioseq.SetId().push_back(seqid);
        bioseq.SetInst().SetLength(start);
        m_Sequence[start] = 0;
        bioseq.SetInst().SetSeq_data().SetIupacna(CIUPACna(&m_Sequence[0]));
        bioseq.SetDescr();

        m_BasesAdded += start;
        return seq_entry;
    }

    return CRef<CSeq_entry>();
}
Beispiel #3
0
bool CAuthor::x_GetLabelV2(string* label, TLabelFlags flags, CTempString name,
                           CTempString initials, CTempString suffix)
{
    if (name.empty()) {
        return false;
    }

    if (name.size() <= 6  &&  (SWNC(name, "et al")  ||  SWNC(name, "et,al"))) {
        name = "et al.";
        if (NStr::EndsWith(*label, " and ")) {
            label->replace(label->size() - 5, NPOS, ", ");
        }
    }

    SIZE_TYPE pos = label->size();
    *label += name;
    if (HasText(initials)) {
        *label += ',';
        *label += initials;
    }
    if (HasText(suffix)) {
        *label += ' ';
        *label += suffix;
    }

    if ((flags & fLabel_FlatEMBL) != 0) {
        NStr::ReplaceInPlace(*label, ",", " ", pos);
    }

    return true;
}
CShortReadFastaInputSource::CShortReadFastaInputSource(CNcbiIstream& infile1,
                               CNcbiIstream& infile2,
                               CShortReadFastaInputSource::EInputFormat format)
    : m_SeqBuffLen(550),
      m_LineReader(new CStreamLineReader(infile1)),
      m_SecondLineReader(new CStreamLineReader(infile2)),
      m_IsPaired(true),
      m_Format(format)
{
    if (m_Format == eFastc) {
        m_LineReader.Reset();
        m_SecondLineReader.Reset();

        NCBI_THROW(CInputException, eInvalidInput, "FASTC format cannot be "
                   "used with two input files");
    }

    // allocate sequence buffer
    m_Sequence.reserve(m_SeqBuffLen + 1);

    // read the first line for FASTA input
    if (m_Format == eFasta) {
        CTempString line;
        do {
            ++(*m_LineReader);
            line = **m_LineReader;
        } while (line.empty() && !m_LineReader->AtEOF());

        if (line[0] != '>') {
            NCBI_THROW(CInputException, eInvalidInput, "FASTA parse error: "
                       "defline expected");
        }
    
        do {
            ++(*m_SecondLineReader);
            line = **m_SecondLineReader;
        } while (line.empty() && !m_SecondLineReader->AtEOF());

        if (line[0] != '>') {
            NCBI_THROW(CInputException, eInvalidInput, "FASTA parse error: "
                       "defline expected");
        }
    }
}
    void operator()( const CDirEntry & dirEntry ) {
        if( ! dirEntry.IsFile() ) {
            return;
        }

        CFile file(dirEntry);
        string name = file.GetName();
        if (NStr::EndsWith(name, ".txt")  ||  NStr::StartsWith(name, ".")) {
            return;
        }

        // extract info from the file name
        const string sFileName = file.GetName();
        vector<CTempString> vecFileNamePieces;
        NStr::Split( sFileName, ".", vecFileNamePieces );
        BOOST_REQUIRE(vecFileNamePieces.size() == 2);

        CTempString tsTestName = vecFileNamePieces[0];
        BOOST_REQUIRE(!tsTestName.empty());
        CTempString tsFileType = vecFileNamePieces[1];
        BOOST_REQUIRE(!tsFileType.empty());
            
        STestInfo & test_info_to_load =
            (*m_pTestNameToInfoMap)[vecFileNamePieces[0]];

        // figure out what type of file we have and set appropriately
        if (tsFileType == mExtInput) {
            BOOST_REQUIRE( test_info_to_load.mInFile.GetPath().empty() );
            test_info_to_load.mInFile = file;
        } 
        else if (tsFileType == mExtOutput) {
            BOOST_REQUIRE( test_info_to_load.mOutFile.GetPath().empty() );
            test_info_to_load.mOutFile = file;
        } 
        else if (tsFileType == mExtErrors) {
            BOOST_REQUIRE( test_info_to_load.mErrorFile.GetPath().empty() );
            test_info_to_load.mErrorFile = file;
        } 

        else {
            BOOST_FAIL("Unknown file type " << sFileName << ".");
        }
    }
Beispiel #6
0
void CRequestContext::x_UpdateStdPassThroughProp(CTempString name) const
{
    if (name.empty()  ||  NStr::EqualNocase(name, kPassThrough_Sid)) {
        if ( IsSetSessionID() ) {
            x_SetPassThroughProp(kPassThrough_Sid, GetSessionID(), false);
        }
        else {
            x_ResetPassThroughProp(kPassThrough_Sid, false);
        }
    }
    if (name.empty()  ||  NStr::EqualNocase(name, kPassThrough_ClientIp)) {
        if ( IsSetClientIP() ) {
            x_SetPassThroughProp(kPassThrough_ClientIp, GetClientIP(), false);
        }
        else {
            x_ResetPassThroughProp(kPassThrough_ClientIp, false);
        }
    }
    if (name.empty()  ||  NStr::EqualNocase(name, kPassThrough_Dtab)) {
        if ( IsSetDtab() ) {
            x_SetPassThroughProp(kPassThrough_Dtab, GetDtab(), false);
        }
        else {
            x_ResetPassThroughProp(kPassThrough_Dtab, false);
        }
    }
    if (name.empty()  ||  NStr::EqualNocase(name, kPassThrough_Phid)) {
        if ( IsSetHitID() ) {
            string sub_phid = const_cast<CRequestContext&>(*this).GetCurrentSubHitID();
            if ( sub_phid.empty() ) {
                sub_phid = const_cast<CRequestContext&>(*this).GetNextSubHitID();
            }
            x_SetPassThroughProp(kPassThrough_Phid, sub_phid, false);
        }
        else {
            x_ResetPassThroughProp(kPassThrough_Phid, false);
        }
    }
}
Beispiel #7
0
static bool IsInteger(const CTempString& value)
{
    if (value.empty())
        return false;

    const char* digit = value.end();

    while (--digit > value.begin())
        if (!isdigit(*digit))
            return false;

    return isdigit(*digit) || (*digit == '-' && value.length() > 1);
}
Beispiel #8
0
TMemberIndex CObjectIStreamAsn::GetChoiceIndex
    (const CChoiceTypeInfo* choiceType,
     const CTempString& id)
{
    TMemberIndex idx;
    if (!id.empty()  &&  isdigit((unsigned char) id[0])) {
        idx = choiceType->GetVariants().Find
            (CMemberId::TTag(NStr::StringToInt(id)), CAsnBinaryDefs::eContextSpecific);
    }
    else {
        idx = choiceType->GetVariants().Find(id);
        if (idx == kInvalidMember) {
            idx = GetAltItemIndex(choiceType,id);
        }
    }
    return idx;
}
Beispiel #9
0
TMemberIndex CObjectIStreamAsn::GetAltItemIndex(
    const CClassTypeInfoBase* classType,
    const CTempString& id,
    const TMemberIndex pos /*= kInvalidMember*/)
{
    TMemberIndex idx = kInvalidMember;
    if (!id.empty()) {
        const CItemsInfo& info = classType->GetItems();
        string id_alt = string(id);
        id_alt[0] = toupper((unsigned char)id_alt[0]);
        if (pos != kInvalidMember) {
            idx = info.Find(CTempString(id_alt),pos);
        } else {
            idx = info.Find(CTempString(id_alt));
        }
        if (idx != kInvalidMember &&
            !info.GetItemInfo(idx)->GetId().HaveNoPrefix()) {
            idx = kInvalidMember;
        }
    }
    return idx;
}
Beispiel #10
0
BEGIN_NCBI_SCOPE


//////////////////////////////////////////////////////////////////////////////
static
TSvrRef
make_server(const CTempString& specification, double& preference)
{
    CTempString server;
    // string host;
    Uint4 host = 0;
    Uint2 port = 0;
    string::size_type pos = 0;

    pos = specification.find_first_of("@(", pos);
    if (pos != string::npos) {
        server = specification.substr(0, pos);

        if (specification[pos] == '@') {
            // string::size_type old_pos = pos + 1;
            pos = specification.find_first_of(":(", pos + 1);
            if (pos != string::npos) {
                // string host_str = specification.substr(old_pos, pos - old_pos);
                // Ignore host in order to avoid dependebcy on libconnect.
                // SOCK_StringToHostPort(specification.c_str() + old_pos, &host, &port);
                if (specification[pos] == ':') {
                    port = NStr::StringToUInt(specification.substr(pos + 1),
                                              NStr::fAllowLeadingSpaces |
                                              NStr::fAllowTrailingSymbols |
                                              NStr::fConvErr_NoThrow);
                    pos = specification.find("(", pos + 1);
                    if (pos != string::npos) {
                        // preference = NStr::StringToDouble(
                        preference = NStr::StringToUInt(
                            specification.substr(pos + 1),
                            NStr::fAllowLeadingSpaces |
                            NStr::fAllowTrailingSymbols |
                            NStr::fConvErr_NoThrow);
                    }
                } else {
                    // preference = NStr::StringToDouble(
                    preference = NStr::StringToUInt(
                        specification.substr(pos + 1),
                        NStr::fAllowLeadingSpaces |
                        NStr::fAllowTrailingSymbols |
                        NStr::fConvErr_NoThrow);
                }
            } else {
                // host = specification.substr(old_pos);
                // Ignore host in order to avoid dependebcy on libconnect.
                // SOCK_StringToHostPort(specification.c_str() + old_pos, &host, &port);
            }
        } else {
            // preference = NStr::StringToDouble(
            preference = NStr::StringToUInt(
                specification.substr(pos + 1),
                NStr::fAllowLeadingSpaces |
                NStr::fAllowTrailingSymbols |
                NStr::fConvErr_NoThrow);
        }
    } else {
        server = specification;
    }

    if (server.empty() && host == 0) {
        DATABASE_DRIVER_ERROR("Either server name or host name expected.",
                              110100 );
    }

    return TSvrRef(new CDBServer(server, host, port));
}
CRef<CSeq_entry>
CShortReadFastaInputSource::x_ReadFastqOneSeq(CRef<ILineReader> line_reader)
{
    CTempString line;
    CTempString id;
    CRef<CSeq_entry> retval;

    // first read defline
    ++(*line_reader);
    line = **line_reader;

    // skip empty lines
    while (!line_reader->AtEOF() && line.empty()) {
        ++(*line_reader);
        line = **line_reader;
    }

    if (line[0] != '@') {
        NCBI_THROW(CInputException, eInvalidInput, (string)"FASTQ parse error:"
                   " defline expected at line: " +
                   NStr::IntToString(line_reader->GetLineNumber()));
    }

    id = x_ParseDefline(line);
    CRef<CSeq_id> seqid(new CSeq_id);
    seqid->Set(CSeq_id::e_Local, id);

    // read sequence
    ++(*line_reader);
    line = **line_reader;
    // skip empty lines
    while (!line_reader->AtEOF() && line.empty()) {
        ++(*line_reader);
        line = **line_reader;
    }

    // set up sequence
    if (line.length() > 0) {
        CRef<CSeq_entry> seq_entry(new CSeq_entry);
        CBioseq& bioseq = seq_entry->SetSeq();
        bioseq.SetInst().SetMol(CSeq_inst::eMol_na);
        bioseq.SetInst().SetRepr(CSeq_inst::eRepr_raw);
        bioseq.SetId().clear();
        bioseq.SetId().push_back(seqid);
        bioseq.SetInst().SetLength(line.length());
        bioseq.SetInst().SetSeq_data().SetIupacna(CIUPACna(line.data()));
        bioseq.SetDescr();

        m_BasesAdded += line.length();
        retval = seq_entry;
    }
    
    // read and skip second defline
    ++(*line_reader);
    line = **line_reader;
    // skip empty lines
    while (!line_reader->AtEOF() && line.empty()) {
        ++(*line_reader);
        line = **line_reader;
    }

    if (line[0] != '+') {
        NCBI_THROW(CInputException, eInvalidInput, (string)"FASTQ parse error:"
                   " defline expected at line: " +
                   NStr::IntToString(line_reader->GetLineNumber()));
    }

    // read and skip quality scores
    ++(*line_reader);
    line = **line_reader;
    // skip empty lines
    while (!line_reader->AtEOF() && line.empty()) {
        ++(*line_reader);
        line = **line_reader;
    }

    return retval;
}
Beispiel #12
0
CTextseq_id& CTextseq_id::Set
(const CTempString& acc_in,
 const CTempString& name_in,
 int                version,
 const CTempString& release_in,
 bool               allow_dot_version)
{
    // Perform general sanity checks up front.
    if (version < 0) {
        NCBI_THROW(CSeqIdException, eFormat,
                   "Unexpected negative version " + NStr::IntToString(version)
                   + " for accession " + string(acc_in));
    }

    CTempString acc     =
        NStr::TruncateSpaces_Unsafe(acc_in,     NStr::eTrunc_Both);
    CTempString name    =
        NStr::TruncateSpaces_Unsafe(name_in,    NStr::eTrunc_Both);
    CTempString release =
        NStr::TruncateSpaces_Unsafe(release_in, NStr::eTrunc_Both);

    if (acc.empty()  &&  name.empty()) {
    }

    if (acc.empty()) {
        ResetAccession();
    } else {
        SIZE_TYPE idx = NPOS;

        if (allow_dot_version) {
            idx = acc.rfind('.');
        }

        if (idx == NPOS) {
            // no version within acc
            SetAccession(acc);

            // any standalone version is ok
            if (version > 0) {
                SetVersion(version); 
            } else {
                ResetVersion();
            }
        } else {
            // accession.version
            CTempString accession = acc.substr(0, idx);
            CTempString acc_ver   = acc.substr(idx + 1);
            int         ver       = NStr::StringToNonNegativeInt(acc_ver);
 
            if (ver <= 0) {
                NCBI_THROW(CSeqIdException, eFormat,
                           "Version embedded in accession " + string(acc)
                           + " is not a positive integer");
            } else if (version > 0  &&  ver != version) {
                NCBI_THROW(CSeqIdException, eFormat,
                           "Incompatible version " + NStr::IntToString(version)
                           + " supplied for accession " + string(acc));
            }
 
            SetAccession(accession);
            SetVersion(ver);
        }
    }

    if (name.empty()) {
        ResetName();
    } else {
        SetName(name);
    }

    if (acc.empty()  &&  name.empty()) {
        NCBI_THROW(CSeqIdException, eFormat,
                   "Accession and name missing for Textseq-id (but got"
                   " version " + NStr::IntToString(version) + ", release "
                   + string(release) + ')');
    } else if (release.empty()) {
        ResetRelease();
    } else {
        SetRelease(release);
    }
    return *this;
}
Beispiel #13
0
        void operator()( const CDirEntry & dirEntry ) {
            const static size_t kInvalidFileNumber = numeric_limits<size_t>::max();

            if( ! dirEntry.IsFile() ) {
                return;
            }

            CFile file(dirEntry);

            // skip the README file
            if( file.GetName() == "README.txt" ) {
                return;
            }

            // skip .svn files
            if( NStr::Find(file.GetPath(), ".svn") != NPOS )
            {
                return;
            }

            const string sFilePath = file.GetPath();
            cout << "Parsing file name: " << sFilePath << endl;

            // extract info from the file name
            const string sFileName = file.GetName();
            vector<CTempString> vecFileNamePieces;
            NStr::Tokenize( sFileName, ".", vecFileNamePieces );

            BOOST_REQUIRE( vecFileNamePieces.size() == 2 ||
                vecFileNamePieces.size() == 3 );

            CTempString tsTestName = vecFileNamePieces[0];
            BOOST_REQUIRE( ! tsTestName.empty() );
            CTempString tsFileType = vecFileNamePieces[1];
            size_t iFileNumber = kInvalidFileNumber;
            if( vecFileNamePieces.size() > 2 ) {
                iFileNumber = NStr::StringToUInt(vecFileNamePieces[2]);
            }
            
            STestInfo & test_info_to_load =
                (*m_pTestNameToInfoMap)[vecFileNamePieces[0]];

            // figure out what type of file we have and set appropriately
            if( tsFileType == "agp" && iFileNumber == kInvalidFileNumber ) {
                // handle agp file
                // (and make sure we don't have duplicates)
                BOOST_REQUIRE( test_info_to_load.m_AGPFile.GetPath().empty() );
                test_info_to_load.m_AGPFile = file;
            } else if( tsFileType == "expected_seq_entry" && iFileNumber != kInvalidFileNumber )
            {
                // handle expected seq-entry file
                // (Note that the files could come in in any order)

                vector<CFile> & vecExpectedSeqEntryFiles = 
                    test_info_to_load.m_vecExpectedSeqEntryFiles;

                if( vecExpectedSeqEntryFiles.size() <= iFileNumber ) {
                    // expand the vector to include this file number
                    vecExpectedSeqEntryFiles.resize( 1 + iFileNumber );
                }

                // make sure no duplicates
                BOOST_REQUIRE( vecExpectedSeqEntryFiles[iFileNumber].GetPath().empty() );
                vecExpectedSeqEntryFiles[iFileNumber] = file;
            } else if( tsFileType == "flags" && iFileNumber == kInvalidFileNumber ) {
                // handle flags file
                BOOST_REQUIRE( test_info_to_load.m_FlagFile.GetPath().empty() );
                test_info_to_load.m_FlagFile = file;
            } else {
                BOOST_FAIL("Unknown file type");
            }
        }