diff --git a/src/obi_ecopcr.c b/src/obi_ecopcr.c old mode 100755 new mode 100644 index dbfa6cb..1d8dc3b --- a/src/obi_ecopcr.c +++ b/src/obi_ecopcr.c @@ -105,7 +105,8 @@ static int create_output_columns(Obiview_p o_view, bool kingdom_mode); * @param o_temp1_column A pointer on the output column for the temperature for the first primer. * @param o_temp2_column A pointer on the output column for the temperature for the second primer. * - * @retval 0 if the operation was successfully completed. + * @retval 0 if the sequence was skipped (taxid not found, warning printed). + * @retval 1 if the sequence was successfully printed to the output. * @retval -1 if an error occurred. * * @since July 2018 @@ -366,6 +367,17 @@ static int print_seq(Obiview_p i_view, Obiview_p o_view, // TODO add check for primer longer than MAX_PAT_LEN (32) + // Get sequence id + seq_id = obi_get_str_with_elt_idx_and_col_p_in_view(i_view, i_id_column, i_idx, 0); + + // Get the taxon structure + main_taxon = obi_taxo_get_taxon_with_taxid(taxonomy, taxid); + if (main_taxon == NULL) + { + obidebug(1, "\nWarning: error reading the taxonomic information of a sequence. Seq id: %s, taxid: %d. Probably deprecated taxid. Skipping this sequence.", seq_id, taxid); + return 0; + } + ldelta = (pos1 <= keep_nucleotides)?pos1:keep_nucleotides; rdelta = ((pos2+keep_nucleotides)>=seq_len)?seq_len-pos2:keep_nucleotides; @@ -432,18 +444,9 @@ static int print_seq(Obiview_p i_view, Obiview_p o_view, tm2 = OBIFloat_NA; // Write sequence id - seq_id = obi_get_str_with_elt_idx_and_col_p_in_view(i_view, i_id_column, i_idx, 0); if (obi_set_str_with_elt_idx_and_col_p_in_view(o_view, o_id_column, o_idx, 0, seq_id) < 0) { - obidebug(1, "\nError writing the sequence id (%s)", seq_id); - return -1; - } - - // Get the taxon structure - main_taxon = obi_taxo_get_taxon_with_taxid(taxonomy, taxid); - if (main_taxon == NULL) - { - obidebug(1, "\nError reading the taxonomic information of a sequence, sequence id: %s, taxid: %d", seq_id, taxid); + obidebug(1, "\nError writing the sequence id"); return -1; } @@ -629,7 +632,7 @@ static int print_seq(Obiview_p i_view, Obiview_p o_view, return -1; } - return 0; + return 1; } @@ -698,6 +701,7 @@ int obi_ecopcr(const char* i_dms_name, obiint_t taxid; char* sequence; + int printed; SeqPtr apatseq=NULL; int32_t o1Hits; @@ -1072,7 +1076,7 @@ int obi_ecopcr(const char* i_dms_name, (!max_len || (length <= max_len))) { // Print the found amplicon - if (print_seq(i_view, o_view, + printed = print_seq(i_view, o_view, i_idx, o_idx, taxonomy, sequence, @@ -1098,12 +1102,14 @@ int obi_ecopcr(const char* i_dms_name, o_strand_column, o_primer1_column, o_primer2_column, o_error1_column, o_error2_column, - o_temp1_column, o_temp2_column) < 0) + o_temp1_column, o_temp2_column); + if (printed < 0) { obidebug(1, "\nError writing the ecopcr result"); return -1; } - o_idx++; + else if (printed > 0) + o_idx++; } } } @@ -1160,7 +1166,7 @@ int obi_ecopcr(const char* i_dms_name, (!max_len || (length <= max_len))) { // Print the found amplicon - if (print_seq(i_view, o_view, + printed = print_seq(i_view, o_view, i_idx, o_idx, taxonomy, sequence, @@ -1186,12 +1192,14 @@ int obi_ecopcr(const char* i_dms_name, o_strand_column, o_primer1_column, o_primer2_column, o_error1_column, o_error2_column, - o_temp1_column, o_temp2_column) < 0) + o_temp1_column, o_temp2_column); + if (printed < 0) { obidebug(1, "\nError writing the ecopcr result"); return -1; } - o_idx++; + else if (printed > 0) + o_idx++; } } }