58 for (; feat_ci; ++feat_ci)
62 int length = orig_length;
64 if (x_IsProtLocation(feat_ci->
GetLocation(), bsh, scope))
77 if ( x_AdjustLocation(new_feat->
SetLocation(),length,from,to,diff) )
86 x_AdjustCdregionFrame(new_feat, diff);
91 if ((*codebreak)->IsSetLoc())
93 if ( x_AdjustLocation((*codebreak)->SetLoc(),length,from,to))
100 new_feat->
SetData().SetCdregion().ResetCode_break();
106 if ( x_AdjustLocation(new_feat->
SetData().SetRna().SetExt().SetTRNA().SetAnticodon(), length,from,to))
108 new_feat->
SetData().SetRna().SetExt().SetTRNA().ResetAnticodon();
115 if (clone_set.
IsSet())
117 for (CClone_seq_set::Tdata::iterator clone_it = clone_set.
Set().begin(); clone_it != clone_set.
Set().end(); ++clone_it)
119 if ((*clone_it)->IsSetLocation())
121 if ( x_AdjustLocation((*clone_it)->SetLocation(), length,from,to))
123 (*clone_it)->ResetLocation();
126 if ((*clone_it)->IsSetSeq())
128 if ( x_AdjustLocation((*clone_it)->SetSeq(),length,from,to))
130 (*clone_it)->ResetSeq();
140 x_UpdateVariation(var, length,from,to);
158 CVariation_inst::TDelta::iterator delta_it = var.
SetData().SetInstance().SetDelta().begin();
159 while ( delta_it != var.
SetData().SetInstance().SetDelta().end())
161 bool to_delete =
false;
162 if ((*delta_it)->IsSetSeq() && (*delta_it)->GetSeq().IsLoc() && x_AdjustLocation((*delta_it)->SetSeq().SetLoc(), length,from,to))
164 delta_it = var.
SetData().SetInstance().SetDelta().erase(delta_it);
170 var.
SetData().SetInstance().ResetDelta();
174 for ( CVariation_ref::C_Data::C_Set::TVariations::iterator var_it = var.
SetData().SetSet().SetVariations().begin(); var_it != var.
SetData().SetSet().SetVariations().end(); ++var_it)
176 x_UpdateVariation(**var_it, length,from,to);
183 if ((*con_it)->IsVariation())
185 x_UpdateVariation((*con_it)->SetVariation(), length,from,to);
196 return prot_bsh.
IsAa();
209 diff += from - begin;
218 if (end > length - 1)
221 diff += end - (length - 1);
229 return x_AdjustLocation(loc, length, from, to, diff);
244 if (end < from || begin > to)
247 x_AdjustInt(begin, end, from, to, length, diff, strand);
256 if (point < from || point > to)
264 if (loc.SetPacked_int().IsSet())
266 vector<CPacked_seqint::Tdata::iterator> del;
267 for (CPacked_seqint::Tdata::iterator p = loc.SetPacked_int().Set().begin(); p != loc.SetPacked_int().Set().end(); ++p)
272 if (end < from || begin > to)
281 x_AdjustInt(begin, end, from, to, length, diff, strand);
285 for (
unsigned int i=0;
i<del.size();
i++)
287 CPacked_seqint::Tdata::iterator p = del[
i];
288 loc.SetPacked_int().Set().erase(p);
290 if (loc.SetPacked_int().Set().empty())
297 if (loc.SetPacked_pnt().IsSetPoints())
299 vector<CPacked_seqpnt::TPoints::iterator> del;
300 for (CPacked_seqpnt::TPoints::iterator p = loc.SetPacked_pnt().SetPoints().begin(); p != loc.SetPacked_pnt().SetPoints().end(); ++p)
303 if (point < from || point > to)
314 for (
unsigned int i=0;
i<del.size();
i++)
316 CPacked_seqpnt::TPoints::iterator p = del[
i];
317 loc.SetPacked_pnt().SetPoints().erase(p);
319 if (loc.SetPacked_pnt().SetPoints().empty())
326 if (loc.SetMix().IsSet())
328 vector<CSeq_loc_mix::Tdata::iterator> del;
329 for (CSeq_loc_mix::Tdata::iterator p = loc.SetMix().Set().begin(); p != loc.SetMix().Set().end(); ++p)
331 CSeq_loc &loc2 = **p;
332 if (x_AdjustLocation(loc2, length, from,to,diff))
335 for (
unsigned int i=0;
i<del.size();
i++)
337 CSeq_loc_mix::Tdata::iterator p = del[
i];
338 loc.SetMix().Set().erase(p);
340 if (loc.SetMix().Set().empty())
347 if (loc.SetEquiv().IsSet())
349 vector<CSeq_loc_equiv::Tdata::iterator> del;
350 for (CSeq_loc_equiv::Tdata::iterator p = loc.SetEquiv().Set().begin(); p != loc.SetEquiv().Set().end(); ++p)
352 CSeq_loc &loc2 = **p;
353 int orig_diff = diff;
354 if (x_AdjustLocation(loc2, length, from,to,orig_diff))
356 if (p == loc.SetEquiv().Set().begin())
359 for (
unsigned int i=0;
i<del.size();
i++)
361 CSeq_loc_equiv::Tdata::iterator p = del[
i];
362 loc.SetEquiv().Set().erase(p);
364 if (loc.SetEquiv().Set().empty())
387 int new_offset = (orig_frame - diff) % 3;
388 if (orig_frame < diff && new_offset != 0)
390 new_offset = 3 - ((diff - orig_frame) % 3);
394 switch (new_offset) {
408 feat->
SetData().SetCdregion().SetFrame(new_frame);
439 new_inst->Assign(prot_bsh.
GetInst());
440 new_inst->ResetExt();
441 new_inst->SetRepr(objects::CSeq_inst::eRepr_raw);
442 new_inst->SetSeq_data().SetNcbieaa().Set(
prot);
455 for ( ; prot_feat_ci; ++prot_feat_ci )
462 new_feat->
SetLocation().SetInt().SetTo(new_inst->GetLength() - 1);
498 for (; align_ci; ++align_ci)
523 for (CBioseq::TId::const_iterator seqid = seqids.begin(); seqid != seqids.end(); ++seqid)
524 for (
unsigned int ii = 0; ii < ids.size(); ++ii) {
525 if ( ids[ii]->Match(**seqid) ) {
534 x_AdjustDensegAlignment(new_align, row, from, to);
539 command->AddCommand(*chgAlign);
547 command->AddCommand(*delAlign);
557 TSeqPos cut_len = cut_to - cut_from + 1;
558 if (cut_to < cut_from) {
559 cut_len = cut_from - cut_to + 1;
567 x_CutDensegSegment(align, row, cut_from);
568 x_CutDensegSegment(align, row, cut_from + cut_len);
578 else if (seg_start < cut_from) {
581 else if (seg_start >= cut_from &&
582 seg_start + denseg.
GetLens()[curseg] <= cut_from + cut_len) {
584 align->
SetSegs().SetDenseg().SetStarts()[index] = -1;
588 align->
SetSegs().SetDenseg().SetStarts()[index] -= cut_len;
608 if ( !x_FindSegment(denseg, row, pos, foundseg, seg_start) ) {
614 if (pos == seg_start) {
665 first_len = pos - seg_start;
666 second_len = denseg.
GetLens()[foundseg] - first_len;
669 second_len = pos - seg_start;
670 first_len = denseg.
GetLens()[foundseg] - second_len;
691 new_denseg->
SetLens().push_back(first_len);
709 new_denseg->
SetLens().push_back(second_len);
735 align->
SetSegs().SetDenseg(*new_denseg);
744 for (seg = 0; seg < denseg.
GetNumseg(); ++seg) {
748 if (pos >= start && pos < start +
len) {
767 new_loc->Assign(new_graph->
GetLoc());
768 result = x_AdjustLocation(*new_loc,length,from,to);
769 new_graph->
SetLoc(*new_loc);
785 TSeqPos copy_start = graph_start;
786 if (trim_start > graph_start) {
787 copy_start = trim_start;
789 TSeqPos copy_stop = graph_stop;
790 if (trim_stop < graph_stop) {
791 copy_stop = trim_stop;
799 switch ( src_data.
Which() ) {
808 copy_start -= graph_start;
809 copy_stop -= graph_start;
819 new_graph->
SetNumval(copy_stop - copy_start + 1);
822 return x_UpdateSeqGraphLoc(new_graph, trim_start, trim_stop, length, seqid);
834 for (; graph_ci; ++graph_ci)
849 for (CBioseq::TId::const_iterator seqid = seqids.begin(); seqid != seqids.end(); ++seqid)
852 if ( graph.
GetLoc().GetId()->Match(**seqid) ) {
853 if (x_TrimSeqGraphData(new_graph, graph, from, to, length, *seqid))
856 command->AddCommand(*delGraph);
862 command->AddCommand(*chgGraph);
879 if( bioseq_len < 1 ) {
880 return eResult_NoTrimNeeded;
885 if( ! x_TestFlag(fFlags_DoNotTrimBeginning) ) {
886 leftmost_good_base = x_FindWhereToTrim(
887 seqvec, leftmost_good_base, rightmost_good_base,
891 if( leftmost_good_base > rightmost_good_base) {
892 if (x_IsThereGapNotAtTheEnd(bioseq_handle, 0, bioseq_len -1, bioseq_len))
893 return eResult_NoTrimNeeded;
895 return x_TrimToNothing( bioseq_handle );
898 if (x_IsThereGapNotAtTheEnd(bioseq_handle, leftmost_good_base, bioseq_len -1, bioseq_len))
900 leftmost_good_base = 0;
903 if( ! x_TestFlag(fFlags_DoNotTrimEnd) ) {
904 rightmost_good_base =
906 seqvec, rightmost_good_base, leftmost_good_base,
910 if( leftmost_good_base > rightmost_good_base) {
911 if (x_IsThereGapNotAtTheEnd(bioseq_handle, 0, bioseq_len -1, bioseq_len))
912 return eResult_NoTrimNeeded;
914 return x_TrimToNothing( bioseq_handle );
917 if (x_IsThereGapNotAtTheEnd(bioseq_handle, 0, rightmost_good_base, bioseq_len))
919 rightmost_good_base = bioseq_len -1;
923 if( (leftmost_good_base == 0) &&
924 (rightmost_good_base == (bioseq_len - 1)) )
926 return eResult_NoTrimNeeded;
932 leftmost_good_base, rightmost_good_base,
935 left = leftmost_good_base;
936 right = rightmost_good_base;
937 return eResult_SuccessfullyTrimmed;
943 if (from == 0 && to == length - 1)
945 bool gap_inside =
false;
947 for (
TSeqPos pos = 1; pos < length - 1; pos++)
953 bool gap_left =
false;
956 for (
TSeqPos pos = 1; pos < from; pos++)
960 bool gap_right =
false;
963 for (
TSeqPos pos = to + 1; pos < length - 1; pos++)
967 return gap_left || gap_right;
@ eExtreme_Positional
numerical value
@ eExtreme_Biological
5' and 3'
virtual EResult Trim(objects::CBioseq_Handle &bioseq_handle, TSignedSeqPos &left, TSignedSeqPos &right)
void x_UpdateVariation(objects::CVariation_ref &var, int length, int from, int to)
bool x_TrimSeqGraphData(CRef< objects::CSeq_graph > new_graph, const objects::CMappedGraph &orig_graph, TSeqPos trim_start, TSeqPos trim_stop, int length, const CRef< objects::CSeq_id > seqid)
bool x_IsThereGapNotAtTheEnd(objects::CBioseq_Handle bsh, TSignedSeqPos from, TSignedSeqPos to, int length)
void TrimAlignments(CRef< CCmdComposite > command, objects::CBioseq_Handle bsh, const objects::CBioseq::TId &seqids, TSeqPos from, TSeqPos to)
void AdjustAndTranslate(objects::CBioseq_Handle bsh, int length, int from, int to, CRef< CCmdComposite > command, objects::CScope &scope, map< objects::CBioseq_Handle, set< objects::CSeq_feat_Handle > > &product_to_cds)
bool x_UpdateSeqGraphLoc(CRef< objects::CSeq_graph > new_graph, TSeqPos from, TSeqPos to, int length, const CRef< objects::CSeq_id > seqid)
bool x_FindSegment(const objects::CDense_seg &denseg, objects::CDense_seg::TDim row, TSeqPos pos, objects::CDense_seg::TNumseg &seg, TSeqPos &seg_start) const
void x_AdjustCdregionFrame(CRef< objects::CSeq_feat > feat, int diff)
bool x_AdjustLocation(objects::CSeq_loc &loc, int length, int from, int to, int &diff)
void TrimSeqGraphs(CRef< CCmdComposite > command, objects::CBioseq_Handle bsh, const objects::CBioseq::TId &seqids, TSeqPos from, TSeqPos to, int length)
void x_RetranslateCDS(objects::CScope &scope, CRef< CCmdComposite > command, CRef< objects::CSeq_feat > cds, const objects::CSeq_feat &old_cds)
void x_AdjustInt(int &begin, int &end, int from, int to, int length, int &diff, objects::ENa_strand strand)
void x_CutDensegSegment(CRef< objects::CSeq_align > align, objects::CDense_seg::TDim row, TSeqPos pos)
void x_AdjustDensegAlignment(CRef< objects::CSeq_align > align, objects::CDense_seg::TDim row, TSeqPos cut_from, TSeqPos cut_to)
bool x_IsProtLocation(const objects::CSeq_loc &loc, objects::CBioseq_Handle bsh, objects::CScope &scope)
SeqMap related exceptions.
namespace ncbi::objects::
constexpr auto begin(const ct_const_array< T, N > &in) noexcept
constexpr auto end(const ct_const_array< T, N > &in) noexcept
static const char si[8][64]
unsigned int TSeqPos
Type for sequence locations and lengths.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
int TSignedSeqPos
Type for signed sequence position.
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
bool IsPartialStart(ESeqLocExtremes ext) const
check start or stop of location for e_Lim fuzz
TSeqPos GetStart(ESeqLocExtremes ext) const
Return start and stop positions of the seq-loc.
void SetPartialStart(bool val, ESeqLocExtremes ext)
set / remove e_Lim fuzz on start or stop (lt/gt - indicating partial interval)
void SetPartialStop(bool val, ESeqLocExtremes ext)
bool IsPartialStop(ESeqLocExtremes ext) const
TSeqPos GetStop(ESeqLocExtremes ext) const
EResult
This indicates what happened with the trim.
static void Translate(const string &seq, string &prot, const CGenetic_code *code, bool include_stop=true, bool remove_trailing_X=false, bool *alt_start=NULL, bool is_5prime_complete=true, bool is_3prime_complete=true)
Translate a string using a specified genetic code.
CRef< CSeq_loc > Map(const CSeq_loc &src_loc)
Map seq-loc.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
CSeq_loc_Mapper_Base & SetMergeAbutting(void)
Merge only abutting intervals, keep overlapping.
@ eProductToLocation
Map from the feature's product to location.
@ eLocationToProduct
Map from the feature's location to product.
TClass GetClass(void) const
CBioseq_set_Handle GetParentBioseq_set(void) const
Return a handle for the parent Bioseq-set, or null handle.
CSeq_entry_Handle GetParentEntry(void) const
Get parent Seq-entry handle.
const CSeqFeatData & GetData(void) const
TSeqPos GetBioseqLength(void) const
bool IsSetProduct(void) const
bool IsProtein(void) const
CSeq_entry_Handle GetParentEntry(void) const
Return a handle for the parent seq-entry of the bioseq.
bool IsSetClass(void) const
CSeqFeatData::ESubtype GetFeatSubtype(void) const
bool IsSetData(void) const
CSeqVector GetSeqVector(EVectorCoding coding, ENa_strand strand=eNa_strand_plus) const
Get sequence: Iupacna or Iupacaa if use_iupac_coding is true.
const TInst & GetInst(void) const
@ eCoding_Iupac
Set coding to printable coding (Iupacna or Iupacaa)
const string & GetTitle(void) const
bool IsSetTitle(void) const
const CSeq_align & GetOriginalSeq_align(void) const
Get original alignment.
const CSeq_loc & GetLocation(void) const
const CSeq_feat & GetOriginalFeature(void) const
Get original feature with unmapped location/product.
const CSeq_feat_Handle & GetSeq_feat_Handle(void) const
Get original feature handle.
const CSeq_graph & GetOriginalGraph(void) const
Get original graph with unmapped location/product.
const CSeq_loc & GetLoc(void) const
CSeq_align_Handle GetSeq_align_Handle(void) const
Get original alignment handle.
const CSeq_graph::C_Graph & GetGraph(void) const
CSeq_graph_Handle GetSeq_graph_Handle(void) const
Get original graph handle.
bool IsInGap(TSeqPos pos) const
true if sequence at 0-based position 'pos' has gap Note: this method is not MT-safe,...
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
bool IsTRNA(void) const
Check if variant TRNA is selected.
bool IsSetAnticodon(void) const
location of anticodon Check if a value has been assigned to Anticodon data member.
bool IsSetExt(void) const
generic fields for ncRNA, tmRNA, miscRNA Check if a value has been assigned to Ext data member.
const TExt & GetExt(void) const
Get the Ext member data.
const TTRNA & GetTRNA(void) const
Get the variant data.
bool CanGetDim(void) const
Check if it is safe to call GetDim method.
const TDenseg & GetDenseg(void) const
Get the variant data.
TLens & SetLens(void)
Assign a value to Lens data member.
E_Choice Which(void) const
Which variant is currently selected.
bool IsSetStrands(void) const
Check if a value has been assigned to Strands data member.
const TStarts & GetStarts(void) const
Get the Starts member data.
void SetSegs(TSegs &value)
Assign a value to Segs data member.
const TLens & GetLens(void) const
Get the Lens member data.
bool CanGetNumseg(void) const
Check if it is safe to call GetNumseg method.
void SetDim(TDim value)
Assign a value to Dim data member.
bool CanGetIds(void) const
Check if it is safe to call GetIds method.
vector< CRef< CSeq_id > > TIds
bool CanGetSegs(void) const
Check if it is safe to call GetSegs method.
TDim GetDim(void) const
Get the Dim member data.
TStarts & SetStarts(void)
Assign a value to Starts data member.
TStrands & SetStrands(void)
Assign a value to Strands data member.
void SetNumseg(TNumseg value)
Assign a value to Numseg data member.
const TIds & GetIds(void) const
Get the Ids member data.
bool CanGetStarts(void) const
Check if it is safe to call GetStarts method.
TNumseg GetNumseg(void) const
Get the Numseg member data.
TIds & SetIds(void)
Assign a value to Ids data member.
const TStrands & GetStrands(void) const
Get the Strands member data.
const TSegs & GetSegs(void) const
Get the Segs member data.
bool CanGetLens(void) const
Check if it is safe to call GetLens method.
const TClone & GetClone(void) const
Get the variant data.
bool IsSetData(void) const
the specific data Check if a value has been assigned to Data data member.
void SetLocation(TLocation &value)
Assign a value to Location data member.
bool IsCdregion(void) const
Check if variant Cdregion is selected.
Tdata & Set(void)
Assign a value to data member.
void SetPartial(TPartial value)
Assign a value to Partial data member.
const TLocation & GetLocation(void) const
Get the Location member data.
TFrame GetFrame(void) const
Get the Frame member data.
const TData & GetData(void) const
Get the Data member data.
const TExcept_text & GetExcept_text(void) const
Get the Except_text member data.
bool IsSetExcept_text(void) const
explain if except=TRUE Check if a value has been assigned to Except_text data member.
void SetData(TData &value)
Assign a value to Data data member.
const TCdregion & GetCdregion(void) const
Get the variant data.
const TProduct & GetProduct(void) const
Get the Product member data.
bool IsClone(void) const
Check if variant Clone is selected.
bool IsVariation(void) const
Check if variant Variation is selected.
bool IsSet(void) const
Check if a value has been assigned to data member.
const TRna & GetRna(void) const
Get the variant data.
const TCode_break & GetCode_break(void) const
Get the Code_break member data.
bool IsRna(void) const
Check if variant Rna is selected.
bool IsSetCode_break(void) const
individual exceptions Check if a value has been assigned to Code_break data member.
bool IsSetClone_seq(void) const
Check if a value has been assigned to Clone_seq data member.
bool IsSetFrame(void) const
Check if a value has been assigned to Frame data member.
@ eFrame_not_set
not set, code uses one
@ eFrame_three
reading frame
void SetTo(TTo value)
Assign a value to To data member.
void SetPoint(TPoint value)
Assign a value to Point data member.
ENa_strand
strand of nucleic acid
TPoint GetPoint(void) const
Get the Point member data.
TFrom GetFrom(void) const
Get the From member data.
void SetFrom(TFrom value)
Assign a value to From data member.
TTo GetTo(void) const
Get the To member data.
bool IsNull(void) const
Check if variant Null is selected.
@ e_Equiv
equivalent sets of locations
void SetMin(TMin value)
Assign a value to Min data member.
TByte & SetByte(void)
Select the variant.
void SetNumval(TNumval value)
Assign a value to Numval data member.
TAxis GetAxis(void) const
Get the Axis member data.
TValues & SetValues(void)
Assign a value to Values data member.
TMax GetMax(void) const
Get the Max member data.
const TByte & GetByte(void) const
Get the variant data.
void SetGraph(TGraph &value)
Assign a value to Graph data member.
bool CanGetLoc(void) const
Check if it is safe to call GetLoc method.
void SetMax(TMax value)
Assign a value to Max data member.
TMin GetMin(void) const
Get the Min member data.
const TValues & GetValues(void) const
Get the Values member data.
E_Choice Which(void) const
Which variant is currently selected.
void SetLoc(TLoc &value)
Assign a value to Loc data member.
const TLoc & GetLoc(void) const
Get the Loc member data.
void SetAxis(TAxis value)
Assign a value to Axis data member.
void Reset(void)
Reset the whole object.
@ eClass_nuc_prot
nuc acid and coded proteins
list< CRef< CSeq_id > > TId
const TInstance & GetInstance(void) const
Get the variant data.
const TSet & GetSet(void) const
Get the variant data.
bool IsSetDelta(void) const
Sequence that replaces the location, in biological order.
TConsequence & SetConsequence(void)
Assign a value to Consequence data member.
const TDelta & GetDelta(void) const
Get the Delta member data.
void SetData(TData &value)
Assign a value to Data data member.
bool IsSetConsequence(void) const
Check if a value has been assigned to Consequence data member.
const TData & GetData(void) const
Get the Data member data.
bool IsInstance(void) const
Check if variant Instance is selected.
bool IsSet(void) const
Check if variant Set is selected.
bool IsSetVariations(void) const
Check if a value has been assigned to Variations data member.
bool IsSetData(void) const
Check if a value has been assigned to Data data member.
#define EDIT_EACH_CODEBREAK_ON_CDREGION(Itr, Var)
#define ERASE_CODEBREAK_ON_CDREGION(Itr, Var)
ERASE_CODEBREAK_ON_CDREGION.
CRef< CCmdComposite > GetDeleteFeatureCommand(const objects::CSeq_feat_Handle &fh, bool remove_proteins=true)