git-svn-id: https://www.grenoble.prabi.fr/svn/LECASofts/ecoPCR/branches/refactoring@61 60f365c0-8329-0410-b2a4-ec073aeeaa1d
This commit is contained in:
@ -15,6 +15,15 @@ void freememory(char **tab, int32_t num){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a pattern match a string using mamberall libapat function
|
||||
* @param line array containing sequence information
|
||||
* @param pattern array containing patterns to test on the sequence
|
||||
* @param numpattern number of pattern in pattern array
|
||||
* @param error_max error rate allowed by the user
|
||||
*
|
||||
* @return int 1 if a pattern match, else 0
|
||||
**/
|
||||
int ispatternmatching(char **line, char **pattern, int32_t numpattern, int32_t error_max){
|
||||
int i;
|
||||
SeqPtr apatseq = NULL;
|
||||
@ -38,6 +47,11 @@ int ispatternmatching(char **line, char **pattern, int32_t numpattern, int32_t e
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*returns the result on standard output
|
||||
* @param line array containing sequence information
|
||||
* @param i length of line
|
||||
**/
|
||||
void printline(char **line, int32_t i){
|
||||
int32_t k=0;
|
||||
for (k=0; k < i; k++)
|
||||
@ -99,36 +113,31 @@ static void ExitUsage(stat)
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int32_t carg = 0;
|
||||
int32_t r = 0; // number of restricted taxid
|
||||
int32_t g = 0; // number of ignored taxid
|
||||
int32_t v = 0;
|
||||
int32_t p = 0; // number of pattern
|
||||
int32_t r = 0; // number of restricted taxid
|
||||
int32_t g = 0; // number of ignored taxid
|
||||
int32_t v = 0; // stores if -v mode is active
|
||||
int32_t p = 0; // number of pattern
|
||||
int32_t i = 0;
|
||||
int32_t errflag = 0;
|
||||
int32_t error_max = 0;
|
||||
int32_t matchingresult = 0;
|
||||
int32_t error_max = 0; // stores the error rate allowed by the user
|
||||
int32_t matchingresult = 0; // stores number of matching result
|
||||
|
||||
ecotaxonomy_t *taxonomy;
|
||||
ecotaxonomy_t *taxonomy; // stores the taxonomy
|
||||
|
||||
char *database = NULL; // stores the database path (for taxonomy)
|
||||
int32_t *restricted_taxid = NULL; // stores the restricted taxid
|
||||
int32_t *ignored_taxid = NULL; // stores the ignored taxid
|
||||
char **pattern = NULL; // stores the regex pattern
|
||||
char *line[19] = {0}; // stores the line
|
||||
|
||||
FILE *file = NULL;
|
||||
char *stream = ECOMALLOC(sizeof(char *)*10000,"error stream buffer allocation");
|
||||
int current_taxid;
|
||||
char *buffer;
|
||||
|
||||
struct stat buf;
|
||||
FILE *file = NULL; // stores the data stream, stdin by default
|
||||
char *stream = ECOMALLOC(sizeof(char *)*10000,"error stream buffer allocation");
|
||||
char *buffer;
|
||||
|
||||
// check stdin
|
||||
if (fstat(fileno(stdin),&buf) == 0)
|
||||
if ( (buf.st_dev) == 0)
|
||||
file = stdin;
|
||||
|
||||
|
||||
/**
|
||||
* Parse commande line options
|
||||
**/
|
||||
while ((carg = getopt(argc, argv, "f:d:i:r:e:vh")) != -1) {
|
||||
|
||||
switch (carg) {
|
||||
@ -178,7 +187,7 @@ int main(int argc, char **argv){
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the leftover command line arguments back
|
||||
* Get the left-over command line arguments back
|
||||
* and check the pattern is not more than 32 character long
|
||||
*/
|
||||
pattern = ECOMALLOC(sizeof *pattern * (argc - optind), "Error in pattern allocation");
|
||||
@ -188,15 +197,26 @@ int main(int argc, char **argv){
|
||||
else
|
||||
{
|
||||
printf("# Sorry, ecogrep doesn't handle pattern longer than 32 characters.\
|
||||
\n# Please correct this one : %s\n",argv[optind]);
|
||||
\n# Please check it out : %s\n",argv[optind]);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check standard input if no file name given in -f option
|
||||
**/
|
||||
if (file == NULL)
|
||||
{
|
||||
if (isatty(fileno(stdin)))
|
||||
errflag++;
|
||||
else
|
||||
file = stdin;
|
||||
}
|
||||
|
||||
/**
|
||||
* try to get the database name from environment variable
|
||||
* if no database name specified in the -d option
|
||||
*/
|
||||
**/
|
||||
if (database == NULL)
|
||||
{
|
||||
database = getenv("ECOPCRDB");
|
||||
@ -205,12 +225,10 @@ int main(int argc, char **argv){
|
||||
}
|
||||
|
||||
/**
|
||||
* check everything required is provided
|
||||
* check at leat one processing is asked
|
||||
* either patterns or taxid filters
|
||||
*/
|
||||
if ( !file ||
|
||||
!database ||
|
||||
(!p && restricted_taxid == NULL && ignored_taxid == NULL)
|
||||
)
|
||||
if ( !p && restricted_taxid == NULL && ignored_taxid == NULL )
|
||||
errflag++;
|
||||
|
||||
if (errflag)
|
||||
@ -224,7 +242,7 @@ int main(int argc, char **argv){
|
||||
/**
|
||||
* Parse the stream
|
||||
*/
|
||||
while( fgets(stream, 10000, file) ){
|
||||
while( fgets(stream, 10000, file) != NULL ){
|
||||
|
||||
if (stream[0]!= '#')
|
||||
{
|
||||
@ -232,6 +250,7 @@ int main(int argc, char **argv){
|
||||
buffer != NULL;
|
||||
i++, buffer = strtok(NULL,"|"))
|
||||
{
|
||||
printf("<EFBFBD><EFBFBD> %s\n",buffer);
|
||||
line[i] = strdup(buffer);
|
||||
}
|
||||
|
||||
@ -254,7 +273,7 @@ int main(int argc, char **argv){
|
||||
continue;
|
||||
}
|
||||
|
||||
else // v mode, invert ignore and restrict taxid
|
||||
else // v mode, invert ignore and restrict options
|
||||
{
|
||||
if ( (r > 0) && (eco_is_taxid_included( taxonomy,
|
||||
restricted_taxid,
|
||||
@ -280,12 +299,15 @@ int main(int argc, char **argv){
|
||||
|
||||
printf("# %d matching result\n",matchingresult);
|
||||
|
||||
/**
|
||||
* clean, close and free before leaving
|
||||
**/
|
||||
if ( file != stdin )
|
||||
fclose(file);
|
||||
|
||||
freememory(line,i);
|
||||
freememory(pattern,p);
|
||||
ECOFREE(pattern,"Error in free pattern");
|
||||
ECOFREE(stream,"Error in free stream");
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user