SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
Software tools for detecting Copy Number Variations (CNV) smice Bioinformatics 26 05-04-2016 10:05 AM
CNV-seq, to detect Copy Number Variation using next-generation sequencing xiechao Literature Watch 46 10-20-2015 10:30 AM
Looking for the right WGS simulator oiiio Bioinformatics 5 07-20-2012 11:59 AM
PubMed: ART: a next-generation sequencing read simulator. Newsbot! Literature Watch 0 12-27-2011 03:00 AM
Nexgen simulator. aloliveira General 1 02-14-2011 09:57 AM

Reply
 
Thread Tools
Old 01-27-2011, 01:19 PM   #1
gprakhar
Member
 
Location: India

Join Date: Aug 2010
Posts: 78
Default CNV Simulator -- Random Number Generation

Hello,

I have written a program to simulate CNV, into the reference genome.

It take the Reference Genome/Chromosome as input. The program then generates a Random number(X), copies the segment from that position(X), size specified by user.
Then generates another random number(Y), and inserts the copied segment from X position, at Y position. The output is the modified input file with inserted CNV and a txt file with Location of CNVs ie. position where copied from (X) and where Inserted (Y).

I give the Random Number generation function MIN and MAX value. MIN =1 and MAX=last Position(Size), it then generates a Random number within these limits.
Problem is, with same input(MIN & MAX) the random numbers generated is same. eg. If I make my program run once and generate 100 numbers, they are random. But if I generate 100 numbers by running the program again, the numbers are same as before.

CODE:
//call this function first to seed
void initialize_rand(){
srand((unsigned)(time(0)));
}

//generates a psuedo-random integer between min and max
long int randint(long int min, long int max){
if(min>max){
return lrand48()%(min-max)+max;
}
else{
return lrand48()%(max-min)+min;
}
}
gprakhar is offline   Reply With Quote
Old 01-27-2011, 01:22 PM   #2
gprakhar
Member
 
Location: India

Join Date: Aug 2010
Posts: 78
Default PS

I know this is not a C programming forum.
Googled the problem, but didn't find anything useful.
But as many of the member here have dealt with similar situation, hence I thought of asking here.
gprakhar is offline   Reply With Quote
Old 01-28-2011, 12:38 AM   #3
simonandrews
Simon Andrews
 
Location: Babraham Inst, Cambridge, UK

Join Date: May 2009
Posts: 871
Default

Quote:
Originally Posted by gprakhar View Post
Problem is, with same input(MIN & MAX) the random numbers generated is same. eg. If I make my program run once and generate 100 numbers, they are random. But if I generate 100 numbers by running the program again, the numbers are same as before.
If that's happening then it means your RNG is using the same seed value each time. I'm not a C programmer but I suspect that time(0) returns the same value each time and that you probably want to use time(NULL) to get the current time value so the seed is different each time.
simonandrews is offline   Reply With Quote
Old 01-28-2011, 11:20 AM   #4
quinlana
Senior Member
 
Location: Charlottesville

Join Date: Sep 2008
Posts: 119
Default

Your issue is likely that the time() function has granularity to the second. If you make multiple calls to you program in the same second, the results will be identical. The following will seed based on time and process_id on POSIX systems. Therefore, for a given boot cycle, you are guaranteed not to have redundant seeds

Code:
srand((unsigned)time(0)+(unsigned)getpid())
You'll need to include the following fir getpud():

Code:
#include <unistd.h>

Last edited by quinlana; 01-28-2011 at 11:20 AM. Reason: typo
quinlana is offline   Reply With Quote
Old 01-29-2011, 08:32 AM   #5
gprakhar
Member
 
Location: India

Join Date: Aug 2010
Posts: 78
Smile Solved

Thank you everyone for the reply.

I made the change suggested by "quinlana".
Also changed the seeding function to srand48().
Every thing is working fine now.
gprakhar is offline   Reply With Quote
Old 05-11-2012, 10:34 PM   #6
adurasiwam3
Member
 
Location: singapore

Join Date: Apr 2012
Posts: 12
Default

is your program available for download? i would like to generate simulated CNV
adurasiwam3 is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 10:44 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO