Python module help. Need help correct my code.

1. substrings(string, k): Input is a string and an integer k. Output is a list of all substrings of length k, of the input string.

my code:

def substrings(string, k):

return ”.join(random.choice(string) for x in range(k))


#how can i show all the possible combinations?

#example input: (substrings(“ACGT”,2)

# example output: AC, AG, AT, etc…

2. profile(string_list, p=0): Input is string_list, a list of string. Output is a dictionary with keys are ‘A’, ‘B’, ‘C’ and ‘D’; and its values are lists of probability values for each position.

“”” The probability is calculated by dividing each count value at position i by the total of the counts for position i. This fraction represents the probability that that letter occurs at that position in the provided motifs. An optional parameter p results in probabilities that are calculated from a count matrix adjusted with pseudo-counts of p. “””

3. select_new(motifs, probs). Input is a list of strings, and a list of associated probabilities. Output is one of the strings selected using the input probabilities. If the probability values do not add up to 1, they need to be normalized to be relative to their sum. This is analogous to simulating the throw of a loaded die.

4. consensus(profile): Input is a list of strings. Output is a string corresponding to the most frequently occurring letter at each position.

Consensus (list_of_string) :

Most frequent letter in each position.

E.g: strings of 4

( ) ( ) ( ) ( )







Most frequent at position 1: A

Most frequent at position 2: G

Most frequent at position 3: C

Most frequent at position 4: T