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

Prepend sequence index if names non-unique in aligned fasta format #29

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion esl_msafile_afa.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,24 @@ esl_msafile_afa_Write(FILE *fp, const ESL_MSA *msa)
int64_t pos;
char buf[61];
int acpl; /* actual number of characters per line */
int make_uniquenames = FALSE; /* TRUE if we force names to be unique */
int status;
int tmpnseq;
int uniqwidth;

status = esl_msa_CheckUniqueNames(msa);
if (status == eslFAIL) {
make_uniquenames = TRUE;
for (tmpnseq = msa->nseq; tmpnseq; tmpnseq /= 10) uniqwidth++; /* how wide the uniqizing numbers need to be */
}

for (i = 0; i < msa->nseq; i++)
{
if (fprintf(fp, ">%s", msa->sqname[i]) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "afa msa file write failed");
if (make_uniquenames) {
if (fprintf(fp, ">%0*d/%s", uniqwidth, i, msa->sqname[i]) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "afa msa file write failed");
} else {
if (fprintf(fp, ">%s", msa->sqname[i]) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "afa msa file write failed");
}
if (msa->sqacc != NULL && msa->sqacc[i] != NULL) { if (fprintf(fp, " %s", msa->sqacc[i]) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "afa msa file write failed"); }
if (msa->sqdesc != NULL && msa->sqdesc[i] != NULL) { if (fprintf(fp, " %s", msa->sqdesc[i]) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "afa msa file write failed"); }
if (fputc('\n', fp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "afa msa file write failed");
Expand Down