Thread: DNA C programing

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    7

    DNA C programing

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main()
    {
    
    	time_t time_start, time_end, time_period;
    	time_start = time(0);
    	//time_start = time(NULL);
    
    	FILE *fPtr;
    
    	if ((fPtr = fopen("basePair_125kb.bin", "wb+")) == NULL)
    	{
    		printf("File could not be opened.\n");
    		return -1;
    	}
    	
    	srand(time(NULL));
    
    	unsigned long basePair_0, basePair_1, basePair_2, basePair_32bit;
    	
    	int loop;
    	
    	for (loop = 0; loop < 7812; loop++)
    	{
    		basePair_0 = rand();
    		basePair_1 = rand();
    		basePair_2 = rand();
    		basePair_32bit = (basePair_2 << 30) + (basePair_1 << 15) + basePair_0;
    		
    		fprintf(fPtr, "%.8X", basePair_32bit);
    
    		if (loop % 1000 == 0)
    		{
    			printf("loop count = %d\n", loop);
    		}
    	}
    
    	basePair_0 = rand();
    	basePair_1 = rand();
    	basePair_2 = rand();
    
    	basePair_32bit = (basePair_2 << 30) + (basePair_1 << 15) + basePair_0;
    	basePair_32bit = basePair_32bit >> 16;
    
    	printf("Random 15-bit basePair_0: %u\n", basePair_0);
    	printf("Random 15-bit basePair_1: %u\n", basePair_1);
    	printf("Random 2-bit basePair_2: %u\n", basePair_2);
    	printf("Random 32-bit basePair_32bit: %u\n", basePair_32bit);
    	printf("RAND_MAX = %u\n", RAND_MAX);
    	printf("sizeof(long) = %d\n", sizeof(long));
    
    	fprintf(fPtr, "%.4X", basePair_32bit);
    	
    	fclose(fPtr);
    
    	time_end = time(0);
    	//time_end = time(NULL);
    	time_period = time_end - time_start;
    	
    	printf("Time to run the random DNA generation = %d\n", time_period);
    
    	return 0;
    }
    hi guys.... afta consult our lecturer, we successfully done few parts of our assignment... somehow, we do not know how to convert it from hexadecimal form to binary form and finally to character form (ATGC)... anyone can suggest us how to convert?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    C programing for DNA...
    And what was wrong with continuing the previous thread?

    I have no idea what you think you are doing, as you seem to assume that rand() generates a 15-bit number, which I'm sure some implementations do, but it's far from guaranteed.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    in order to get the number into AGCT form take the number and convert it into base 4, then use that as an array index for a character array holding "AGCT"
    Last edited by ಠ_ಠ; 04-29-2009 at 09:58 AM.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C programing for DNA...
    By S16 in forum C Programming
    Replies: 9
    Last Post: 04-29-2009, 09:25 AM
  2. Programing microcontrollers in c
    By gorabhat in forum C Programming
    Replies: 2
    Last Post: 09-09-2008, 10:40 AM
  3. Human brain and programing
    By avgprogamerjoe in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 08-27-2007, 04:48 PM
  4. Non programing Question
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 06-21-2002, 06:55 AM
  5. DNA Supernanocomputers and the city problem.
    By sean in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 06-05-2002, 01:12 PM