Skip to content

Commit

Permalink
review update
Browse files Browse the repository at this point in the history
  • Loading branch information
vasudeva8 committed Feb 14, 2025
1 parent 51253f1 commit 8ccc6df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
17 changes: 8 additions & 9 deletions header.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2018-2020, 2023 Genome Research Ltd.
Copyright (c) 2018-2020, 2023, 2025 Genome Research Ltd.
Authors: James Bonfield <[email protected]>, Valeriu Ohan <[email protected]>
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -145,7 +145,7 @@ static int sam_hrecs_update_hashes(sam_hrecs_t *hrecs,
const char *name = NULL;
const char *altnames = NULL;
hts_pos_t len = -1;
int r, dup = 0;
int r, invLN = 0;
khint_t k;

while (tag) {
Expand All @@ -156,9 +156,8 @@ static int sam_hrecs_update_hashes(sam_hrecs_t *hrecs,
assert(tag->len >= 3);
hts_pos_t tmp = len;
len = strtoll(tag->str+3, NULL, 10);
if (tmp != -1 && tmp != len) {
//LN again with different value, discard
dup = 1;
if (tmp != -1 && tmp != len) { //duplicate and different LN
invLN = 1;
}
} else if (tag->str[0] == 'A' && tag->str[1] == 'N') {
assert(tag->len >= 3);
Expand All @@ -178,10 +177,10 @@ static int sam_hrecs_update_hashes(sam_hrecs_t *hrecs,
return -1; // LN should be present, according to spec.
}

if (dup) {
hts_log_error("Header includes @SQ line \"%s\" with duplicate LN: tag", \
name);
return -1;
if (invLN) {
hts_log_error("Header includes @SQ line \"%s\" with multiple LN:"
" tag with different values.", name);
return -1; // LN should not be duplicated or be same
}

// Seen already?
Expand Down
18 changes: 6 additions & 12 deletions sam.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* sam.c -- SAM and BAM file I/O and manipulation.
Copyright (C) 2008-2010, 2012-2024 Genome Research Ltd.
Copyright (C) 2008-2010, 2012-2025 Genome Research Ltd.
Copyright (C) 2010, 2012, 2013 Broad Institute.
Author: Heng Li <[email protected]>
Expand Down Expand Up @@ -1911,12 +1911,6 @@ static sam_hdr_t *sam_hdr_sanitise(sam_hdr_t *h) {
cp[h->l_text] = '\0';
}

if (sam_hdr_fill_hrecs(h) < 0) {
//failed in parsing / validation
sam_hdr_destroy(h);
return NULL;
}

return h;
}

Expand Down Expand Up @@ -1972,13 +1966,13 @@ static sam_hdr_t *sam_hdr_create(htsFile* fp) {
} else {
if (strncmp(q, "LN:", 3) == 0) {
hts_pos_t tmp = strtoll(q + 3, (char**)&q, 10);
if (ln != -1 && tmp != ln) {
//duplicate LN tag with different value
hts_log_error("111Header includes @SQ line \"%s\" with \
duplicate LN: tag", sn);
if (ln != -1 && ln != tmp) { //duplicate & different LN
hts_log_error("Header includes @SQ line \"%s\" with"
" multiple LN: tag with different values.", sn);
goto error;
} else {
ln = tmp;
}
ln = tmp;
}
}

Expand Down

0 comments on commit 8ccc6df

Please sign in to comment.