readfeat.cpp

来自「ncbi源码」· C++ 代码 · 共 1,648 行 · 第 1/5 页

CPP
1,648
字号
{    string line;    string feat, qual, val;    Int4 start, stop;    bool partial5, partial3, ispoint;    Int4 offset = 0;    CSeqFeatData::ESubtype sbtyp = CSeqFeatData::eSubtype_bad;    CSeqFeatData::E_Choice typ = CSeqFeatData::e_not_set;    CRef<CSeq_annot> sap(new CSeq_annot);    CSeq_annot::C_Data::TFtable& ftable = sap->SetData().SetFtable();    CRef<CSeq_feat> sfp;    CSeq_loc_mix *mix = 0;    CT_POS_TYPE pos(0);    if (! annotname.empty ()) {      CAnnot_descr& descr = sap->SetDesc ();      CRef<CAnnotdesc> annot(new CAnnotdesc);      annot->SetName (annotname);      descr.Set().push_back (annot);    }    while (ifs.good ()) {        pos = ifs.tellg ();        NcbiGetlineEOL (ifs, line);        if (! line.empty ()) {            if (line [0] == '>') {                // if next feature table, reposition and return current sap                ifs.seekg (pos);                return sap;            } else if (line [0] == '[') {                // set offset !!!!!!!!            } else if (x_ParseFeatureTableLine (line, &start, &stop, &partial5, &partial3,                                                &ispoint, feat, qual, val, offset)) {                // process line in feature table                if ((! feat.empty ()) && start >= 0 && stop >= 0) {                    // process start - stop - feature line                    if (m_FeatKeys.find (feat) != m_FeatKeys.end ()) {                        sbtyp = m_FeatKeys [feat];                        if (sbtyp != CSeqFeatData::eSubtype_bad) {                            // populate *sfp here...                            sfp.Reset (new CSeq_feat);                            sfp->ResetLocation ();                            typ = CSeqFeatData::GetTypeFromSubtype (sbtyp);                            sfp->SetData ().Select (typ);                            CSeqFeatData& sfdata = sfp->SetData ();                            if (typ == CSeqFeatData::e_Rna) {                                CRNA_ref& rrp = sfdata.SetRna ();                                CRNA_ref::EType rnatyp = CRNA_ref::eType_unknown;                                switch (sbtyp) {                                    case CSeqFeatData::eSubtype_preRNA :                                        rnatyp = CRNA_ref::eType_premsg;                                        break;                                    case CSeqFeatData::eSubtype_mRNA :                                        rnatyp = CRNA_ref::eType_mRNA;                                        break;                                    case CSeqFeatData::eSubtype_tRNA :                                        rnatyp = CRNA_ref::eType_tRNA;                                        break;                                    case CSeqFeatData::eSubtype_rRNA :                                        rnatyp = CRNA_ref::eType_rRNA;                                        break;                                    case CSeqFeatData::eSubtype_snRNA :                                        rnatyp = CRNA_ref::eType_snRNA;                                        break;                                    case CSeqFeatData::eSubtype_scRNA :                                        rnatyp = CRNA_ref::eType_scRNA;                                        break;                                    case CSeqFeatData::eSubtype_snoRNA :                                        rnatyp = CRNA_ref::eType_snoRNA;                                        break;                                    case CSeqFeatData::eSubtype_otherRNA :                                        rnatyp = CRNA_ref::eType_other;                                        break;                                    default :                                        break;                                }                                rrp.SetType (rnatyp);                            } else if (typ == CSeqFeatData::e_Imp) {                                CImp_feat_Base& imp = sfdata.SetImp ();                                imp.SetKey (feat);                            }                            ftable.push_back (sfp);                            // now create location                            CRef<CSeq_loc> location (new CSeq_loc);                            mix = &(location->SetMix ());                            sfp->SetLocation (*location);                            // and add first interval                            x_AddIntervalToFeature (sfp, mix, seqid, start, stop, partial5, partial3);                        }                    } else {                        // unrecognized feature key                        if ((flags & CFeature_table_reader::fReportBadKey) != 0) {                            ERR_POST (Warning << "Unrecognized feature " << feat);                        }                        if ((flags & CFeature_table_reader::fKeepBadKey) != 0) {                            sfp.Reset (new CSeq_feat);                            sfp->ResetLocation ();                            sfp->SetData ().Select (CSeqFeatData::e_Imp);                            CSeqFeatData& sfdata = sfp->SetData ();                            CImp_feat_Base& imp = sfdata.SetImp ();                            imp.SetKey (feat);                            ftable.push_back (sfp);                            CRef<CSeq_loc> location (new CSeq_loc);                            mix = &(location->SetMix ());                            sfp->SetLocation (*location);                            x_AddIntervalToFeature (sfp, mix, seqid, start, stop, partial5, partial3);                        }                    }                } else if (start >= 0 && stop >= 0 && feat.empty () && qual.empty () && val.empty ()) {                    // process start - stop multiple interval line                    x_AddIntervalToFeature (sfp, mix, seqid, start, stop, partial5, partial3);                } else if ((! qual.empty ()) && (! val.empty ())) {                    // process qual - val qualifier line                    if (! x_AddQualifierToFeature (sfp, qual, val)) {                        // unrecognized qualifier key                        if ((flags & CFeature_table_reader::fReportBadKey) != 0) {                            ERR_POST (Warning << "Unrecognized qualifier " << qual);                        }                        if ((flags & CFeature_table_reader::fKeepBadKey) != 0) {                            CSeq_feat::TQual& qlist = sfp->SetQual ();                            CRef<CGb_qual> gbq (new CGb_qual);                            gbq->SetQual (qual);                            gbq->SetVal (val);                            qlist.push_back (gbq);                        }                    }                } else if ((! qual.empty ()) && (val.empty ())) {                    // check for the few qualifiers that do not need a value                    if (find (m_SingleKeys.begin (), m_SingleKeys.end (), qual) != m_SingleKeys.end ()) {                        x_AddQualifierToFeature (sfp, qual, val);                    }                } else if (! feat.empty ()) {                                    // unrecognized location                    if ((flags & CFeature_table_reader::fReportBadKey) != 0) {                        ERR_POST (Warning << "Bad location on feature " << feat <<                                 " (start " << start << ", stop " << stop << ")");                    }                }            }        }    }    return sap;}CRef<CSeq_feat> CFeature_table_reader_imp::CreateSeqFeat (    const string& feat,    CSeq_loc& location,    const CFeature_table_reader::TFlags flags){    CRef<CSeq_feat> sfp (new CSeq_feat);    if (! feat.empty ()) {        if (m_FeatKeys.find (feat) != m_FeatKeys.end ()) {            CSeqFeatData::ESubtype sbtyp = m_FeatKeys [feat];            CSeqFeatData::E_Choice typ = CSeqFeatData::GetTypeFromSubtype (sbtyp);            sfp->SetData ().Select (typ);            CSeqFeatData& sfdata = sfp->SetData ();            sfp->SetLocation (location);            if (typ == CSeqFeatData::e_Rna) {                CRNA_ref& rrp = sfdata.SetRna ();                CRNA_ref::EType rnatyp = CRNA_ref::eType_unknown;                switch (sbtyp) {                    case CSeqFeatData::eSubtype_preRNA :                        rnatyp = CRNA_ref::eType_premsg;                        break;                    case CSeqFeatData::eSubtype_mRNA :                        rnatyp = CRNA_ref::eType_mRNA;                        break;                    case CSeqFeatData::eSubtype_tRNA :                        rnatyp = CRNA_ref::eType_tRNA;                        break;                    case CSeqFeatData::eSubtype_rRNA :                        rnatyp = CRNA_ref::eType_rRNA;                        break;                    case CSeqFeatData::eSubtype_snRNA :                        rnatyp = CRNA_ref::eType_snRNA;                        break;                    case CSeqFeatData::eSubtype_scRNA :                        rnatyp = CRNA_ref::eType_scRNA;                        break;                    case CSeqFeatData::eSubtype_snoRNA :                        rnatyp = CRNA_ref::eType_snoRNA;                        break;                    case CSeqFeatData::eSubtype_otherRNA :                        rnatyp = CRNA_ref::eType_other;                        break;                    default :                        break;                }                rrp.SetType (rnatyp);            } else if (typ == CSeqFeatData::e_Imp) {                CImp_feat_Base& imp = sfdata.SetImp ();                imp.SetKey (feat);            }            sfp->SetLocation (location);         } else {            // unrecognized feature key            if ((flags & CFeature_table_reader::fReportBadKey) != 0) {                ERR_POST (Warning << "Unrecognized feature " << feat);            }            if ((flags & CFeature_table_reader::fKeepBadKey) != 0) {                sfp.Reset (new CSeq_feat);                sfp->ResetLocation ();                sfp->SetData ().Select (CSeqFeatData::e_Imp);                CSeqFeatData& sfdata = sfp->SetData ();                CImp_feat_Base& imp = sfdata.SetImp ();                imp.SetKey (feat);                sfp->SetLocation (location);            }        }    }    return sfp;}void CFeature_table_reader_imp::AddFeatQual (    CRef<CSeq_feat> sfp,    const string& qual,    const string& val,    const CFeature_table_reader::TFlags flags){    if ((! qual.empty ()) && (! val.empty ())) {        if (! x_AddQualifierToFeature (sfp, qual, val)) {            // unrecognized qualifier key            if ((flags & CFeature_table_reader::fReportBadKey) != 0) {                ERR_POST (Warning << "Unrecognized qualifier " << qual);            }            if ((flags & CFeature_table_reader::fKeepBadKey) != 0) {                CSeq_feat::TQual& qlist = sfp->SetQual ();                CRef<CGb_qual> gbq (new CGb_qual);                gbq->SetQual (qual);                gbq->SetVal (val);                qlist.push_back (gbq);            }        }    } else if ((! qual.empty ()) && (val.empty ())) {        // check for the few qualifiers that do not need a value        if (find (m_SingleKeys.begin (), m_SingleKeys.end (), qual) != m_SingleKeys.end ()) {            x_AddQualifierToFeature (sfp, qual, val);        }    }}// public access functionsCRef<CSeq_annot> CFeature_table_reader::ReadSequinFeatureTable (    CNcbiIstream& ifs,    const string& seqid,    const string& annotname,    const TFlags flags){    // just read features from 5-column table    CRef<CSeq_annot> sap = x_GetImplementation ().ReadSequinFeatureTable (ifs, seqid, annotname, flags);    // go through all features and demote single interval seqlocmix to seqlocint    for (CTypeIterator<CSeq_feat> fi(*sap); fi; ++fi) {        CSeq_feat& feat = *fi;        CSeq_loc& location = feat.SetLocation ();        if (location.IsMix ()) {            CSeq_loc_mix& mx = location.SetMix ();            switch (mx.Get ().size ()) {         

⌨️ 快捷键说明

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