Esempio n. 1
0
int main(int argc, char *argv[]) {
	int i;
	Table_T identifiers = Table_new(0, NULL, NULL);
	for (i = 1; i < argc; i++) {
		FILE *fp = fopen(argv[i], "r");
		if (fp == NULL) {
			fprintf(stderr, "%s: can't open '%s' (%s)\n",
				argv[0], argv[i], strerror(errno));
			return EXIT_FAILURE;
		} else {
			xref(argv[i], fp, identifiers);
			fclose(fp);
		}
	}
	if (argc == 1) xref(NULL, stdin, identifiers);
	{
		int i;
		void **array = Table_toArray(identifiers, NULL);
		qsort(array, Table_length(identifiers),
			2*sizeof (*array), compare);
		for (i = 0; array[i]; i += 2) {
			printf("%s", (char *)array[i]);
			print(array[i+1]);
		}
		FREE(array);
	}
	return EXIT_SUCCESS;
}
Esempio n. 2
0
File: xref.c Progetto: mrkeng/CII
void print(Table_T files) {
	int i;
	void **array = Table_toArray(files, NULL);
	qsort(array, Table_length(files), 2*sizeof (*array),
		compare);
	for (i = 0; array[i]; i += 2) {
		if (*(char *)array[i] != '\0')
			printf("\t%s:", (char *)array[i]);
		{
			void **lines = Set_toArray(array[i+1], NULL);
			qsort(lines, Set_length(array[i+1]), sizeof (*lines),
				cmpint);
         int j, c;
			for (j = 0; lines[j]; j++) {
            printf(" %d", *(int *)lines[j]);
            c = 0;
			   while (lines[j+1] 
			      && *(int *)lines[j+1] == *(int *)lines[j] + 1) {
			      j++;
               c = 1;
			   }
			   if (c)
               printf("-%d", *(int *)lines[j]);
			}
			FREE(lines);
		}
		printf("\n");
	}
	FREE(array);
}
Esempio n. 3
0
int main(int argc, char *argv[]) {
	int i;
	Table_T identifiers = Table_new(10000, textcmp, texthash);
	Text_save_T mark = Text_save();

	Fmt_register('T', Text_fmt);
	Fmt_register('D', Integer_fmt);
	first = Text_cat(Text_cat(Text_ucase, Text_lcase), Text_box("_", 1));
	rest  = Text_cat(first, Text_digits);
	for (i = 1; i < argc; i++) {
		FILE *fp = fopen(argv[i], "r");
		if (fp == NULL)
		fprintf(stderr, "%s: can't open '%s' (%s)\n", argv[0], argv[i], strerror(errno));
		else {
			cref(argv[i], fp, identifiers);
			fclose(fp);
		}
	}
	if (argc == 1)
		cref(NULL, stdin, identifiers);
	{
		int i;
		void **array = Table_toArray(identifiers, NULL);
		qsort(array, Table_length(identifiers), 2*sizeof (*array), compare);
		for (i = 0; array[i]; i += 2) {
			Fmt_print("%T", array[i]);
			print(array[i+1]);
			FREE(array[i]);
		}
		FREE(array);
		Table_free(&identifiers);
	}
	Text_restore(&mark);
	return EXIT_SUCCESS;
}
Esempio n. 4
0
File: wf.c Progetto: ZoneMo/backup
void wf(char *name, FILE *fp) {
	Table_T table = Table_new(0, NULL, NULL);
	char buf[128];
	while (getword(fp, buf, sizeof buf, first, rest)) {
		const char *word;
		int i, *count;
		for (i = 0; buf[i] != '\0'; i++)
			buf[i] = tolower(buf[i]);
		word = Atom_string(buf);
		count = Table_get(table, word);
		if (count)
			(*count)++;
		else {
			NEW(count);
			*count = 1;
			Table_put(table, word, count);
		}
	}
	if (name)
		printf("%s:\n", name);
	{ int i;
	  void **array = Table_toArray(table, NULL);
	  qsort(array, Table_length(table), 2*sizeof (*array),
	  	compare);
	  for (i = 0; array[i]; i += 2)
	  	printf("%d\t%s\n", *(int *)array[i+1],
	  		(char *)array[i]);
	  FREE(array); }
	Table_map(table, vfree, NULL);
	Table_free(&table);
}
Esempio n. 5
0
void print(Table_T files){
	int i;
	void **array = Table_toArray(files, NULL);
	
	qsort(array, Table_length(files), 2 * sizeof(*array), compare);
	
	for (i = 0; array[i]; i += 2){
		if (*(char *)array[i] != '\0'){
			printf("\t%s:", (char *)array[i]);
		}
		// print the line numbers in the set array[i+1]
		{
			int j;
			void **lines = Set_toArray(array[i + 1], NULL);
			
			qsort(lines, Set_length(array[i+1], sizeof(*lines), cmpint);
			
			for (j = 0; lines[j]; j++){
				printf(" %d", *(int *)lines[j]);
			}
			FREE(lines);
		}
		
		printf("\n");
	}
	FREE(array);
}
Esempio n. 6
0
File: kref.c Progetto: ZoneMo/backup
int main(int argc, char *argv[]) {
	int i;
	Table_T identifiers = Table_new(5000,
		(int (*)(const void *, const void *))strcmp, strhash);

	Fmt_register('S', Str_fmt);
	first = Str_catv("abcdefghijklmnopqrstuvwxyz", 1, 0,
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 0, "_", 1, 0, NULL);
	rest  = Str_cat(first, 1, 0, "0123456789", 1, 0);
	for (i = 1; i < argc; i++) {
		FILE *fp = fopen(argv[i], "r");
		if (fp == NULL)
			fprintf(stderr, "%s: can't open '%s' (%s)\n", argv[0], argv[i], strerror(errno));
		else {
			kref(argv[i], fp, identifiers);
			fclose(fp);
		}
	}
	if (argc == 1)
		kref(NULL, stdin, identifiers);
	{
		int i;
		void **array = Table_toArray(identifiers, NULL);
		qsort(array, Table_length(identifiers), 2*sizeof (*array), compare);
		for (i = 0; array[i]; i += 2) {
			Fmt_print("%S", array[i], 1, 0);
			print(array[i+1]);
			FREE(array[i]);
		}
		FREE(array);
		Table_free(&identifiers);
	}
	return EXIT_SUCCESS;
}
Esempio n. 7
0
static void _cleanup(OeSession session) {

    T _this_ = OeNet_get_proto(OeSession_get_net(session));
    int sz = Table_length(_this_->pending);
    void **array = Table_toArray(_this_->pending, NULL);
    for ( int i = 0; i < sz && array[i]; i+= 2 ) {
        CID_KEY *key = (CID_KEY *) array[i];
        ACContext *pc = Table_remove(_this_->pending, key);
        _send_con_closed(pc->context);
    }
    Mem_free(array, __FILE__, __LINE__);
    Table_free(&_this_->pending);
    //OepClient_free(&_this_);  //closing the proto is hard and buggy.
}
Esempio n. 8
0
/*finds and returns the number of sets with more than one value*/
int num_fgroups(Table_T* table)
{
        int table_len = Table_length(*table);
        void **table_array = Table_toArray(*table, NULL);
        int counter = 0;

        for (int i=1; i<(2*table_len); i += 2) {
                if (Set_length((Set_T)table_array[i]) > 1) {
                        counter++;
                }
        }
        free(table_array);
        return counter;
}
Esempio n. 9
0
static void _free_items(Table_T items) {

    assert(items);

    int sz = Table_length(items);
    if (sz > 0) {
        void **array = Table_toArray(items, NULL);
        for ( int i = 0; i < sz && array[i]; i+= 2 ) {
            char *key = (char *) array[i];
            Set_T titem = Table_remove(items, key);
            if (titem) {
                Set_free( &titem );
            }
        }
        Mem_free(array, __FILE__, __LINE__);
    }
}
Esempio n. 10
0
END_TEST


START_TEST(test_put_replace)
{
    /* New values replace old values with the same key. */

    Table_T *table = Table_new(0, cmpatom, hashatom);

    Table_put(table, (void*)0x12, (void*)0x34);
    Table_put(table, (void*)0x12, (void*)0x56);

    fail_unless( Table_length(table) == 1 );
    fail_unless( Table_get(table, (void*)0x12) == (void*)0x56);

    Table_remove(table, (void*)0x12);
    Table_free(&table);
}
Esempio n. 11
0
 /* prints the sets in the table that have more than 1 value*/
void print_table(Table_T* table)
{
        int table_len = Table_length(*table);
        void **table_array = Table_toArray(*table, NULL);

        int counter = num_fgroups(table);

        for (int i=1; i<(2*table_len); i += 2) {
                if(Set_length((Set_T)table_array[i]) > 1) {
                        print_set((Set_T *)&table_array[i]);
                        counter--;
                        if (counter != 0) {     
                                printf("\n");
                        }
                }
                Set_free((Set_T *)&table_array[i]);
        }
        free(table_array);
}
Esempio n. 12
0
File: kref.c Progetto: ZoneMo/backup
void print(Table_T files) {
	int i;

	void **array = Table_toArray(files, NULL);
	qsort(array, Table_length(files), 2*sizeof (*array), compare);
	for (i = 0; array[i]; i += 2) {
		Seq_T seq = array[i+1];
		char *filename = array[i];
		if (*filename)
			Fmt_print("\t%S:", filename, 1, 0);
		while (Seq_length(seq) > 0)
			Fmt_print(" %S", Seq_remhi(seq), 1, 0);
		Fmt_print("\n");
		FREE(filename);
		Seq_free(&seq);
	}
	FREE(array);
	Table_free(&files);
}
Esempio n. 13
0
END_TEST


START_TEST(test_get)
{
    /* Table_get() with non-existant key returns NULL */

    Table_T *table = Table_new(0, cmpatom, hashatom);

    Table_put(table, (void*)0x12, (void*)0x34);

    fail_unless( Table_length(table) == 1 );
    fail_unless( Table_get(table, (void*)0x12) == (void*)0x34);

    /* non-existant key */
    fail_unless( Table_get(table, (void*)0x34) == NULL);

    Table_remove(table, (void*)0x12);
    Table_free(&table);
}
Esempio n. 14
0
void print_fgroups(T* table)
{
    char ** arr = (char **)Table_toArray(*table, NULL);
    int table_length = Table_length(*table) * 2;
    for (int i=0; i < table_length; i+=2) {
        L list_ptr = ((L)arr[i+1]);
        int list_size = List_length(list_ptr);
        if (list_size >= 2) {
            char **names = (char**) List_toArray(list_ptr, NULL);
            for (int j = 0; names[j]; j++)
                printf("%s\n", (char*)(names[j]));
            if (2*i+2 < table_length)
                printf("\n");
            free(names);
        }
        List_free(&list_ptr);
    }
    free(arr);
    Table_free(table);
}
Esempio n. 15
0
int try_running_tests_in_dso(struct herc *h, const char *file, void *handle) {
	size_t i = 0;
	void *suite_fixture, *test_fixture;
	//get the suites
	Table_T suitesTable = get_testnames_in_file(file, handle);

	//convert to array for easier sorting and iteration
	unsigned nSuites = Table_length(suitesTable);
	void **suites = Table_toArray(suitesTable, 0);
	Table_free(&suitesTable);
	
	//sort
	qsort(suites, nSuites, 2*sizeof(suites[0]), (int (*)(const void *, const void *))strcmp);

	//iterate and run
	for (i = 0; i<nSuites; i++) {
		suite_desc *suite = suites[i*2+1];
		suite_fixture = invoke_before_suite(suite);//TODO call RBE callback
		cr_list_iter *iter = cr_list_iter_create(suite->tests);
		while (!cr_list_iter_past_end(iter)) {
			test_fixture = invoke_before_test(suite, suite_fixture);
			test_desc *test = (test_desc*)cr_list_iter_get(iter);
			herc_rbe_invoke(h->rbe, start_test, test);
			run_test(h, handle, test, test_fixture);
			herc_rbe_invoke(h->rbe, end_test, test);
			invoke_after_test(suite, test_fixture);
			cr_list_iter_next(iter);
		}
		cr_list_iter_free(iter);
		invoke_after_suite(suite, suite_fixture);
	}

	for (i = 0; i<nSuites; i++) {
		suite_desc_free(suites[i*2+1]);
	}


	free(suites);
	return 0;
}
Esempio n. 16
0
END_TEST


START_TEST(test_put_in_same_bucket)
{
    /* Our hash function always places key/vals in the same bucket -
     * assert that multiple items can be placed and retreived from
     * the same bucket */

    Table_T *table = Table_new(0, cmpatom, hashatom);

    Table_put(table, (void*)0x12, (void*)0x34);
    Table_put(table, (void*)0x56, (void*)0x78);

    fail_unless( Table_length(table) == 2 );
    fail_unless( Table_get(table, (void*)0x12) == (void*)0x34);
    fail_unless( Table_get(table, (void*)0x56) == (void*)0x78);

    Table_remove(table, (void*)0x12);
    Table_remove(table, (void*)0x56);
    Table_free(&table);
}
Esempio n. 17
0
void print(Table_T files) {
	int i;

	void **array = Table_toArray(files, NULL);
	qsort(array, Table_length(files), 2*sizeof (*array), compare);
	for (i = 0; array[i]; i += 2) {
		Ring_T ring = array[i+1];
		Text_T *filename = array[i];
		if (filename->len > 0)
			Fmt_print("\t%T:", filename);
		while (Ring_length(ring) > 0) {
			Integer_T line = Ring_remhi(ring);
			Fmt_print(" %D", line);
			FREE(line);
		}
		Fmt_print("\n");
		FREE(filename);
		Ring_free(&ring);
	}
	FREE(array);
	Table_free(&files);
}
Esempio n. 18
0
int exponent_table_length(exponent_table *E)
{
  return Table_length(E->table);
}
Esempio n. 19
0
int main()
{
  FILE *fp = fopen("test.txt", "r");
  int c = 0;
  int i = 0;
  char s[512];
  Table_T our_table = Table_new(10, NULL, NULL);
  char * name;
  const char *fingerprint;
  const char* temp;
  while((c=fgetc(fp)) != ' ' && c != EOF)  //Fingerprint section
    {
      s[i]= c;
      i++;
    }
  s[i] = '\0';
  //Here we have fingerprint in s
  fingerprint = Atom_string(s);
  temp = Atom_string(s); 
  i = 0;
  while((c = getc(fp)) != '\n' && c != EOF)
    {
      s[i] = c;
      i++;
    }
  s[i] = '\0';
  //Here we have name in s
  name = s;    
  Table_put(our_table, fingerprint, name);
  while( c != EOF)
    {
      i = 0;
      while((c = fgetc(fp)) != ' ' && c != EOF) // Fingerprint section
	{
	  s[i] = c;
          i++;
	}
       s[i] = '\0';
       fingerprint = Atom_string(s);
       i = 0;
       while((c = getc(fp)) != '\n' && c != EOF)
	   {
             s[i] = c;
             i++;
            }
        s[i] = '\0';
        name = s;
        printf("FP: %s\n ", fingerprint);
    printf("NAME: %s\n", name);
 
	char * test = Table_put(our_table, fingerprint, name);
        printf("idk: %s\n", test); 
	// printf("VALUE STORED IN FP: %s\n\n", (char *)Table_get(our_table, temp));   
  }

  // NEED TO DEAL WITH TABLE MAP AND IMPLEMENTING A LIST   
  // Table_map(our_table, vfree, NULL);
  
  //printf("%s", fingerprint);
  // printf("%s", (char *)Table_get(our_table, fingerprint));
  
  printf("%d", Table_length(our_table));
  
  // Table_map(our_table, vfree, NULL);
  int length = Table_length(our_table);
  void **table = Table_toArray(our_table, NULL);
 for(int x = 0; x < 2*length; x++)
    {
      printf("%s ", (char *)table[x]); 
   }


  Table_free(&our_table);
  return 0;
}
Esempio n. 20
0
static void
write_contig_file (char *genomesubdir, char *fileroot, Table_T accsegmentpos_table, 
		   Tableint_T chrlength_table, List_T contigtypelist) {
  FILE *textfp;
  char *textfile, *iitfile, *annot;
  int naccessions, i;
  char **accessions, *divstring;
  Segmentpos_T segmentpos;
  Chrom_T chrom;
  Genomicpos_T chroffset, universalpos1, universalpos2;
  List_T divlist = NULL, intervallist = NULL, labellist = NULL, annotlist = NULL, p;
  Table_T intervaltable, labeltable, annottable;
  Interval_T interval;
#if 0
  void **keys;
  int *values, ntypes;
#endif
  
  if (divsort == NO_SORT) {
    accessions = (char **) Table_keys_by_timeindex(accsegmentpos_table,NULL);
    naccessions = Table_length(accsegmentpos_table);
  } else {
    /* Get accessions in order */
    accessions = (char **) Table_keys(accsegmentpos_table,NULL);
    naccessions = Table_length(accsegmentpos_table);
    current_accsegmentpos_table = accsegmentpos_table;
    qsort(accessions,naccessions,sizeof(char *),bysegmentpos_compare);
  }

#if 0
  /* Get types in order */
  keys = Tableint_keys(contigtype_table,NULL);
  values = Tableint_values(contigtype_table,0);
  ntypes = Tableint_length(contigtype_table);
  contigtypes = (char **) CALLOC(ntypes+1,sizeof(char *)); /* Add 1 for type 0 */
  contigtypes[0] = "";
  for (j = 0; j < ntypes; j++) {
    contigtypes[values[j]] = keys[j];
  }
  FREE(values);
  FREE(keys);
#endif

  /* Write contig text file */
  textfile = (char *) CALLOC(strlen(genomesubdir)+strlen("/")+
			     strlen(fileroot)+strlen(".contig")+1,sizeof(char));
  sprintf(textfile,"%s/%s.contig",genomesubdir,fileroot);
  /* Use binary, not text, so files are Unix-compatible */
  if ((textfp = FOPEN_WRITE_BINARY(textfile)) == NULL) {
    fprintf(stderr,"Can't write to file %s\n",textfile);
    exit(9);
  }
  FREE(textfile);

  for (i = 0; i < naccessions; i++) {
    segmentpos = (Segmentpos_T) Table_get(accsegmentpos_table,(void *) accessions[i]);
    chrom = Segmentpos_chrom(segmentpos);
    chroffset = (Genomicpos_T) Tableint_get(chrlength_table,chrom);
    universalpos1 = chroffset + Segmentpos_chrpos1(segmentpos);
    universalpos2 = chroffset + Segmentpos_chrpos2(segmentpos);

    /* Print as 1-based, inclusive [a,b] */
    if (Segmentpos_revcompp(segmentpos) == true) {
      fprintf(textfp,"%s\t%u..%u\t%s:%u..%u\t%u",
	      accessions[i],universalpos2+1U,universalpos1,
	      Chrom_string(chrom),Segmentpos_chrpos2(segmentpos)+1U,Segmentpos_chrpos1(segmentpos),
	      Segmentpos_length(segmentpos));
    } else {
      fprintf(textfp,"%s\t%u..%u\t%s:%u..%u\t%u",
	      accessions[i],universalpos1+1U,universalpos2,
	      Chrom_string(chrom),Segmentpos_chrpos1(segmentpos)+1U,Segmentpos_chrpos2(segmentpos),
	      Segmentpos_length(segmentpos));
    }
#if 0
    if (Segmentpos_type(segmentpos) > 0) {
      fprintf(textfp,"\t%s",contigtypes[Segmentpos_type(segmentpos)]);
    }
#endif

    fprintf(textfp,"\n");

    /* Store as 0-based, inclusive [a,b] */
    labellist = List_push(labellist,(void *) accessions[i]);
    if (Segmentpos_revcompp(segmentpos) == true) {
      /* The negative sign in the interval is the indication that the
	 contig was reverse complement */
      intervallist = List_push(intervallist, 
			       (void *) Interval_new(universalpos2-1U,universalpos1,
						     Segmentpos_type(segmentpos)));
    } else {
      intervallist = List_push(intervallist, 
			       (void *) Interval_new(universalpos1,universalpos2-1U,
						     Segmentpos_type(segmentpos)));
    }

#if 0
    /* IIT version 1 */
    sprintf(seglength,"%u",Segmentpos_length(segmentpos));
    annot = (char *) CALLOC(strlen(seglength)+1,sizeof(char));
    strcpy(annot,seglength);
#else
    /* IIT versions >= 2 */
    annot = (char *) CALLOC(1,sizeof(char));
    annot[0] = '\0';
#endif
    annotlist = List_push(annotlist,(void *) annot);

  }
  fclose(textfp);

#if 0
  FREE(contigtypes);
#endif
  FREE(accessions);
  intervallist = List_reverse(intervallist);
  /* contigtypelist = List_reverse(contigtypelist); -- Done by caller */ 
  labellist = List_reverse(labellist);
  annotlist = List_reverse(annotlist);

  /* Write contig IIT file */
  divstring = (char *) CALLOC(1,sizeof(char));
  divstring[0] = '\0';
  divlist = List_push(NULL,divstring);

  intervaltable = Table_new(65522,Table_string_compare,Table_string_hash);
  labeltable = Table_new(65522,Table_string_compare,Table_string_hash);
  annottable = Table_new(65522,Table_string_compare,Table_string_hash);

  Table_put(intervaltable,(void *) divstring,intervallist);
  Table_put(labeltable,(void *) divstring,labellist);
  Table_put(annottable,(void *) divstring,annotlist);

  iitfile = (char *) CALLOC(strlen(genomesubdir)+strlen("/")+
			    strlen(fileroot)+strlen(".contig.iit")+1,sizeof(char));
  sprintf(iitfile,"%s/%s.contig.iit",genomesubdir,fileroot);

#if 0
  debug(
	for (p = contigtypelist; p != NULL; p = List_next(p)) {
	  printf("Type %s\n",(char *) List_head(p));
	}
	);