예제 #1
0
void output_updated_edges ( char * outfile )
{
	FILE * fp;
	char name[256];
	unsigned int i, validCounter = 0;
	EDGE * edge;
	sprintf ( name, "%s.updated.edge", outfile );
	fp = ckopen ( name, "w" );

	for ( i = 1; i <= num_ed; i++ )
		{ validCounter++; }

	fprintf ( fp, "EDGEs %d\n", validCounter );
	validCounter = 0;

	for ( i = 1; i <= num_ed; i++ )
	{
		edge = &edge_array[i];
		fprintf ( fp, ">length %d,", edge->length );
		print_kmer ( fp, vt_array[edge->from_vt].kmer, ',' );
		print_kmer ( fp, vt_array[edge->to_vt].kmer, ',' );

		if ( EdSmallerThanTwin ( i ) )
			{ fprintf ( fp, "1," ); }
		else if ( EdLargerThanTwin ( i ) )
			{ fprintf ( fp, "-1," ); }
		else
			{ fprintf ( fp, "0," ); }

		fprintf ( fp, "%d\n", edge->cvg );
	}

	fclose ( fp );
}
예제 #2
0
void output_1edge ( preEDGE * edge, FILE * fp )
{
	int i;
	fprintf ( fp, ">length %d,", edge->length );
	print_kmer ( fp, edge->from_node, ',' );
	print_kmer ( fp, edge->to_node, ',' );
	fprintf ( fp, "cvg %d, %d\n", edge->cvg, edge->bal_edge );

	for ( i = 0; i < edge->length; i++ )
	{
		fprintf ( fp, "%c", int2base ( ( int ) edge->seq[i] ) );

		if ( ( i + 1 ) % 100 == 0 )
			{ fprintf ( fp, "\n" ); }
	}

	fprintf ( fp, "\n" );
}
예제 #3
0
//after this LINKFLAGFILTER in the Kmer is destroyed
static void output1vt ( kmer_t * node1, FILE * fp )
{
	if ( !node1 )
		{ return; }

	if ( ! ( node1->linear ) && ! ( node1->deleted ) )
	{
		outvCounter++;
		print_kmer ( fp, node1->seq, ' ' );

		//printKmerSeq(stdout,node1->seq);
		//printf("\n");
		if ( outvCounter % 8 == 0 )
			{ fprintf ( fp, "\n" ); }
	}
}
예제 #4
0
int main(int argc, char **argv) {

	char *fn = NULL;
	FILE *fh = NULL;

	unsigned int kmer = 0;

	bool nonzero = false;
	bool label = false;
	bool kmer_set = false;
	bool count_compliment = false;
	bool force_sparse = false;

	static struct option long_options[] = {
		{"input", required_argument, 0, 'i'},
		{"kmer",  required_argument, 0, 'k'},
		{"compliment", required_argument, 0, 'c'},
		{"nonzero", no_argument, 0, 'n'},
		{"label", no_argument, 0, 'l'},
		{"sparse", no_argument, 0, 's'},
		{"help", no_argument, 0, 'h'},
		{0, 0, 0, 0}
	};

	while (1) {

		int option_index = 0;
		int c = 0;

		c = getopt_long (argc, argv, "i:k:cnslvh", long_options, &option_index);

		if (c == -1)
			break;

		switch (c) {
			case 'i':
				fn = optarg;
				break;
			case 'k':
				kmer = atoi(optarg);
				kmer_set = true;
				break;
			case 'c':
				count_compliment = true;
				break;
			case 'n':
				nonzero = true; 
				break;
			case 'l':
				label = true;
				break;
			case 's':
				force_sparse = true;
				break;
			case 'h':
				help();
				exit(EXIT_SUCCESS);
				break;
			case 'v':
				printf("dna-utils version " VERSION "\n");
				exit(EXIT_SUCCESS);
				break;
			default:
				break;
		}
	}
	if(argc == 1) {
		help();
		exit(EXIT_FAILURE);
	}
	if(fn == NULL) {
		fprintf(stderr, "no input file specified with -i, reading from stdin\n");
		fh = stdin;
	}
	else {
		fh = fopen(fn, "r");
		if(fh == NULL) {
			fprintf(stderr, "Could not open %s - %s\n", fn, strerror(errno));
			exit(EXIT_FAILURE);
		}
	}
	if(!kmer_set) {
		fprintf(stderr, "Error: kmer (-k) must be supplied\n");
		exit(EXIT_FAILURE);
	}
	if(kmer == 0) { 
		fprintf(stderr, "Error: invalid kmer - '%d'.\n", kmer);
		exit(EXIT_FAILURE);
	}

	if(kmer > 12 || force_sparse) {
		kmer_map *counts = NULL;
		kmer_map *res = get_kmer_counts_from_file(counts, fh, kmer, count_compliment);

		print_kmer(res, label, nonzero, kmer);
	}
	else {
		unsigned long long *counts = NULL;
		unsigned long long *res = get_kmer_counts_from_file(counts, fh, kmer, count_compliment);
		print_kmer(res, label, nonzero, kmer);
	}

	return EXIT_SUCCESS;
}