Skip to content

support int tags with samtools view options -d and -D #1357

@dariomel

Description

@dariomel

the -d and -D options of samtools view currently handle only tags of type string, as evidenced by the following code:

samtools/sam_view.c

Lines 104 to 112 in d58fc8a

if (settings->tvhash && settings->tag) {
uint8_t *s = bam_aux_get(b, settings->tag);
if (s) {
khint_t k = kh_get(tv, settings->tvhash, (char*)(s + 1));
if (k == kh_end(settings->tvhash)) return 1;
} else {
return 1;
}
}

It would be nice if those options could also handle tags of type integer.
For example, the following mods allowed me to use option -D with a file containing 1651 integers:

    if (settings->tvhash && settings->tag) {                                     
        uint8_t *s = bam_aux_get(b, settings->tag);                              
        if (s) {                                                                 
            uint8_t t[24];                                                         
            khint_t k;                                                             
            if (*s=='i') { sprintf((char*)t,"%ld",bam_aux2i(s)); s=t; } else ++s;  
            k = kh_get(tv, settings->tvhash, (char*)s);                          
            if (k == kh_end(settings->tvhash)) return 1;                         
        } else {                                                                 
            return 1;                                                            
        }                                                                        
    }                                                                            

Otherwise, the man page should state that the -d and -D options can only handle tags of type string.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions