#include #include #include #include #include #define max(x,y) (x>y?x:y) #define min(x,y) (x 0) && (np2 > 0)) { if (strcmp(outfile, "") != 0) { fprintf(fpc, "%s\n", name1); } if (strcmp(posfile, "") != 0) { for (i=0; i 0) { substring_start = seq + ovector[0]; substring_length = ovector[1] - ovector[0]; pos = strlen(seq) - ovector[0] - 1; // save the position positions[ *np ] = pos; // save the orientation orientations[ *no ] = 1; startoffset = ovector[0] + substring_length; seq_pos[ pos ] = 1; (*np)++; (*no)++; } //return 0; if (singlestrand == 0) { // OTHER STRAND cr = complement(r); //printf("Complement of %s is %s\n", r, cr); startoffset = 0; re = pcre_compile(cr, 0, &error, &erroffset, NULL); while ( (rc = pcre_exec(re, NULL, seq, strlen(seq), startoffset, 0, ovector, 30)) > 0) { substring_start = seq + ovector[0]; substring_length = ovector[1] - ovector[0]; pos = strlen(seq) - ovector[0] - 1; // if not a palindromic version if (seq_pos[ pos ] != 1) { // save the position positions[ *np ] = pos; (*np)++; } // save the orientation in all cases orientations[ *no ] = -1; (*no)++; startoffset = ovector[0] + substring_length; } } if (cr != 0) free(cr); free(seq_pos); pcre_free(re); return 0; } // // take a char* and replace every nt by its complement // char* complement(char* s) { int l = strlen(s); char* c; char d; int i; c = (char*)calloc(l+1, sizeof(char)); for (i=l-1; i>=0; i--) { if (s[i] == 'A') d = 'T'; else if (s[i] == 'T') d = 'A'; else if (s[i] == 'G') d = 'C'; else if (s[i] == 'C') d = 'G'; else if (s[i] == '[') d = ']'; else if (s[i] == ']') d = '['; else d = s[i]; strncat(c, &d, 1); } return c; } void chomp(char* s) { int j; j = strlen(s); while (j >= 0) { if (s[j] == '\n') { s[j] = '\0'; return; } j--; } } // // returns the next sequence in the file fp // char* nextSequence(FILE* fp, char** name, int* size, int* nextSequence_started, int* nextSequence_ended, char* nextSequence_currentLine) { int len = 20000; char* seq; // not yet started, get the first line if (*nextSequence_started == 0) { fgets(nextSequence_currentLine, len, fp); chomp(nextSequence_currentLine); *nextSequence_started = 1; } //printf("%s\n", nextSequence_currentLine); // if file is finished, return 0 if (*nextSequence_ended == 1) { return 0; } // if started, line should be filled with ">..." if (nextSequence_currentLine[0] == '>') { *name = strdup(nextSequence_currentLine + 1); // create a new line seq = (char*)calloc(100000, sizeof(char) ); while (1) { fgets(nextSequence_currentLine, len, fp); if (feof(fp)) { *nextSequence_ended = 1; return seq; } chomp(nextSequence_currentLine); if (strlen(nextSequence_currentLine) == 0) { continue; } if (nextSequence_currentLine[0] == '>') { return seq; } else { strcat(seq, nextSequence_currentLine); } } } else return 0; } char* get_parameter(int argc, char** argv, char* param) { int i = 0; while ((i < argc) && (strcmp(param, argv[i]))) i++; if (i