49 #include <wx/filedlg.h>
50 #include <wx/choicdlg.h>
51 #include <wx/msgdlg.h>
58 wxFileDialog
file(parent,
wxT(
"Import file"), wxEmptyString, wxEmptyString,
60 if (
file.ShowModal() != wxID_OK) {
75 if (dlg.ShowModal() == wxID_OK) {
96 for (
size_t index = 0; index <
m_Ids.size(); ++index) {
100 }
catch (exception &) {
106 for (
CBioseq_CI bi(tse); bi && !found; ++bi) {
107 for (
auto&& id_it : bi->GetId()) {
109 if (id2 && id1->
Match(*id2)) {
133 wxArrayString choices;
134 choices.Add(
_(
"All unmatched sequences are far pointers"));
135 choices.Add(
_(
"Remove all unmatched sequences from the alignment"));
136 choices.Add(
_(
"Read in a file that maps alignment IDs to sequence IDs"));
143 msg <<
" from alignment in set";
145 int answer = wxGetSingleChoiceIndex(msg,
_(
"Unmatched sequences found"), choices);
149 else if (answer == 1) {
152 else if (answer == 2) {
156 return (answer != -1);
163 SFind_ID(
const string& id_name) : m_IdName(id_name) {}
165 bool operator() (
const pair<string, string>& str_pair)
const
175 for (CUpdateAlign::TIdToRowVec::iterator it = nonPresentIDs.begin();
176 it != nonPresentIDs.end(); ++it) {
177 if (it->second == index) {
181 return nonPresentIDs.end();
184 string s_GetIDLabel(
const string& initial_val)
186 string id_label = initial_val;
187 size_t pos = id_label.find(
"|");
188 if (pos != string::npos) {
189 id_label = id_label.substr(pos + 1, string::npos);
205 int dim =
static_cast<int>(dense_seg.
GetIds().size());
209 rows.push_back(it.second);
218 auto starts_it = dense_seg.
GetStarts().begin();
220 for (
int seg = 0; seg < numseg; ++seg) {
221 for (
int index = 0; index < dim; ++index) {
222 if (find(rows.begin(), rows.end(), index) == rows.end()) {
223 new_starts.push_back(*starts_it);
234 auto strand_it = dense_seg.
GetStrands().begin();
236 for (
int seg = 0; seg < numseg; ++seg) {
237 for (
int index = 0; index < dim; ++index) {
238 if (find(rows.begin(), rows.end(), index) == rows.end()) {
239 new_strands.push_back(*strand_it);
250 for (
size_t index = 0; index < dense_seg.
GetIds().size(); ++index) {
251 if (find(rows.begin(), rows.end(), (
int)index) == rows.end()) {
252 new_ids.push_back(dense_seg.
GetIds()[index]);
258 dense_seg.
SetIds().swap(new_ids);
274 size_t previous_ids = dense_seg.
GetIds().size();
277 for (
size_t index = 0; index < dense_seg.
GetIds().
size(); ++index) {
280 if ((
int)index == it.second) {
281 string farptrID =
"acc" + s_GetIDLabel(it.first);
283 new_ids.push_back(new_id);
290 new_ids.push_back(dense_seg.
GetIds()[index]);
294 dense_seg.
SetIds().swap(new_ids);
308 vector<pair<string, string>> oldId_toNewId;
309 wxFileDialog
file(parent,
wxT(
"Import ID map from file"), wxEmptyString, wxEmptyString,
311 wxFD_OPEN | wxFD_FILE_MUST_EXIST);
312 if (
file.ShowModal() != wxID_OK) {
316 wxString path =
file.GetPath();
317 if (!path.IsEmpty()) {
322 string str = *++line_reader;
326 list<string> row_values;
328 if (row_values.size() == 2) {
329 oldId_toNewId.emplace_back(*row_values.begin(), *row_values.rbegin());
331 }
while (!line_reader.
AtEOF());
335 size_t previous_ids = dense_seg.
GetIds().size();
338 string unmapped_ids =
"(";
341 for (
size_t index = 0; index < dense_seg.
SetIds().
size(); ++index) {
344 new_ids.push_back(dense_seg.
GetIds()[index]);
347 std::function<
bool(
const pair<string, string>& str_pair)> tester = SFind_ID(id_it->first);
348 auto map_it = find_if(begin(oldId_toNewId), end(oldId_toNewId), tester);
349 if (map_it == oldId_toNewId.end()) {
351 unmapped_ids += id_it->first;
352 unmapped_ids +=
", ";
353 new_ids.push_back(dense_seg.
GetIds()[index]);
357 new_ids.push_back(new_id);
362 dense_seg.
SetIds().swap(new_ids);
365 unmapped_ids.pop_back();
366 unmapped_ids.pop_back();
369 string msg =
"Mapping not found for ";
378 msg +=
"Is this a far pointer? ";
381 msg +=
"Are these far pointers?";
384 if (wxYES == wxMessageBox(
ToWxString(msg),
"Info", wxYES_DEFAULT|wxYES_NO, parent)) {
451 const string&
id = (*iter2).GetID();
452 int line_num = (*iter2).GetLineNum();
458 errmsg +=
"At line ";
462 errmsg +=
"(Sequence ID ";
466 errmsg += (*iter2).GetMsg();
479 vector<CAlnReader::EAlphabet> alphas;
494 ITERATE(vector<CAlnReader::EAlphabet>, iter, alphas) {
511 _TRACE(
"reading text alignment failed: " << e.what());
class CAlnReader supports importing a large variety of text-based alignment formats into standard dat...
const TErrorList & GetErrorList(void) const
void Read(bool guess, bool generate_local_ids=false, objects::ILineErrorListener *pErrorListener=nullptr)
void SetMatch(const string &value)
CRef< objects::CSeq_align > GetSeqAlign(TFastaFlags fasta_flags=0, objects::ILineErrorListener *pErrorListener=nullptr)
Create ASN.1 classes from the parsed alignment.
const vector< string > & GetIds(void) const
Parsed result data accessors.
void SetMiddleGap(const string &value)
void SetEndGap(const string &value)
void SetBeginningGap(const string &value)
void SetAlphabet(const string &value)
void SetMissing(const string &value)
void RemovePureGapSegs()
Remove any segments in which every row has a gap (these can arise when ExtractRows is used)
static wxString GetDialogFilter(EFileType fileType)
const CTextAlignParams & GetData() const
void SetData(const CTextAlignParams &data)
Simple implementation of ILineReader for i(o)streams.
void SetEnd(wxString value)
void SetMatch(wxString value)
void SetMiddle(wxString value)
wxString GetBegin() const
void SetSeqType(int value)
wxString GetUnknown() const
wxString GetMatch() const
void SetBegin(wxString value)
void SetUnknown(wxString value)
wxString GetMiddle() const
vector< pair< string, int > > TIdToRowVec
bool x_ProcessNotPresentIDs(wxWindow *parent)
CRef< objects::CSeq_align > m_SeqAlign
void x_ReadAlign(const CTextAlignParams ¶ms)
TIdToRowVec m_NonPresentIDs
void x_ChangeIDsToFarPointers()
void x_FindNotPresentIDs(objects::CSeq_entry_Handle tse)
void x_MapNonPresentIDs(wxWindow *parent)
void x_RemoveIDsFromAlign()
void apply(objects::CSeq_entry_Handle tse, ICommandProccessor *cmdProcessor, wxWindow *parent)
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
static unsigned int line_num
static const char * str(char *buf, int n)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
EDialogReturnValue NcbiMessageBox(const string &message, TDialogType type=eDialog_Ok, EDialogIcon icon=eIcon_Exclamation, const string &title="Error", EDialogTextMode text_mode=eRaw)
bool AtEOF(void) const
Indicates (negatively) whether there is any more input.
bool Match(const CSeq_id &sid2) const
Match() - TRUE if SeqIds are equivalent.
@ fParse_Default
By default in ParseIDs and IsValid, allow raw parsable non-numeric accessions and plausible local acc...
void Reset(void)
Reset reference object.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
bool IsSetNumseg(void) const
number of segments here Check if a value has been assigned to Numseg data member.
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.
vector< ENa_strand > TStrands
vector< TSignedSeqPos > TStarts
void SetDim(TDim value)
Assign a value to Dim data member.
vector< CRef< CSeq_id > > TIds
TStarts & SetStarts(void)
Assign a value to Starts data member.
TStrands & SetStrands(void)
Assign a value to Strands data member.
bool IsSetStarts(void) const
start OFFSETS in ids order within segs Check if a value has been assigned to Starts data member.
const TIds & GetIds(void) const
Get the Ids member data.
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.
void SetData(TData &value)
Assign a value to Data data member.
Lightweight interface for getting lines of data with minimal memory copying.
const struct ncbi::grid::netcache::search::fields::SIZE size
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Utility macros and typedefs for exploring NCBI objects from seqset.asn.
static string s_FormatErrors(const CAlnReader::TErrorList &errors)
wxString ToWxString(const string &s)
string ToStdString(const wxString &s)