Hot answers tagged

3

I guess you meant print(dna[i:i+len("AGATC")]). In Python, if the end of the substring is before the beginning, the substring is empty, so you are printing a bunch of empty strings.


2

The answer to your specific question is that if dna_data[i] == formation_count_small[j] compares an int to a string. However, there are several other problems, so I'm going to offer advice. Don't hardcode the specific sequences being looked for. The first line of the csv file has the information, get it from there. Then there's no need to look at the exact ...


2

According to the python csv doc, this col = len(next(reader)) # get number of columns "Return[s] the next row of the reader’s iterable object as a list", which in this case is the first row. This reader = list(reader) returns the "rest" of the rows in the iterable object. If you get rid of the first line (the col =), that next line will convert the iterable ...


2

That code on StackOverflow is meant to calculate something else, I guess. We don't need overlap, in our case, we have to keep track of the longest contiguous repetition sequence. For that, we need separate variables for current and longest streak, and update the longest if the current surpasses it. Also, we have to check whether the current match happens to ...


1

The databases/small.csv file from the distro code looks like this: name,AGATC,AATG,TATC Alice,2,8,3 Bob,4,1,5 Charlie,3,2,5 The file is 57 bytes and dated 21-Oct-2019. Perhaps redownload the distro code. (Or correct the file in your favorite editor).


1

Got the solution via a very cheeky way; storing the values in a list, checking each row of values for each STR, then comparing those database values with the ones I got using my count function. if sys.argv[1] == 'databases/large.csv': AGATC = count(string, 'AGATC') TTTTTTCT = count(string, 'TTTTTTCT') AATG = ...


1

Ok, I`ve found the bug. It came out, that my code wasn't comparing the current sequnce lenth with the previous maximum, but just increased 'counter' value, if the STR lenth was greater than 1. It meant that in case I had two seqences 2 and 3 STR long, my result would'n be '3' but '5'. A minor change in code and one more variable did the job!


1

A DictReader object (instance) has the public methods list in this doc. It is not a python Built-in type, and cannot be used as such. One approach would be to store the rows in a python collection (eg list, dict).


1

The first cur_count = 1 would have to be inside the y loop, so numbers don't carry over. Rare case, but still. If you like to do it that way, I'd write a while loop instead of for i in range, and increment the index manually, incrementing by the str length on a match, and by one on a mismatch/counter reset. Also, I'd use 0 as the starting value, if you ...


1

I don't think you should hard-code any sequences, but take them from the first row of the CSV file. You may assume that the first row of the CSV file will be the column names. The first column will be the word name and the remaining columns will be the STR sequences themselves.


1

The proximate cause of the infinite loop is this while in the repeatss function: while dna_str[j : j + len_str] in str_csv[i]: curr_str += 1 j += len_str In python, if i is greater than len(s) in slice notation (s[i : j]), it returns the empty string (even though s[i] would return index out of range error). From ...


1

What is the value of i when the function moves on to the next str?


1

Your problem is that the nucleotide loop steps through each letter of the sample, but when you find a match your index variable falls out of sync with the letter you are checking. I generally prefer not to just write code as an answer, but have a look at this variation of your comp_repeats function to see the difference: def comp_repeats(header, sample): ...


1

The way you wrote it, partial matches from multiple people would add up. Set match inside the outer loop, so that each person starts fresh at zero.


1

My mistake was hard coding STRs[] and result[] Here the correction STRs = [] for key in result_dic[1]: if not key == 'name': STRs.append(key) # Gets the longest sequence for each STR result = [0] * len(STRs) i = 0


1

Without answering your question directly (i.e. how to convert to int), let me point out that your csv_list is not actually a list. If you run a print(type(csv_list)) as a sanity check, you'll see it shows <class '_csv.reader'>. To read in the data, change your code to the following: with open(argv[1], mode='r') as csv_file: csv_list = list(csv....


1

There's a subtle bug in here: for char in range(len(tf)): # ... char += len(str)-1 Let's say range(len(tf) = [0, 1, 2, 3, 4] and len(str) = 3. What happens if we match while char == 0 is that we will update it using char += ... to char == 2. But then the for-loop goes into the next iteration and resets it to char == 1, because that is ...


1

Maybe your "repeats" is not doing what you think it's doing? Try this: string = "ACTGTCTCTCTGGCTGCTAA" substring = "CT" repeats = [0] * len(string) print(repeats) for i in range(len(string)-len(substring), -1, -1): if string[i:i+len(substring)-1] == substring: repeats[i] = 1 + repeats[i+len(substring)] print(repeats)


1

checkCS50 is strict, once it gave me a zero just because the result did not had '\n' as expected, so share your last part of the code when printing the match i will try to help


1

This sequence = sequence_o.read doesn't execute the read function. It declares sequence as (basically) a copy of the read function. When a function does not take arguments (as with read), one must use read() to execute the function.


1

SO I've had that exact problem a couple of hours ago. you are not actually comparing an int to an int think about the type of MAX_AGATC and the type that you will get from the key 'AGATC' you will get a string from 'AGATC' so you need to str(MAX_AGATC) and they will be the same type and the values will be compared properly same goes for the rest of them ...


1

header = next(<reader variable>) The next function should give you the 1st row of the file, but I am unsure if this is the answer to your situation as you did not provide any code.


Only top voted, non community-wiki answers of a minimum length are eligible