2
$\begingroup$

Looking for some guidance.

In an introductory bioinformatics class I am tasked with doing the following in R:

  1. Create the sequence ACTGACTG
  2. Generate a random string of nucleotides with equal probabilities.

Are there certain functions that I should be looking at? No library or package or set of functions was provided so I am completely lost. I am assuming there must be functions in R that do these things that I need to manipulate, but I cannot seem to find any resources explaining that. I looked at seq() (thinking it might generate DNA sequences), but it only seems to generate sequences of integers. I also looked at randDNA(), but it is random, how could I make it generate the exact string in question 1).

Any direction will be greatly appreciated. Thanks.

$\endgroup$
1
  • 1
    $\begingroup$ They are two separate problems. If you have something that generates sequences of random integers can you think of a way to map those to the bases you want to report. The first question is ambiguous. How do your report the sequence you created? $\endgroup$
    – Bioathlete
    Oct 14, 2018 at 14:01

1 Answer 1

1
$\begingroup$

Without giving away too much for your homework check out the sample() function in R. Think about how you can pass DNA bases to this function to generate random sequences.

$\endgroup$
2
  • $\begingroup$ Thanks this is really helpful. Can you please help me understand the prob parameter, as I understand the probability of each element is relative to the entire list. Is it possible to specify probabilities for each element in certain positions? say I have sample(1:2, size=4, replace=TRUE, prob=c(0.8, 0.2)) This says that 1 has probability 0.8 is the list overall, but I want to say 1 has probability 0.8 in position 4 (and some other probability in other positions) $\endgroup$
    – EvaD
    Oct 13, 2018 at 22:16
  • 1
    $\begingroup$ This can't be done using just the prob parameter, because it only takes a single vector as input. You'll have to find some loopy, or otherwize crazy way for trying to apply different probabilities at different positions. $\endgroup$
    – gringer
    Oct 13, 2018 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.