Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.bai files are not found when "bam" is part of the file path #4

Open
ericfournier2 opened this issue Dec 20, 2018 · 0 comments
Open

Comments

@ericfournier2
Copy link

ericfournier2 commented Dec 20, 2018

Hello,

the bam_index_load_local function from bam_index.c fails to find index files named my_file.bai if the substring "bam" is present anywhere in the path. For example, the following file pair fails to be recognized:

"/home/bioinfo5/Desktop/UPM-CBGP/analysis/201810_Brapa_ChIP_FL/bams/3_filtdupes_FL_C1.bai"
"/home/bioinfo5/Desktop/UPM-CBGP/analysis/201810_Brapa_ChIP_FL/bams/3_filtdupes_FL_C1.bam"

This is because when looking for the "bam" suffix, bam_index_load_local uses strstr, and fails if the returned index does not correspond to the last three characters. This could be fixed by looping while s is different than 0 when looking for the suffix (something like this, untested):

char *s = strstr(fn, "bam");
while(s) {
    if (s == fn + strlen(fn) - 3) {
        strcpy(fnidx, fn);
	fnidx[strlen(fn)-1] = 'i';
        fp = fopen(fnidx, "rb");
    } else {
        s = strstr(s, "bam");
    }
}

Cheers,
-Eric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant