Skip to main content
3 votes
Accepted

Why can't I print the entire string from the read file?

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.
Blauelf's user avatar
  • 21k
2 votes

DNA: Errors in sequences.3 and 18.txt

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.
Blauelf's user avatar
  • 21k
2 votes
Accepted

pset6 DNA // having problem comparing elements from the database and the sequence file

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 ...
juls's user avatar
  • 359
2 votes

PSET6 DNA Almost done - matching not working correctly

And I just realized it can be fixed by moving the counter inside of the loop. with open(sys.argv[1], "r") as fl: dictionary = csv.DictReader(fl) for row in dictionary: ...
Alexander Alexandrov's user avatar
2 votes

PSET6(DNA)- How do I access the STR's from the list (first line of csv file) dna

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 ...
DinoCoderSaurus's user avatar
2 votes
Accepted

Problem Set 6 - DNA (Using the DictReader function)

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. ...
Sorphil's user avatar
  • 27
2 votes
Accepted

DNA doesn't work with large database

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 ...
Blauelf's user avatar
  • 21k
1 vote

PSET 6 - DNA - Checking the equality of STRs

The print will occur on the first match it finds. It looks like it is not comparing the STRs as a set, but one at a time. For instance, the test on 8.txt is expected to produce Ginny. One can ...
DinoCoderSaurus's user avatar
1 vote

PSET 6 - DNA - Is there something wrong with my if statement?

One possible explanation: the database values are strings, not integers. From the csv.reader doc Each row read from the csv file is returned as a list of strings. No automatic data type conversion is ...
DinoCoderSaurus's user avatar
1 vote

pset6 DNA - help creating and referencing dictionaries

Let's start with the easy question: "how to create and reference Python dictionaries?". Dictionaries store key,value pairs (where keys must be an immutable object; e.g., ints, floats, ...
kcw78's user avatar
  • 912
1 vote
Accepted

DNA - String Compare

Your confusion is understandable and a good learning point. You are correct, when char=0 then char-length_str will always be negative. This "works" because negative indices are not part of ...
kcw78's user avatar
  • 912
1 vote
Accepted

PSET6 DNA Why is my (count consecutive substrings in string) function always returns 0's?

for i in dict: iterates through the keys (i.e. i is a key). dict[key] returns the value. So what is string set to here string = str(track_str[i])?
DinoCoderSaurus's user avatar
1 vote
Accepted

What does "consecutively" mean in pset6 DNA?

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 ...
DinoCoderSaurus's user avatar
1 vote

PSET6 DNA Think I'm getting an infinite loop which is apparent when testing with every txt file after 4.txt

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 ...
DinoCoderSaurus's user avatar
1 vote
Accepted

PSET 6 DNA - Computing STRs

What is the value of i when the function moves on to the next str?
Sentox's user avatar
  • 950
1 vote
Accepted

Computing consecutive STR is sometimes off by a little (Spoiler!)

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 ...
Sentox's user avatar
  • 950
1 vote
Accepted

DNA code doesn't work sometimes

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 ...
Taras  Lysak's user avatar
1 vote
Accepted

PSET6 DNA How to read each value in the CSV file?

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 ...
DinoCoderSaurus's user avatar
1 vote
Accepted

PSET 6 - DNA - How to pass only value in python

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 ...
Blauelf's user avatar
  • 21k
1 vote

PSET 6 - DNA.py faiils checks 2 out of 21 text files. (8.txt and 9.txt.)

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 ...
Blauelf's user avatar
  • 21k
1 vote

PSET6 DNA only getting no match

Looks like you are not comparing the correct items. If I print out the code you have here: for people in databaselist: print(people[1:], str(list(maxstr_counts))) if people[1:] == str(list(...
jrobson's user avatar
  • 11
1 vote

My code is 95% correct and I can't understand why. Why, Harry? WHY?

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 ...
Luana Nunes's user avatar
1 vote
Accepted

Pset6, DNA - Convert all columns in a list to integers, skipping the first column

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 ...
user3671's user avatar
  • 165
1 vote

Counter fails to update for DNA

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 ...
xjcl's user avatar
  • 111
1 vote

DNA pset6 - Unable to calculate maximum STR repeats in DNA file

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(...
user3671's user avatar
  • 165
1 vote

PSET6 DNA - I passed every test it wanted me to do, but I got 42% after submitting?

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
reham501's user avatar
1 vote
Accepted

MY code works with a hardcoded string, but not a string object

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 ...
DinoCoderSaurus's user avatar
1 vote
Accepted

Difficulty comparing sequence and individual in PSET6 DNA

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 ...
FAT UNEMPLOYED MIDDLE-AGED NIN's user avatar
1 vote
Accepted

Stroring the header row from a csv file

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.
Ojou Nii's user avatar
  • 731

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