obi clean: fixed a memory bug, fixed the behaviour when no sample info,

and added checks warnings and error handling when sample info not
dereplicated
This commit is contained in:
Celine Mercier
2020-07-01 18:17:47 +02:00
parent ade1107b42
commit aab59f2214
4 changed files with 25 additions and 8 deletions

View File

@ -36,8 +36,7 @@ def addOptions(parser):
dest="clean:sample-tag-name", dest="clean:sample-tag-name",
metavar="<SAMPLE TAG NAME>", metavar="<SAMPLE TAG NAME>",
type=str, type=str,
default="merged_sample", help="Name of the tag where merged sample count informations are kept (typically generated by obi uniq, usually MERGED_sample, default: None).")
help="Name of the tag where sample counts are kept.")
group.add_argument('--ratio', '-r', group.add_argument('--ratio', '-r',
action="store", dest="clean:ratio", action="store", dest="clean:ratio",
@ -107,6 +106,9 @@ def run(config):
command_line = " ".join(sys.argv[1:]) command_line = " ".join(sys.argv[1:])
comments = View.print_config(config, "clean", command_line, input_dms_name=[i_dms_name], input_view_name=[i_view_name]) comments = View.print_config(config, "clean", command_line, input_dms_name=[i_dms_name], input_view_name=[i_view_name])
if 'sample-tag-name' not in config['clean']:
config['clean']['sample-tag-name'] = ""
if obi_clean(i_dms.name_with_full_path, tobytes(i_view_name), tobytes(config['clean']['sample-tag-name']), tobytes(o_view_name), comments, \ if obi_clean(i_dms.name_with_full_path, tobytes(i_view_name), tobytes(config['clean']['sample-tag-name']), tobytes(o_view_name), comments, \
config['clean']['distance'], config['clean']['ratio'], config['clean']['heads-only'], config['clean']['thread-count']) < 0: config['clean']['distance'], config['clean']['ratio'], config['clean']['heads-only'], config['clean']['thread-count']) < 0:
raise Exception("Error running obiclean") raise Exception("Error running obiclean")

View File

@ -1,5 +1,5 @@
major = 3 major = 3
minor = 0 minor = 0
serial= '0b26' serial= '0b26a'
version ="%d.%d.%s" % (major,minor,serial) version ="%d.%d.%s" % (major,minor,serial)

View File

@ -246,7 +246,16 @@ int obi_clean(const char* dms_name,
// Open the sample column if there is one // Open the sample column if there is one
if ((strcmp(sample_column_name, "") == 0) || (sample_column_name == NULL)) if ((strcmp(sample_column_name, "") == 0) || (sample_column_name == NULL))
sample_column = NULL; {
fprintf(stderr, "Info: No sample information provided, assuming one sample.\n");
sample_column = obi_view_get_column(i_view, COUNT_COLUMN);
if (sample_column == NULL)
{
obidebug(1, "\nError getting the COUNT column");
return -1;
}
sample_count = 1;
}
else else
{ {
sample_column = obi_view_get_column(i_view, sample_column_name); sample_column = obi_view_get_column(i_view, sample_column_name);
@ -255,6 +264,13 @@ int obi_clean(const char* dms_name,
obidebug(1, "\nError getting the sample column"); obidebug(1, "\nError getting the sample column");
return -1; return -1;
} }
sample_count = (sample_column->header)->nb_elements_per_line;
// Check that the sample column is a merged column with all sample informations
if (sample_count == 1)
{
obidebug(1, "\n\nError: If a sample column is provided, it must contain 'merged' sample counts as built by obi uniq with the -m option\n");
return -1;
}
} }
// Create the output view, or a temporary one if heads only // Create the output view, or a temporary one if heads only
@ -279,8 +295,6 @@ int obi_clean(const char* dms_name,
return -1; return -1;
} }
sample_count = (sample_column->header)->nb_elements_per_line;
// Create the output columns // Create the output columns
if (create_output_columns(o_view, sample_column, sample_count) < 0) if (create_output_columns(o_view, sample_column, sample_count) < 0)
{ {
@ -549,7 +563,7 @@ int obi_clean(const char* dms_name,
if (heads_only) if (heads_only)
{ {
line_selection = malloc((o_view->infos)->line_count * sizeof(index_t)); line_selection = malloc((((o_view->infos)->line_count) + 1) * sizeof(index_t));
if (line_selection == NULL) if (line_selection == NULL)
{ {
obi_set_errno(OBI_MALLOC_ERROR); obi_set_errno(OBI_MALLOC_ERROR);

View File

@ -52,7 +52,8 @@
* *
* @param dms A pointer on an OBIDMS. * @param dms A pointer on an OBIDMS.
* @param i_view_name The name of the input view. * @param i_view_name The name of the input view.
* @param sample_column_name The name of the OBI_STR column in the input view where the sample information is kept. * @param sample_column_name The name of the column in the input view where the sample information is kept.
* Must be merged informations as built by the obi uniq tool (checked by the function).
* NULL or "" (empty string) if there is no sample information. * NULL or "" (empty string) if there is no sample information.
* @param o_view_name The name of the output view where the results should be written (should not already exist). * @param o_view_name The name of the output view where the results should be written (should not already exist).
* @param o_view_comments The comments that should be associated with the output view. * @param o_view_comments The comments that should be associated with the output view.