Header Leaderboard Ad

Collapse

CNV Simulator -- Random Number Generation

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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;
    }
    }

  • #2
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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, 11:20 AM. Reason: typo

        Comment


        • #5
          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.

          Comment


          • #6
            is your program available for download? i would like to generate simulated CNV

            Comment

            Latest Articles

            Collapse

            • seqadmin
              A Brief Overview and Common Challenges in Single-cell Sequencing Analysis
              by seqadmin


              ​​​​​​The introduction of single-cell sequencing has advanced the ability to study cell-to-cell heterogeneity. Its use has improved our understanding of somatic mutations1, cell lineages2, cellular diversity and regulation3, and development in multicellular organisms4. Single-cell sequencing encompasses hundreds of techniques with different approaches to studying the genomes, transcriptomes, epigenomes, and other omics of individual cells. The analysis of single-cell sequencing data i...

              01-24-2023, 01:19 PM
            • seqadmin
              Introduction to Single-Cell Sequencing
              by seqadmin
              Single-cell sequencing is a technique used to investigate the genome, transcriptome, epigenome, and other omics of individual cells using high-throughput sequencing. This technology has provided many scientific breakthroughs and continues to be applied across many fields, including microbiology, oncology, immunology, neurobiology, precision medicine, and stem cell research.

              The advancement of single-cell sequencing began in 2009 when Tang et al. investigated the single-cell transcriptomes
              ...
              01-09-2023, 03:10 PM
            • seqadmin
              AVITI from Element Biosciences: Latest Sequencing Technologies—Part 6
              by seqadmin
              Element Biosciences made its sequencing market debut this year when it released AVITI, its first sequencer. The AVITI System uses avidity sequencing, a novel sequencing chemistry that delivers higher quality data, decreases cycle times, and requires lower reagent concentrations. This new instrument reportedly features lower operating and start-up costs while maintaining quality sequencing.

              Read type and length
              AVITI is a short-read benchtop sequencer that also offers an innovative...
              12-29-2022, 10:44 AM

            ad_right_rmr

            Collapse
            Working...
            X