Question

In: Statistics and Probability

8.Write in R code. a)stimulate a string of 10,000 characters drawn uniformly and independently for the...

8.Write in R code.

a)stimulate a string of 10,000 characters drawn uniformly and independently for the set {A,C,G,T} [HINT: sample]

b) create a frequency table of the string [HINT:table]

c) write a function to create a contingency table of adjacent k-tuples. For example, with k=3 and with the string "CAGACAAAAC", you would want to produce the following table: [ ONLY USE FOR LOOPS AND PASTE (,collapse=""), DO NOT USE EMBED, SUBSTR, or DO.CALL]

AAA AAC ACA AGA CAA CAG GAC

2 1    1 1 1 1 1

Solutions

Expert Solution

Answer:

Given that :

a) stimulate a strong of 10,000 characters drawn uniformly and independently for the set{A,C,G,T}

R code with comments

#set the random seed for repeatability
set.seed(123)

#set the string
x<-c("A","C","G","T")
#set the number of simulations
R<-10000

#part a)
#simulate a string of R characters
s<-sample(x,size=R,replace=TRUE)

#part b)
#create a frequency table
table(s)

#part c
getTable<-function(y,k){
#initialize the result
result<-character(0)
#go through the string, k places at a time
for (i in 1:(length(y)-k+1)){
#get k characters and concat
result<-rbind(result,paste(y[i:(i+k-1)],collapse=""))
}
#create the contigency table
out<-table(result)
return(out)
}

#test the function given in the example
s1<-c("C","A","G","A","C","A","A","A","A","C")
getTable(s1,3)

#test the function on the string from part a)
getTable(s,3)

--------

#get this


Related Solutions

write a python code that Returns a string composed of characters drawn, in strict alternation, from...
write a python code that Returns a string composed of characters drawn, in strict alternation, from s1 and s2. If one string is longer than the other, the excess characters are added to the end of the string as shown in the examples below #Example 1 - blend("ape", "BANANA") returns "aBpAeNANA" #Example 2 - blend("BOOT", "gold") returns "BgOoOlTd"
Write Java code that prompts the user for a string and tells them if the grouping characters in that string are balanced.
Write Java code that prompts the user for a string and tells them if the grouping characters in that string are balanced. Grouping characters are ( and ), [ and ], and { and }. I got the basic idea for this problem from HackerRank. It’s also a very common interview question.*******************8Example output**************Enter the expression:{[()]} {[()]}is balancedEnter the expression: {()()} {()()}is balancedEnter the expression: {([[])} {([[])}is not balancedEnter the expression: {([)]} {([)]}is not balanced
IN PYTHON Given a string with duplicate characters in it. Write a program to generate a...
IN PYTHON Given a string with duplicate characters in it. Write a program to generate a list that only contains the duplicate characters. In other words, your new list should contain the characters which appear more than once. Suggested Approach Used two nested for loops. The first for loop iterates from 0 to range(len(input_str)). The second for loop iterates from first_loop_index + 1 to range(len(input_str)). The reason you want to start at first_loop_index + 1 in the nested inner loop...
Given a string, write a method called removeRepthat returns another string where adjacent characters that are...
Given a string, write a method called removeRepthat returns another string where adjacent characters that are the same have been reduced to a single character. Test the program by calling the method from the main method. For example: removeRep(“yyzzza”) à “yza” removeRep(“aabbbccd”) à “abcd” removeRep(“122333”) à “123”
Write a method that computes the number of lowercase letters (a-z) characters in a String: The...
Write a method that computes the number of lowercase letters (a-z) characters in a String: The method signature is as follows:  public int count(String s)
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
Write a C program with a struct that contains a string of 12 characters and two...
Write a C program with a struct that contains a string of 12 characters and two integers: number1 and number2. Read all 3 values in from the keyboard using scanf. Print the string and the sum of the two integers using the fully qualified struct names.
Write a C++ program which reads a string, less than 10 characters long. This string represents...
Write a C++ program which reads a string, less than 10 characters long. This string represents an integer expressed in roman numbers. Let a function convert the number from roman to arabic form (i.e., our standard digits). Let then the main program writes out both forms. The roman numbers are written according to: M = 1000, D = 500, C =100, L=50, X=10, V=5, I=1. Examples: LXXXVII = 87 CCXIX = 219 MCCCLIV = 1354 MMDCLXXIII = 2673
1.Write the java code to create a two dimensional String array of sizes 12 by 8;...
1.Write the java code to create a two dimensional String array of sizes 12 by 8; Given the java array:       double[] test = new double[3]; 2.  Write the java code to put the numbers 1.0, 2.0, and 3.0 in to the array so that the 1.0 goes in the first cell, the 2.0 goes in the second cell and the 3.0 goes in the third cell. 3. Can you have different types of data is a three dimensional array? 4....
Let D = {xi} n i=1, where xi ∈ R, be a data set drawn independently...
Let D = {xi} n i=1, where xi ∈ R, be a data set drawn independently from a Gumbel distribution α ∈ R is the location parameter and β > 0 is the scale parameter. a) Derive an algorithm for estimating α and β. b) Implement the algorithm derived above and evaluate it on data sets of different sizes. First, find or develop a random number generator that creates a data set with n ∈ {100, 1000, 10000} values using...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT