35 for (
int p = 0; splitBefore[p] != END__ && !
error; ++p) {
39 else if (splitBefore[p]<rest.
start()) error =
"invalid position order";
40 else error =
"empty range dectected";
43 ranges.push_back(next);
50 else ranges.push_back(rest);
57 return parts<0 ?
digits(-parts) : (parts<10 ? 1 : (parts<100 ? 2 : 3));
61 static SmartCharPtr ali;
68 for (
size_t r = 0; r<ranges.size(); ++r) {
69 if (r>0) buf.
put(
'-');
81 size_t seq_len = strlen(seq);
82 const int parts = ranges.size();
88 for (
int p = 0; p<parts && !
error; ++p) {
97 char *part = ranges[p].dup_corresponding_part(seq, seq_len);
122 for (
int p = 0; p<parts && !
error; ++p) {
150 if (ali_source_len<=0) {
157 const int parts = ranges.size();
158 if (parts<2 && !error) {
159 error =
GBS_global_string(
"Not enough parts (%i) specified to split alignment", parts);
163 bool is_aligned =
true;
165 const char *ali_type =
"rna";
170 for (
int p = 0; p<parts && !
error; ++p) {
178 if (overwriteAlignments) {
204 size_t data_count = 0;
205 size_t sai_data_count = 0;
206 size_t sequences_splitted = 0;
207 size_t sai_data_splitted = 0;
211 for (
int pass = 1; pass<=2 && !
error; ++pass) {
219 gb_species && !
error;
224 if (pass == 1) ++data_count;
227 if (!error) ++sequences_splitted;
243 if (!error) ++sai_data_splitted;
247 else if (pass == 2) {
256 size_t overall_data_splitted = sequences_splitted + sai_data_splitted;
257 if (overall_data_splitted) {
258 size_t split_count = overall_data_splitted*parts;
259 fprintf(stdout,
"Summary: splitted %zu element%s into %zu parts.\n", overall_data_splitted,
plural(overall_data_splitted), split_count);
263 error =
"No sequences were splitted (none of the handled species contained data in alignment; check settings)";
270 error = ta.
close(error);
286 void TEST_split_alignment() {
305 int split[] = { 41, 175, END__ };
312 int split[] = { 168, END__ };
320 int split[] = { 1, 160, 161, 336, END__ };
326 int split[] = { 25, 65, END__ };
332 int split[] = { 150, END__ };
339 int split[] = { END__ };
341 "Not enough parts (1) specified to split alignment");
344 int split[] = { 41, 470, END__ };
346 "last position exceeds overall length (=337)");
350 int split[] = { 336, 4100, END__ };
352 "last position exceeds overall length (=337)");
355 int split[] = { 337, 4100, END__ };
357 "position 338 exceeds overall length (=337)");
360 int split[] = { 338, 4100, END__ };
362 "position 339 exceeds overall length (=337)");
365 int split[] = { 0, 4100, END__ };
367 "empty range dectected");
371 int split[] = { 41, 30, 175, END__ };
373 "invalid position order");
376 int split[] = { 41, 41, 175, END__ };
378 "empty range dectected");
383 int split[] = { 41, 175, END__ };
385 "alignment 'ali_nosuch' not found");
391 const char *ali_conflict =
"ali_existing_3";
395 gb_ali_conflict =
GBT_create_alignment(gb_main, ali_conflict, 123, 0, 0,
"dna",
"by TEST_split_alignment");
400 int split[] = { 41, 175, END__ };
402 "alignment 'ali_existing_3' already exists");
411 int split[] = { 170, END__ };
429 #if defined(TEST_AUTO_UPDATE)
430 TEST_COPY_FILE(savename, expected);
431 #else // !defined(TEST_AUTO_UPDATE)
456 #define AWAR_SPLIT_ALI_BASE "split_ali/"
457 #define AWAR_SPLIT_ALI_BTMP "tmp/" AWAR_SPLIT_ALI_BASE
459 #define AWAR_SPLIT_ALI_TARGET AWAR_SPLIT_ALI_BTMP "target"
460 #define AWAR_SPLIT_ALI_POSITIONS AWAR_SPLIT_ALI_BASE "pos"
461 #define AWAR_SPLIT_ALI_MARKED AWAR_SPLIT_ALI_BASE "marked"
462 #define AWAR_SPLIT_ALI_OVERWRITE AWAR_SPLIT_ALI_BASE "overwrite"
466 const char *ali_part =
"ali_example_part";
500 int split_positions[numbers.
size()+1];
501 for (
size_t n = 0; n<numbers.
size() && !
error; ++n) {
502 const char *num = numbers[n];
503 split_positions[n] =
bio2info(atoi(num));
504 if (split_positions[n]<1) {
514 error =
split_alignment(gb_main, ali_source, ali_target_prefix, split_positions, markedOnly, overwrite);
517 free(ali_target_prefix);
528 const char *hyphen = strchr(editor_range,
'-');
531 if (editor_range[0]) {
532 error =
"expected range to contain '-'.";
535 error =
"No block has been highlighted in sequence editor.";
539 long i1 = atol(editor_range);
540 long i2 = atol(hyphen+1);
552 AW_window_simple *aws =
new AW_window_simple;
553 aws->init(awr,
"SPLIT_ALIGNMENT",
"Split alignment");
557 const int BUTTON_LENGTH = 10;
558 const int FIELD_LENGTH = 40;
559 const int LABEL_LENGTH = 30;
562 aws->auto_space(PAD/2, PAD);
564 aws->button_length(BUTTON_LENGTH);
567 aws->create_button(
"CLOSE",
"Close",
"C");
570 aws->create_button(
"HELP",
"Help",
"H");
574 aws->label_length(LABEL_LENGTH);
576 aws->label(
"Target alignment prefix:");
580 aws->label(
"Position(s) to split before:\n"
581 "(comma-separated)");
585 aws->button_length(LABEL_LENGTH-1);
587 aws->create_button(
"USE_EDITOR_RANGE",
"Use editor range:");
588 aws->button_length(FIELD_LENGTH);
590 aws->button_length(BUTTON_LENGTH);
593 aws->label(
"Split marked only:");
597 aws->label(
"Overwrite existing alignments:\n"
598 "(deletes ALL data)");
603 aws->create_button(
"GO",
"GO",
"G");
#define AWAR_SPLIT_ALI_OVERWRITE
static GB_ERROR calculate_and_check_ranges(int ali_source_len, const int *splitBefore, RangeVec &ranges)
GBDATA * GBT_first_SAI(GBDATA *gb_main)
GBDATA * GB_open(const char *path, const char *opent)
GBDATA * GBT_first_marked_species(GBDATA *gb_main)
GBDATA * GB_child(GBDATA *father)
GB_ERROR GBT_restore_marked_species(GBDATA *gb_main, const char *stored_marked)
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
PosRange intersection(PosRange r1, PosRange r2)
long GBT_mark_all(GBDATA *gb_main, int flag)
GBDATA * GBT_get_alignment(GBDATA *gb_main, const char *aliname)
bool ARB_is_alignment_relative_data(GBDATA *gb_data)
static void use_editor_range_cb(AW_window *aww)
char * ARB_strdup(const char *str)
char * GB_read_as_string(GBDATA *gbd)
const char * GBS_global_string(const char *templat,...)
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
void AW_POPDOWN(AW_window *window)
void auto_subtitles(const char *prefix)
int GB_unlink(const char *path)
AW_window * NT_create_splitAlignment_window(AW_root *awr)
GBDATA * GB_get_grandfather(GBDATA *gbd)
GB_ERROR GBT_delete_alignment(GBDATA *gbMain, const char *source)
GB_ERROR GBT_add_alignment_changekeys(GBDATA *gb_main, const char *ali)
const char * plural(NUM val)
vector< ExplicitRange > RangeVec
const char * read_char_pntr() const
GB_ERROR GB_await_error()
WindowCallback makeHelpCallback(const char *helpfile)
GB_TYPES GB_read_type(GBDATA *gbd)
GB_CSTR GB_read_key_pntr(GBDATA *gbd)
static GB_ERROR split_data_into_parts(GBDATA *gb_data, const RangeVec &ranges, const char *ali_target_prefix)
int GB_read_security_write(GBDATA *gbd)
CONSTEXPR_INLINE int digits(int parts)
static GB_ERROR split_alignment(GBDATA *gb_main, const char *ali_source, const char *ali_target_prefix, const int *splitBefore, bool markedOnly, bool overwriteAlignments)
GB_ERROR GB_save_as(GBDATA *gbd, const char *path, const char *savetype)
#define TEST_REJECT_NULL(n)
static void error(const char *msg)
GB_CSTR GB_path_in_ARBHOME(const char *relative_path)
static PosRange after(int pos)
GBDATA * GBT_next_marked_species(GBDATA *gb_species)
static void create_splitAlignment_awars(AW_root *root, AW_default properties, GBDATA *gb_main)
ASSERTING_CONSTEXPR_INLINE int info2bio(int infopos)
#define TEST_EXPECT_ZERO_OR_SHOW_ERRNO(iocond)
char * read_string() const
const char * target_ali_name(const char *ali_target_prefix, int p, int digits)
AW_awar * awar(const char *awar)
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
#define AWAR_SPLIT_ALI_MARKED
static GB_ERROR copy_field_into_partial_alignments(GBDATA *gb_data, const int parts, const char *ali_target_prefix)
static void split_ali_cb(AW_window *aww)
GBDATA * GBT_next_SAI(GBDATA *gb_sai)
ASSERTING_CONSTEXPR_INLINE int bio2info(int biopos)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
GB_ERROR close(GB_ERROR error)
GBDATA * GBT_first_species(GBDATA *gb_main)
#define TEST_EXPECT_NO_ERROR(call)
GBDATA * GBT_create_alignment(GBDATA *gb_main, const char *name, long len, long aligned, long security, const char *type, const char *why_created)
GBDATA * GBT_next_species(GBDATA *gb_species)
#define TEST_EXPECT_ERROR_CONTAINS(call, part)
NOT4PERL GBDATA * GBT_create_sequence_data(GBDATA *species, const char *ali_name, const char *key, GB_TYPES type, int security_write)
#define AWAR_SPLIT_ALI_TARGET
GB_ERROR write_string(const char *aw_string)
#define AWAR_SPLIT_ALI_POSITIONS
char * GBT_get_default_alignment(GBDATA *gb_main)
GBDATA * GB_nextChild(GBDATA *child)
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
#define TEST_EXPECT_TEXTFILES_EQUAL(fgot, fwant)
void GBT_splitNdestroy_string(ConstStrArray &names, char *&namelist, const char *separator, SplitMode mode)
GBDATA * GB_entry(GBDATA *father, const char *key)
void inc_and_check_user_abort(GB_ERROR &error)
void aw_message_if(GB_ERROR error)
char * GBS_global_string_copy(const char *templat,...)
void GB_close(GBDATA *gbd)
char * build_split_id(const RangeVec &ranges)
GB_ERROR GB_write_autoconv_string(GBDATA *gbd, const char *val)