Made the OBITools3 more 'empty file friendly'

This commit is contained in:
MercierC
2021-03-15 16:25:41 +13:00
parent d48aed38d4
commit 425fe25bd2
4 changed files with 90 additions and 73 deletions

View File

@ -205,10 +205,16 @@ def run(config):
if type(entries) == list: if type(entries) == list:
forward = entries[0] forward = entries[0]
reverse = entries[1] reverse = entries[1]
if len(forward) == 0 or len(reverse) == 0:
aligner = None
else:
aligner = Kmer_similarity(forward, \ aligner = Kmer_similarity(forward, \
view2=reverse, \ view2=reverse, \
kmer_size=config['alignpairedend']['kmersize'], \ kmer_size=config['alignpairedend']['kmersize'], \
reversed_column=None) reversed_column=None)
else:
if len(entries) == 0:
aligner = None
else: else:
aligner = Kmer_similarity(entries, \ aligner = Kmer_similarity(entries, \
column2=entries[REVERSE_SEQUENCE_COLUMN], \ column2=entries[REVERSE_SEQUENCE_COLUMN], \
@ -251,7 +257,7 @@ def run(config):
pb(i, force=True) pb(i, force=True)
print("", file=sys.stderr) print("", file=sys.stderr)
if kmer_ali : if kmer_ali and aligner is not None:
aligner.free() aligner.free()
# Save command config in View and DMS comments # Save command config in View and DMS comments

View File

@ -645,6 +645,7 @@ def run(config):
g = 0 g = 0
u = 0 u = 0
i = 0
no_tags = config['ngsfilter']['notags'] no_tags = config['ngsfilter']['notags']
try: try:
for i in range(entries_len): for i in range(entries_len):

View File

@ -53,7 +53,11 @@ def entryIteratorFactory(lineiterator,
i = iterator i = iterator
try:
first=next(i) first=next(i)
except StopIteration:
first=""
pass
format=b"tabular" format=b"tabular"

View File

@ -229,6 +229,8 @@ int obi_clean(const char* dms_name,
return -1; return -1;
} }
seq_count = (i_view->infos)->line_count;
// Open the sequence column // Open the sequence column
if (strcmp((i_view->infos)->view_type, VIEW_TYPE_NUC_SEQS) == 0) if (strcmp((i_view->infos)->view_type, VIEW_TYPE_NUC_SEQS) == 0)
iseq_column = obi_view_get_column(i_view, NUC_SEQUENCE_COLUMN); iseq_column = obi_view_get_column(i_view, NUC_SEQUENCE_COLUMN);
@ -245,7 +247,7 @@ 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) || (seq_count == 0))
{ {
fprintf(stderr, "Info: No sample information provided, assuming one sample.\n"); fprintf(stderr, "Info: No sample information provided, assuming one sample.\n");
sample_column = obi_view_get_column(i_view, COUNT_COLUMN); sample_column = obi_view_get_column(i_view, COUNT_COLUMN);
@ -340,6 +342,8 @@ int obi_clean(const char* dms_name,
return -1; return -1;
} }
if (seq_count > 0)
{
// Build kmer tables // Build kmer tables
ktable = hash_seq_column(i_view, iseq_column, 0); ktable = hash_seq_column(i_view, iseq_column, 0);
if (ktable == NULL) if (ktable == NULL)
@ -349,8 +353,6 @@ int obi_clean(const char* dms_name,
return -1; return -1;
} }
seq_count = (i_view->infos)->line_count;
// Allocate arrays for sample counts otherwise reading in mapped files takes longer // Allocate arrays for sample counts otherwise reading in mapped files takes longer
complete_sample_count_array = (int*) malloc(seq_count * sample_count * sizeof(int)); complete_sample_count_array = (int*) malloc(seq_count * sample_count * sizeof(int));
if (complete_sample_count_array == NULL) if (complete_sample_count_array == NULL)
@ -404,6 +406,7 @@ int obi_clean(const char* dms_name,
} }
} }
} }
}
for (i=0; i< (seq_count-1); i++) for (i=0; i< (seq_count-1); i++)
{ {
@ -551,17 +554,20 @@ int obi_clean(const char* dms_name,
} }
} }
if (seq_count > 0)
{
free_kmer_tables(ktable, seq_count); free_kmer_tables(ktable, seq_count);
free(complete_sample_count_array); free(complete_sample_count_array);
free(blob_array); free(blob_array);
free(alignment_result_array); free(alignment_result_array);
}
fprintf(stderr, "\n"); fprintf(stderr, "\n");
if (stop) if (stop)
return -1; return -1;
if (heads_only) if (heads_only && (seq_count > 0))
{ {
line_selection = malloc((((o_view->infos)->line_count) + 1) * sizeof(index_t)); line_selection = malloc((((o_view->infos)->line_count) + 1) * sizeof(index_t));
if (line_selection == NULL) if (line_selection == NULL)
@ -635,7 +641,7 @@ int obi_clean(const char* dms_name,
} }
// Flag the end of the line selection // Flag the end of the line selection
if (heads_only) if (heads_only && (seq_count > 0))
line_selection[l] = -1; line_selection[l] = -1;
// Create new view with line selection if heads only // Create new view with line selection if heads only