1

I'm trying to make a Plot of two lists, once shall have the time measured with timeit and the other the amount of times i ran through the loop. I only get an empty plot so i figured that something is wrong. Could somebody perhaps tell me where the mistake is? The functions are not really important but I will post the whole thing to provide context. Here is the code:

import random
import timeit
import matplotlib.pyplot as plt

def generateSequences(n):

    RandomSequences = []
    dna = ["A","G","C","T"]
    for i in range(int(n)):

        randseq=''

        for i in range(50):
            randseq+=random.choice(dna)

        RandomSequences.append(randseq)

    return RandomSequences

def generatePrefixes(p, RandomSequences):

    First20Chars = [x[:20] for x in RandomSequences]
    RandomChoices = []
    for i in range(p):
        randomPrefix = random.choice(First20Chars)
        RandomChoices.append(randomPrefix)

    return First20Chars, RandomChoices

def searchReadsInList(RandomSequences, RandomChoices):

    start_time = timeit.default_timer()
    Matches_RS_RC = []
    for i in RandomChoices:
        for j in RandomSequences:
            if i in j:
                Matches_RS_RC.append(j)
    elapsed_sRL = timeit.default_timer() - start_time
    return Matches_RS_RC, elapsed_sRL



if __name__ == "__main__":
    count = 10
    while count < 1000:
        RandomSequences = generateSequences(count)
        First20Chars, RandomChoices = generatePrefixes(5, RandomSequences)
        Matches_RS_RC, elapsed_sRL = searchReadsInList(RandomSequences, RandomChoices)
        ListCounts = []
        ListCounts.append(count)
        ListTime = []
        ListTime.append(elapsed_sRL)
        count = count + 10

    plt.plot(ListTime, count)
    plt.xlabel('Time')
    plt.ylabel('# of Reads')
    plt.savefig("TimePlot.pdf")
    plt.show()
1
  • Your lists store only 2 values: [990] and [0.0012807846069335938]. When plot use plt.plot(ListTime, ListCounts). Commented Jun 1, 2016 at 9:17

1 Answer 1

1

I improve the main function, you had cleared lists on an every iteration:

if __name__ == "__main__":
    count = 10
    ListCounts = []
    ListTime = []

    while count < 1000:
        RandomSequences = generateSequences(count)
        First20Chars, RandomChoices = generatePrefixes(5, RandomSequences)
        Matches_RS_RC, elapsed_sRL = searchReadsInList(RandomSequences, RandomChoices)
        ListCounts.append(count)
        ListTime.append(elapsed_sRL)
        count = count + 10

    print ListCounts
    print ListTime

    plt.plot(ListTime, ListCounts)
    plt.xlabel('Time')
    plt.ylabel('# of Reads')
    plt.savefig("TimePlot.pdf")
    plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.