Beispiel #1
0
void insert(struct trie *root, char *window, int start, char *seqname, int which){
  struct trie *current = root;
  int i;
  int loc;

  for (i=0;i<strlen(window);i++){
    loc = cindex(window[i]);
    if (current->kids[loc] == NULL){
      if (VERBOSE)
	printf("alloc for %c - %d\n", window[i], loc);
      alloc_trie(&(current->kids[loc]));
    }
    current = current->kids[loc];
  }

  /* not a leaf node any more */
  if (current->freq == INTERNALNODE) 
    current->freq = 0;
    

  if (which == 1)
    current->freq++;
  else
    current->freq--;


  // we're at the leaf now; fix this for multiple hits.
  // insert_sloc(&(current->location), start, seqname);
  //strcpy(current->seq, seqname);
  if (VERBOSE)
    printf("inserted %d\n", start);
  //current->location = start;
}
Beispiel #2
0
Trie *init_trie(CalcPrefixFunc addPrefixFunc, CalcPrefixFunc findPrefixFunc) {
	Trie *trie = alloc_trie();
	trie->root = alloc_trie_node();
	trie->table = init_table();
	trie->addPrefixFunc = addPrefixFunc;
	trie->findPrefixFunc = findPrefixFunc;
	return trie;
}
Beispiel #3
0
int main(int argc, char **argv){

  int i, j;
  FILE *fasta;
  FILE *treefile;
  struct trie *root;
  char fname[SEQ_LENGTH*2];
  char idxname[SEQ_LENGTH];
  char command[SEQ_LENGTH*5];
  char fgnuplot[SEQ_LENGTH*5];
  FILE *gnuplot;

  int filestat;

  int LOADED;

  char searchFile[SEQ_LENGTH];
  char seqname[SEQ_LENGTH];

  char gnuseq[SEQ_LENGTH];
  int gnufreq;
  FILE *freqFile;
  FILE *freqList;
  struct timeval start, end;
  struct timezone tz;

  /* directory stuff */
  DIR *dp;
  struct dirent *ep;

  triemem = 0;
  slocmem = 0;
  identifier = 0;

  DUMPTREE = 0;
  VERBOSE = 0;
  SAVEINDEX = 0;
  LOADED = 0;
  MINWIN = 1;
  THREADS = 1;
  idxname[0] = 0;
  genomelen = 0;

  allocs = 0;
  frees = 0;

  if (argc < 3){
    help(argv[0]);
    return 0;
  } 

  fname[0] = 0;

  searchFile[0] = 0;

  QUALFILE[0] = 0;

  pthread_mutex_init(&logMutex, NULL);
  pthread_mutex_init(&readMutex, NULL);

  INDEXSTART = 0;
  seqname[0] = 0;

  for (i=1;i<argc;i++){
    if (!strcmp(argv[i], "-ws"))
      WINDOW_SIZE = atoi(argv[i+1]);
    else if (!strcmp(argv[i], "-ss"))
      SLIDE_SIZE = atoi(argv[i+1]);
    else if (!strcmp(argv[i], "-nr"))
      NOREV = 1;
    else if (!strcmp(argv[i], "-uniq"))
      UNIQ = 1;
    else if (!strcmp(argv[i], "-v"))
      VERBOSE=1;	
    else if (!strcmp(argv[i], "-f"))
      strcpy(fname, argv[i+1]);	
    else if (!strcmp(argv[i], "-seqname"))
      strcpy(seqname, argv[i+1]);
  }


  if (fname[0] == 0){
    help(argv[0]);
    return 0;
  }
  
  alloc_trie(&root);
  
  if (fname[0] != 0)
    fprintf(stderr,"\tfile:\t\t%s\n",fname);
  fprintf(stderr,"\twindow size:\t%d\n\tslide size:\t%d\n", WINDOW_SIZE, SLIDE_SIZE);
  if (VERBOSE)
    fprintf(stderr,"\tverbose:\t\ton\n");

  filestat = do_file(fname, root, 1);
  if (filestat == 0)
    return 0;

  if (WINDOW_SIZE == 0){ 
    fprintf(stderr, "Strange ws.\n");
    return 0;
  }



  fprintf(stderr, "Total memory for the trie: %lld bytes = %6.2f Kbytes = %4.2f Mbytes\n", triemem, (float)triemem/1024.0, (float)triemem/1024.0/1024.0);
  
  slocmem = 0;

  allocs = 0;
  frees = 0;
  callocs = 0;
  cfrees = 0;
  clallocs = 0;
  clfrees = 0;

  sprintf(idxname, "%s.k%d.txt", fname, WINDOW_SIZE);

  saveTrie(root, idxname);

  return 1;
}