Esempio n. 1
0
CAnnotCompare::TCompareFlags
CAnnotCompare::CompareFeats(const CSeq_feat& feat1,
                            CScope& scope1,
                            const CSeq_feat& feat2,
                            CScope& scope2,
                            vector<ECompareFlags>* complex_flags,
                            list<string>* comments)
{
    return CompareFeats(feat1, feat1.GetLocation(), scope1,
                        feat2, feat2.GetLocation(), scope2,
                        complex_flags, comments);
}
Esempio n. 2
0
//	----------------------------------------------------------------------------
CConstRef<CSeq_feat> CFeatTableEdit::xGetMrnaParent(
    const CSeq_feat& feat)
//	----------------------------------------------------------------------------
{
    CConstRef<CSeq_feat> pMrna;
    CSeq_feat_Handle sfh = mpScope->GetSeq_featHandle(feat);
    CSeq_annot_Handle sah = sfh.GetAnnot();
    if (!sah) {
        return pMrna;
    }

    size_t bestLength(0);
    CFeat_CI findGene(sah, CSeqFeatData::eSubtype_mRNA);
    for ( ; findGene; ++findGene) {
        Int8 compare = sequence::TestForOverlap64(
                           findGene->GetLocation(), feat.GetLocation(),
                           sequence::eOverlap_Contained);
        if (compare == -1) {
            continue;
        }
        size_t currentLength = sequence::GetLength(findGene->GetLocation(), mpScope);
        if (!bestLength  ||  currentLength > bestLength) {
            pMrna.Reset(&(findGene->GetOriginalFeature()));
            bestLength = currentLength;
        }
    }
    return pMrna;
}
Esempio n. 3
0
//  ----------------------------------------------------------------------------
bool CGffRecord::AssignStop(
    const CSeq_feat& feature )
//  ----------------------------------------------------------------------------
{
    if ( feature.CanGetLocation() ) {
        const CSeq_loc& location = feature.GetLocation();
        unsigned int uEnd = location.GetStop( eExtreme_Positional ) + 1;
        m_strEnd = NStr::UIntToString( uEnd );
    }
    return true;
}
Esempio n. 4
0
TSeqPos CFeatTrim::x_GetStartOffset(const CSeq_feat& feat,
    TSeqPos from, TSeqPos to) 
{
    TSeqPos offset = 0;
    const auto strand = feat.GetLocation().GetStrand();
    CRange<TSeqPos> feat_range = feat.GetLocation().GetTotalRange();

    if (strand != eNa_strand_minus) {
        TSeqPos feat_from = feat_range.GetFrom();
        if (feat_from < from) {
            offset = from - feat_from;
        }
    }
    else { // eNa_strand_minus
        TSeqPos feat_to = feat_range.GetTo();
        if (feat_to > to) {
            offset = feat_to - to;
        }
    }
    return offset;
}
Esempio n. 5
0
//  ----------------------------------------------------------------------------
CRef<CSeq_feat> CFeatTableEdit::xMakeGeneForMrna(
    const CSeq_feat& rna)
//  ----------------------------------------------------------------------------
{
    CRef<CSeq_feat> pGene;
    CSeq_feat_Handle sfh = mpScope->GetSeq_featHandle(rna);
    CSeq_annot_Handle sah = sfh.GetAnnot();
    if (!sah) {
        return pGene;
    }
    CConstRef<CSeq_feat> pExistingGene = xGetGeneParent(rna);
    if (pExistingGene) {
        return pGene;
    }
    pGene.Reset(new CSeq_feat);
    pGene->SetLocation().SetInt();
    pGene->SetLocation().SetId(*rna.GetLocation().GetId());
    pGene->SetLocation().SetInt().SetFrom(rna.GetLocation().GetStart(
            eExtreme_Positional));
    pGene->SetLocation().SetInt().SetTo(rna.GetLocation().GetStop(
                                            eExtreme_Positional));
    pGene->SetData().SetGene();
    return pGene;
}
Esempio n. 6
0
//  ----------------------------------------------------------------------------
bool CBedGraphWriter::xWriteSingleFeature(
    const CBedTrackRecord& trackdata,
    const CSeq_feat& feature)
//  ----------------------------------------------------------------------------
{
    CBedGraphRecord bedRecord;

    const CSeq_loc& location = feature.GetLocation();
    if (!location.IsInt()) {
        NCBI_THROW(
            CObjWriterException,
            eInterrupted,
            "BedGraph writer does not support feature locations that are not intervals.");
    }
    const CSeq_interval& interval = location.GetInt();

    const string& scoreStr = feature.GetNamedQual("score");
    if (scoreStr.empty()) {
        NCBI_THROW(
            CObjWriterException,
            eInterrupted,
            "BedGraph writer only supports features with a \"score\" qualifier.");
    }
    double score = 0;
    try {
        score = NStr::StringToDouble(scoreStr);
    }
    catch(CException&) {
        NCBI_THROW(
            CObjWriterException,
            eInterrupted,
            "BedGraph writer encountered feature with bad \"score\" qualifier.");
    }

    const CSeq_id& id = interval.GetId();
    string recordId;
    id.GetLabel(&recordId);
    bedRecord.SetChromId(recordId);

    bedRecord.SetChromStart(interval.GetFrom());
    bedRecord.SetChromEnd(interval.GetTo()-1);
    bedRecord.SetChromValue(score);
    bedRecord.Write(m_Os);
    return true;
}
Esempio n. 7
0
//  ----------------------------------------------------------------------------
bool CGffRecord::AssignSeqId(
    const CSeq_feat& feature )
//  ----------------------------------------------------------------------------
{
    m_strSeqId = "<unknown>";

    if ( feature.CanGetLocation() ) {
        const CSeq_loc& location = feature.GetLocation();
        const CSeq_id* pId = location.GetId();
        switch ( pId->Which() ) {
            
            case CSeq_id::e_Local:
                if ( pId->GetLocal().IsId() ) {
                    m_strSeqId = NStr::UIntToString( pId->GetLocal().GetId() );
                }
                else {
                    m_strSeqId = pId->GetLocal().GetStr();
                }
                break;

            case CSeq_id::e_Gi:
                m_strSeqId = NStr::IntToString( pId->GetGi() );
                break;

            case CSeq_id::e_Other:
                if ( pId->GetOther().CanGetAccession() ) {
                    m_strSeqId = pId->GetOther().GetAccession();
                    if ( pId->GetOther().CanGetVersion() ) {
                        m_strSeqId += ".";
                        m_strSeqId += NStr::UIntToString( 
                            pId->GetOther().GetVersion() ); 
                    }
                }
                break;

            default:
                break;
        }
    }

    return true;
}
Esempio n. 8
0
bool CLocation_constraint :: Match(const CSeq_feat& feat, CConstRef <CSeq_feat> feat_to, CConstRef <CBioseq> feat_bioseq) const
{
  if (x_IsLocationConstraintEmpty()) {
     return true;
  }
 
  const CSeq_loc& feat_loc = feat.GetLocation();
  if (GetStrand() != eStrand_constraint_any) {
    if (feat_bioseq.Empty()) {
       return false;
    }
    else if (feat_bioseq->IsAa()) {
      if (feat_to.Empty()) {  // when feat is product, feat_to points to cds
         return false;
      }
      else if (!x_DoesStrandMatchConstraint (feat_to->GetLocation())) {
        return false;
      }
    }
    else if (!x_DoesStrandMatchConstraint (feat_loc)) {
        return false;
    }
  }

  if (!x_DoesBioseqMatchSequenceType(feat_bioseq, GetSeq_type())) {
     return false;
  }

  if (!x_DoesLocationMatchPartialnessConstraint (feat_loc)) {
     return false;
  }

  if (!x_DoesLocationMatchTypeConstraint (feat_loc)) {
     return false;
  }

  if (!x_DoesLocationMatchDistanceConstraint(feat_bioseq, feat_loc)) {
     return false;
  }

  return true;
};
Esempio n. 9
0
//  ----------------------------------------------------------------------------
bool CGffRecord::AssignStrand(
    const CSeq_feat& feature )
//  ----------------------------------------------------------------------------
{
    m_strStrand = ".";
    if ( feature.CanGetLocation() ) {
        const CSeq_loc& location = feature.GetLocation();
        ENa_strand strand = location.GetStrand();
        switch( strand ) {
        default:
            break;
        case eNa_strand_plus:
            m_strStrand = "+";
            break;
        case eNa_strand_minus:
            m_strStrand = "-";
            break;
        }
    }
    return true;
}
Esempio n. 10
0
CRef<CSeq_feat> CFeatTrim::Apply(const CSeq_feat& feat,
    const CRange<TSeqPos>& range)
{
    CRef<CSeq_loc> loc = Ref(new CSeq_loc());
    loc->Assign(feat.GetLocation());

    const TSeqPos from = range.GetFrom();
    const TSeqPos to = range.GetTo();

    const bool set_partial = true;

    x_TrimLocation(from, to, set_partial, loc);
    if (loc->IsNull()) {
        return Ref(new CSeq_feat());
    }

    // Create a new seq-feat with the trimmed location
    CRef<CSeq_feat> new_sf(new CSeq_feat());
    new_sf->Assign(feat);
    new_sf->SetLocation(*loc);
    if (!loc->IsNull() &&
        (loc->IsPartialStart(eExtreme_Biological) || 
        loc->IsPartialStop(eExtreme_Biological))) {
        new_sf->SetPartial(true);
    }


    // If Cdregion need to consider changes in frameshift
    if (new_sf->GetData().IsCdregion()) {
        const TSeqPos offset = x_GetStartOffset(feat, from, to);
        x_UpdateFrame(offset, new_sf->SetData().SetCdregion());

        if (new_sf->SetData().SetCdregion().IsSetCode_break()) {
            // iterate over code breaks and remove if they fall outside the range
            list<CRef<CCode_break>>& code_breaks = new_sf->SetData().SetCdregion().SetCode_break();
            code_breaks.remove_if(SOutsideRange(from,to));
            if (code_breaks.empty()) {
                new_sf->SetData().SetCdregion().ResetCode_break();
            }
            else {
                const auto strand = loc->GetStrand();
                // Trim the 3' end
                if (strand != eNa_strand_minus) {
                    for (auto code_break : code_breaks) {
                        const TSeqPos cb_to = code_break->GetLoc().GetTotalRange().GetTo();
                        if (cb_to > to) {
                            x_TrimCodeBreak(from, to, *code_break);
                        }
                    }
                }
                else { // strand == eNa_strand_minus
                    for (auto code_break : code_breaks) {
                        const TSeqPos cb_from = code_break->GetLoc().GetTotalRange().GetFrom();
                        if (cb_from < from) {
                            x_TrimCodeBreak(from, to, *code_break);
                        }
                    }
                } 
            }
        }
    }
    else 
    if (new_sf->GetData().GetSubtype() == CSeqFeatData::eSubtype_tRNA) {
        auto& rna = new_sf->SetData().SetRna();
        if (rna.IsSetExt() && rna.GetExt().IsTRNA()) {
            x_TrimTrnaExt(from, to, rna.SetExt().SetTRNA());
        }
    }
    return new_sf;
}