Skip to content
Snippets Groups Projects
Commit a39d873d authored by Marco Biasini's avatar Marco Biasini Committed by Valerio Mariani
Browse files

added "role" attribute to sequence

parent 02c8cc95
No related branches found
No related tags found
No related merge requests found
......@@ -87,7 +87,8 @@ SequenceHandle shift_reference(const ConstSequenceHandle& ref_seq,
}
new_sequence << ref_str.substr(last);
SequenceHandle s=CreateSequence(ref_seq.GetName(),
new_sequence.str());
new_sequence.str(),
ref_seq.GetRole());
if (ref_seq.HasAttachedView())
s.AttachView(ref_seq.GetAttachedView());
s.SetOffset(ref_seq.GetOffset());
......@@ -122,7 +123,8 @@ SequenceHandle realign_sequence(const AlignmentHandle& aln,
}
new_sequence << s2.GetOneLetterCode(i);
}
SequenceHandle s=CreateSequence(s2.GetName(), new_sequence.str());
SequenceHandle s=CreateSequence(s2.GetName(), new_sequence.str(),
s2.GetRole());
if (s2.HasAttachedView())
s.AttachView(s2.GetAttachedView());
s.SetOffset(s2.GetOffset());
......
......@@ -34,15 +34,15 @@ BOOST_AUTO_TEST_SUITE(ost_seq_alg)
BOOST_AUTO_TEST_CASE(merge_pairwise_alignments_one)
{
SequenceHandle ref=CreateSequence("REF", "abcdefghijklmn");
SequenceHandle ref=CreateSequence("REF", "abcdefghijklmn", "R");
SequenceHandle s1=CreateSequence("S1", "abcd---efghijklmn");
SequenceHandle s2=CreateSequence("S2", "abcdxyzefghijklmn");
SequenceHandle s2=CreateSequence("S2", "abcdxyzefghijklmn", "X");
AlignmentHandle aln1=CreateAlignment();
aln1.AddSequence(s1);
aln1.AddSequence(s2);
SequenceHandle s3=CreateSequence("S1", "abcdefghij---klmn");
SequenceHandle s4=CreateSequence("S2", "abcdefghijxyzklmn");
SequenceHandle s4=CreateSequence("S2", "abcdefghijxyzklmn", "Y");
AlignmentHandle aln2=CreateAlignment();
aln2.AddSequence(s3);
......@@ -55,6 +55,9 @@ BOOST_AUTO_TEST_CASE(merge_pairwise_alignments_one)
BOOST_CHECK_EQUAL(seqs[0].GetString(), "abcd---efghij---klmn");
BOOST_CHECK_EQUAL(seqs[1].GetString(), "abcdxyzefghij---klmn");
BOOST_CHECK_EQUAL(seqs[2].GetString(), "abcd---efghijxyzklmn");
BOOST_CHECK_EQUAL(seqs[0].GetRole(), "R");
BOOST_CHECK_EQUAL(seqs[1].GetRole(), "X");
BOOST_CHECK_EQUAL(seqs[2].GetRole(), "Y");
}
BOOST_AUTO_TEST_CASE(merge_pairwise_alignments_two)
......
......@@ -257,6 +257,8 @@ void const_seq_handle_def(O& bp_class)
.add_property("last_non_gap", &C::GetLastNonGap)
.def("GetAttachedView", &C::GetAttachedView)
.def("GetGaplessString", &C::GetGaplessString)
.add_property("role", make_function(&C::GetRole,
return_value_policy<copy_const_reference>()))
.def("GetString", &C::GetString,
return_value_policy<copy_const_reference>())
.def("GetName", &C::GetName,
......@@ -299,6 +301,9 @@ void export_sequence()
make_function(&SequenceHandle::GetString,
return_value_policy<copy_const_reference>()),
&SequenceHandle::SetString)
.add_property("role", make_function(&SequenceHandle::GetRole,
return_value_policy<copy_const_reference>()),
&SequenceHandle::SetRole)
.def("SetName", &SequenceHandle::SetName)
.add_property("name",
make_function(&SequenceHandle::GetName,
......@@ -312,7 +317,8 @@ void export_sequence()
implicitly_convertible<SequenceHandle, ConstSequenceHandle>();
def("CreateSequence", &CreateSequence);
def("CreateSequence", &CreateSequence,
(arg("name"), arg("seq"), arg("role")="UNKNOWN"));
/*class_<SequenceHandleList>("SequenceHandleList", init<>())
.def(vector_indexing_suite<SequenceHandleList>())
;*/
......@@ -348,6 +354,9 @@ void export_sequence()
.def("GetSequences", &AlignmentHandle::GetSequences)
.def("GetCoverage", &AlignmentHandle::GetCoverage)
.def("AttachView", attach_view_a)
.def("SetSequenceRole", &AlignmentHandle::SetSequenceRole)
.def("GetSequenceRole", &AlignmentHandle::GetSequenceRole,
return_value_policy<copy_const_reference>())
.def("AttachView", attach_view_b)
.def("Cut", &AlignmentHandle::Cut)
.def("MakeRegion", &AlignmentHandle::MakeRegion)
......
......@@ -313,4 +313,20 @@ mol::EntityViewPair AlignmentHandle::GetMatchingBackboneViews(int idx0, int idx1
return mol::EntityViewPair(v1, v2);
}
const String& AlignmentHandle::GetSequenceRole(int seq_index)
{
this->CheckValidity();
return impl_->GetSequence(seq_index)->GetRole();
}
void AlignmentHandle::SetSequenceRole(int seq_index, const String& role)
{
this->CheckValidity();
impl_->GetSequence(seq_index)->SetRole(role);
}
}}
......@@ -170,6 +170,10 @@ public:
/// between 0 (no coverage) and 1 (full coverage)
Real GetCoverage(int seq_index) const;
const String& GetSequenceRole(int seq_index);
void SetSequenceRole(int seq_index, const String& role);
private:
void CheckValidity() const;
impl::SequenceListImplPtr impl_;
......
......@@ -55,11 +55,12 @@ bool SequenceImpl::IsSequenceStringSane(const String& seq_string)
}
SequenceImplPtr SequenceImpl::FromString(const String& seq_name,
const String& seq_string)
const String& seq_string,
const String& role)
{
if (SequenceImpl::IsSequenceStringSane(seq_string)) {
return SequenceImplPtr(new SequenceImpl(seq_name, seq_string));
return SequenceImplPtr(new SequenceImpl(seq_name, seq_string, role));
}
throw InvalidSequence();
}
......@@ -102,15 +103,15 @@ void SequenceImpl::SetString(const String& seq)
}
SequenceImpl::SequenceImpl(const String& seq_name,
const String& seq_string)
: seq_name_(seq_name), seq_string_(seq_string), offset_(0)
const String& seq_string, const String& role)
: seq_name_(seq_name), seq_string_(seq_string), seq_role_(role), offset_(0)
{
this->ShiftsFromSequence();
}
SequenceImplPtr SequenceImpl::Copy() const
{
SequenceImplPtr new_seq(new SequenceImpl(seq_name_, seq_string_));
SequenceImplPtr new_seq(new SequenceImpl(seq_name_, seq_string_, seq_role_));
new_seq->offset_=offset_;
new_seq->shifts_=shifts_;
new_seq->attached_view_=attached_view_;
......
......@@ -50,7 +50,8 @@ class DLLEXPORT_OST_SEQ SequenceImpl : public GenericPropContainerImpl {
public:
/// \brief Construct new sequence object from sequence_string.
static SequenceImplPtr FromString(const String& seq_name,
const String& sequence_string);
const String& sequence_string,
const String& role="UNKNOWN");
/// \brief Get residue index corresponding to given sequence position
/// \param pos zero-based index
......@@ -105,7 +106,8 @@ public:
///
/// If you want to check whether the sequence String does only contain
/// valid characters use \c CreateSequence instead.
SequenceImpl(const String& seq_name, const String& sequence_string);
SequenceImpl(const String& seq_name, const String& sequence_string,
const String& role);
/// \brief get one letter code of residue at position
char GetOneLetterCode(int position) const;
......@@ -148,7 +150,15 @@ public:
{
return seq_string_[index];
}
const String& GetRole() const
{
return seq_role_;
}
void SetRole(const String& role)
{
seq_role_=role;
}
private:
/// \brief Recalculates gap shifts from sequence.
......@@ -169,6 +179,7 @@ private:
} Shift;
String seq_name_;
String seq_string_;
String seq_role_;
std::list<Shift> shifts_;
bool editing_;
int offset_;
......
......@@ -59,6 +59,25 @@ char ConstSequenceHandle::operator[](int index) const
const String& ConstSequenceHandle::GetRole() const
{
this->CheckValidity();
return Impl()->GetRole();
}
const String& SequenceHandle::GetRole() const
{
this->CheckValidity();
return Impl()->GetRole();
}
void SequenceHandle::SetRole(const String& role) const
{
this->CheckValidity();
Impl()->SetRole(role);
}
void ConstSequenceHandle::CheckValidity() const
{
......@@ -78,9 +97,10 @@ impl::SequenceImplPtr& ConstSequenceHandle::Impl() const
}
SequenceHandle CreateSequence(const String& name, const String& seq)
SequenceHandle CreateSequence(const String& name, const String& seq,
const String& role)
{
return SequenceHandle(impl::SequenceImpl::FromString(name, seq));
return SequenceHandle(impl::SequenceImpl::FromString(name, seq, role));
}
......@@ -222,6 +242,7 @@ SequenceHandle SequenceFromInfo(info::InfoGroup& group)
}
#endif
std::ostream& operator<<(std::ostream& os, const ConstSequenceHandle& sequence)
{
if (sequence.IsValid()) {
......
......@@ -122,6 +122,8 @@ public:
/// \sa SequenceHandle::AttachView(const mol::EntityView&, const String&)
bool HasAttachedView() const;
const String& GetRole() const;
bool operator==(const ConstSequenceHandle& rhs) const;
bool operator!=(const ConstSequenceHandle& rhs) const;
......@@ -286,6 +288,10 @@ public:
/// \internal
SequenceHandle(const impl::SequenceImplPtr& impl);
const String& GetRole() const;
void SetRole(const String& role) const;
impl::SequenceImplPtr& Impl() const;
GenericPropContainerImpl* GpImpl();
......@@ -297,9 +303,9 @@ private:
};
SequenceHandle DLLEXPORT_OST_SEQ CreateSequence(const String& name,
const String& seq);
#if(OST_INFO_ENABLED)
const String& seq,
const String& role="UNKNOWN");
/// \brief export sequence to info
void DLLEXPORT_OST_SEQ SequenceToInfo(const ConstSequenceHandle& sequence,
info::InfoGroup& group);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment