Skip to content

Commit

Permalink
cumulative lengths and normalization base; fix names in the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
pratas committed Jan 9, 2023
1 parent 92cf3e2 commit 19fcdaa
Show file tree
Hide file tree
Showing 10 changed files with 1,162 additions and 141 deletions.
1,119 changes: 1,015 additions & 104 deletions src/Makefile

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions src/alcor.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,22 @@ void P_LocalRedundancy(char **p, int c)

MAP = (LR_PARAMETERS *) Calloc(1, sizeof(LR_PARAMETERS));

MAP->help = ArgsState (DEF_LR_HELP, p, c, "-h", "--help");
MAP->verbose = ArgsState (DEF_LR_VERBOSE, p, c, "-v", "--verbose");
MAP->hide = ArgsState (DEF_LR_HIDE, p, c, "-e", "--hide");
MAP->dna = ArgsState (DEF_LR_DNA, p, c, "-d", "--dna");
MAP->mask = ArgsState (DEF_LR_MASK, p, c, "-k", "--mask");
MAP->nosize = ArgsState (DEF_LR_NOSIZE, p, c, "-n", "--no-size");
MAP->threshold = ArgsDouble (DEF_LR_THRESHOLD, p, c, "-t", "--threshold");
MAP->color = ArgsNum (DEF_LR_COLOR, p, c, "-c", "--color",
0, 255);
MAP->window = ArgsNum (DEF_LR_WINDOW, p, c, "-w", "--window",
0, 999999999);
MAP->ignore = ArgsNum (DEF_LR_IGNORE, p, c, "-i", "--ignore",
0, 999999999);
MAP->level = ArgsNum (0, p, c, "-l", "--level",
DEF_LR_MIN_LEVEL, DEF_LR_MAX_LEVEL);
MAP->help = ArgsState (DEF_LR_HELP, p, c, "-h", "--help");
MAP->verbose = ArgsState (DEF_LR_VERBOSE, p, c, "-v", "--verbose");
MAP->hide = ArgsState (DEF_LR_HIDE, p, c, "-e", "--hide");
MAP->dna = ArgsState (DEF_LR_DNA, p, c, "-d", "--dna");
MAP->mask = ArgsState (DEF_LR_MASK, p, c, "-k", "--mask");
MAP->nosize = ArgsState (DEF_LR_NOSIZE, p, c, "-n", "--no-size");
MAP->renormalize = ArgsState (DEF_LR_RENORMALIZE, p, c, "-r", "--renormalize");
MAP->threshold = ArgsDouble (DEF_LR_THRESHOLD, p, c, "-t", "--threshold");
MAP->color = ArgsNum (DEF_LR_COLOR, p, c, "-c", "--color",
0, 255);
MAP->window = ArgsNum (DEF_LR_WINDOW, p, c, "-w", "--window",
0, 999999999);
MAP->ignore = ArgsNum (DEF_LR_IGNORE, p, c, "-i", "--ignore",
0, 999999999);
MAP->level = ArgsNum (0, p, c, "-l", "--level",
DEF_LR_MIN_LEVEL, DEF_LR_MAX_LEVEL);

if(c < MIN_NPARAM_FOR_PROGS + 1 || MAP->help)
{
Expand Down
1 change: 1 addition & 0 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef int8_t I8;
#define DEF_LR_THRESHOLD 0
#define DEF_LR_WINDOW 5
#define DEF_LR_MASK 0
#define DEF_LR_RENORMALIZE 0
#define DEF_LR_IGNORE 10
#define DEF_LR_REGION 500
#define DEF_LR_ALPHABET "ACGT"
Expand Down
72 changes: 72 additions & 0 deletions src/dna.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,78 @@ void CountFastaReadsAndMax(FASTA_READS *FA, char *fn)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SA *CreateSA(void)
{
SA *S = (SA *) Calloc(1, sizeof(SA));
S->array = (uint64_t *) Calloc(1, sizeof(uint64_t));
S->size = 1;
S->idx = 0;
return S;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void UpdateSA(SA *S, uint64_t len)
{
if(S->idx == 0) S->array[S->idx] = len;
else S->array[S->idx] = S->array[S->idx-1] + len;
S->array = (uint64_t *) Realloc(S->array, ++S->size * sizeof(uint64_t),
sizeof(uint64_t));
++S->idx;
return;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void RemoveSA(SA *S)
{
free(S->array);
free(S);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void GetCumulativeReadsLength(SA *S, char *fn)
{
uint8_t buffer[BUFFER_SIZE], sym = 0, header = 1;
uint32_t k, idx;
FILE *F = Fopen(fn, "r");
uint64_t seqLen = 0;
uint64_t readIdx = 0;

while((k = fread(buffer, 1, BUFFER_SIZE, F)))
for(idx = 0 ; idx < k ; ++idx)
{
sym = buffer[idx];
if(sym == '>')
{
if(readIdx > 0)
UpdateSA(S, seqLen);

header = 1;
++readIdx;
seqLen = 0;
continue;
}
if(sym == '\n' && header == 1)
{
header = 0;
continue;
}
if(sym == '\n') continue;
if(header == 1) continue;

++seqLen;
}

UpdateSA(S, seqLen);

fclose(F);
return;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

FASTA_READS *CreateFastaReads(void)
{
FASTA_READS *FA = (FASTA_READS *) Calloc(1, sizeof(FASTA_READS));
Expand Down
44 changes: 28 additions & 16 deletions src/dna.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,36 @@ typedef struct
}
FASTA_READS;

typedef struct
{
uint64_t idx;
uint64_t *array;
uint64_t size;
}
SA;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

FASTA_READS *CreateFastaReads (void);
void CountFastaReadsAndMax (FASTA_READS *, char *);
void RemoveFastaReads (FASTA_READS *);
uint64_t NDNASyminFile (FILE *);
uint64_t NDNASymInFasta (FILE *);
uint64_t NSymInFasta (FILE *);
uint64_t NDNASymInFastq (FILE *);
uint8_t DNASymToNum (uint8_t);
uint8_t NumToDNASym (uint8_t);
uint8_t GetCompNum (uint8_t);
uint8_t GetCompSym (uint8_t);
void ComplementArrayStack (uint8_t [], uint32_t);
void CheckInputIsFASTA (void);
void CheckFileIsFASTA (char *);
void ExtractSeqFromFASTA (uint32_t, uint32_t, char *, char[], char *,
uint32_t);
FASTA_READS *CreateFastaReads (void);
void CountFastaReadsAndMax (FASTA_READS *, char *);
void RemoveFastaReads (FASTA_READS *);
void GetCumulativeReadsLength (SA *, char *);
SA *CreateSA (void);
void UpdateSA (SA *, uint64_t);
void RemoveSA (SA *);
uint64_t NDNASyminFile (FILE *);
uint64_t NDNASymInFasta (FILE *);
uint64_t NSymInFasta (FILE *);
uint64_t NDNASymInFastq (FILE *);
uint8_t DNASymToNum (uint8_t);
uint8_t NumToDNASym (uint8_t);
uint8_t GetCompNum (uint8_t);
uint8_t GetCompSym (uint8_t);
void ComplementArrayStack (uint8_t [], uint32_t);
void CheckInputIsFASTA (void);
void CheckFileIsFASTA (char *);
void ExtractSeqFromFASTA (uint32_t, uint32_t, char *, char[],
char *, uint32_t);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Expand Down
4 changes: 2 additions & 2 deletions src/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ uint32_t size)
fprintf(stdout, "%c", header[x]);
fprintf(stdout, "\n");

return;
}
return;
}

//////////////////////////////////////////////////////////////////////////////
// - - - - - - - - - - - I N F O R M A T I O N M A I N - - - - - - - - - - -
Expand Down
18 changes: 18 additions & 0 deletions src/lr.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,24 @@ void LocalRedundancy(LR_PARAMETERS *MAP)
if(P->verbose) fprintf(stderr, "[>] Done!\n");
}

if(MAP->renormalize == 1) // RENORMALIZE POSITIONS
{
if(P->verbose) fprintf(stderr, "[>] Renormalize positions ...\n");

SA *S = CreateSA();
GetCumulativeReadsLength(S, P->filename);
for(idx = 0 ; idx < S->idx ; ++idx)
fprintf(stderr, "[>] Cumulative read length %"PRIu64": %"PRIu64"\n",
idx+1, S->array[idx]);




RemoveSA(S);

if(P->verbose) fprintf(stderr, "[>] Done!\n");
}

if(P->verbose) fprintf(stderr, "[>] Cleaning structures ...\n");
RemovePositions(PO);

Expand Down
11 changes: 7 additions & 4 deletions src/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void PrintMenuVi(void){
"EXAMPLE \n"
" %s %s -v -o map.svg pos1.txt:pos2.txt:pos3.txt \n"
" \n",
PNAME, LT_KEYS[4].key, PNAME, LT_KEYS[4].key, PNAME, LT_KEYS[4].key);
PNAME, LT_KEYS[5].key, PNAME, LT_KEYS[5].key, PNAME, LT_KEYS[5].key);
return;
}

Expand Down Expand Up @@ -250,7 +250,7 @@ void PrintMenuEx(void){
"EXAMPLE \n"
" %s %s -v -f -i 101 -e 301 seq.fa\n"
" \n",
PNAME, LT_KEYS[1].key, PNAME, LT_KEYS[1].key, PNAME, LT_KEYS[1].key);
PNAME, LT_KEYS[2].key, PNAME, LT_KEYS[2].key, PNAME, LT_KEYS[2].key);
return;
}

Expand Down Expand Up @@ -302,6 +302,9 @@ void PrintMenuLR(void){
" -o, --output-mask \n"
" output FASTA filename with the masked sequence, \n"
" \n"
" -r, --renormalize \n"
" renormalize the positions of a multi-FASTA file, \n"
" \n"
" -p, --show-parameters \n"
" show parameters of the models for optimization, \n"
" \n"
Expand All @@ -323,7 +326,7 @@ void PrintMenuLR(void){
"EXAMPLE \n"
" %s %s -v -w 10 -m 13:50:0:1:10:0.9/5:10:0.9 -k -o m.fa seq.fa\n"
" \n",
PNAME, LT_KEYS[2].key, PNAME, LT_KEYS[2].key, PNAME, LT_KEYS[2].key);
PNAME, LT_KEYS[3].key, PNAME, LT_KEYS[3].key, PNAME, LT_KEYS[3].key);
return;
}

Expand Down Expand Up @@ -396,7 +399,7 @@ void PrintMenuSi(void){
"EXAMPLE \n"
" %s %s -rs 50:0:1:0.1:0:0 -ms 80:7:50:0:7:0:0:0:x.fa\n"
" \n",
PNAME, LT_KEYS[3].key, PNAME, LT_KEYS[3].key, PNAME, LT_KEYS[3].key);
PNAME, LT_KEYS[4].key, PNAME, LT_KEYS[4].key, PNAME, LT_KEYS[4].key);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/param.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ void PrintParametersLR(LR_PARAMETERS *M)
"no" : "yes");
fprintf(stderr, "[>] Applying mask .................. %s\n", M->mask == 0 ?
"no" : "yes");
fprintf(stderr, "[>] Renormalize .................... %s\n", M->renormalize
== 0 ? "no" : "yes");
fprintf(stderr, "[>] Color for visualization ........ %u\n", M->color);
fprintf(stderr, "[>] Low-pass window size ........... %u\n", M->window);
for(n = 0 ; n < M->nModels ; ++n){
Expand Down
1 change: 1 addition & 0 deletions src/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ typedef struct
U8 level;
U8 dna;
U8 hide;
U8 renormalize;
U8 nosize;
double threshold;
U32 color;
Expand Down

0 comments on commit 19fcdaa

Please sign in to comment.