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 ...
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 ...
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 ...
The databases/small.csv file from the distro code looks like this:
The file is 57 bytes and dated 21-Oct-2019. Perhaps redownload the distro code. (Or correct the file in your favorite editor).
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 == 'databases/large.csv':
AGATC = count(string, 'AGATC')
TTTTTTCT = count(string, 'TTTTTTCT')
AATG = ...
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!
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).
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 ...
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.
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).
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):
My mistake was hard coding STRs and result
Here the correction
STRs = 
for key in result_dic:
if not key == 'name':
# Gets the longest sequence for each STR
result =  * len(STRs)
i = 0
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, mode='r') as csv_file:
csv_list = list(csv....
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 ...
Maybe your "repeats" is not doing what you think it's doing? Try this:
string = "ACTGTCTCTCTGGCTGCTAA"
substring = "CT"
repeats =  * len(string)
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)]
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.
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 ...