I don't know how to print the person's name that matches the numbers (as strings) returned from "list4"
(sorry for bad english) So I use print(list4)
and I get the right values, but I don't know how to get
the name from the person. Example : list4 = ['4', '1', '5']
, so how I get 'Bob'? I would appreciate any help!
import csv
import sys
import itertools
import re
import collections
import json
import functools
def main():
# TODO: Check for command-line usage
# not done yet
filecsv = sys.argv[1]
filetext = sys.argv[2]
names = []
# TODO: Read DNA sequence file into a variable
with open(filecsv, "r") as csvfile:
reader = csv.reader(csvfile)
dict_list = list(reader)
names.append(dict_list)
# Open sequences file and convert to list
with open(filetext, "r") as file:
sequence = file.read()
# TODO: Find longest match of each STR in DNA sequence
find_STR = []
for i in range(1, len(dict_list[0])):
find_STR.append(longest_match(sequence, dict_list[0][i]))
#TODO: Check database for matching profiles
#convert dict_list to a string
listToStr = ' '.join([str(elem) for elem in dict_list])
#convert find_STR to a string
A = [str(x) for x in find_STR]
# compare both strings
list3 = set(A)&set(listToStr)
list4 = sorted(list3, key = lambda k : A.index(k))
if(list4):
print(name) # how???`
return
def longest_match(sequence, subsequence):
"""Returns length of longest run of subsequence in sequence."""
# Initialize variables
longest_run = 0
subsequence_length = len(subsequence)
sequence_length = len(sequence)
# Check each character in sequence for most consecutive runs of subsequence
for i in range(sequence_length):
# Initialize count of consecutive runs
count = 0
# Check for a subsequence match in a "substring" (a subset of characters) within sequence
# If a match, move substring to next potential match in sequence
# Continue moving substring and checking for matches until out of consecutive matches
while True:
# Adjust substring start and end
start = i + count * subsequence_length
end = start + subsequence_length
# If there is a match in the substring
if sequence[start:end] == subsequence:
count += 1
# If there is no match in the substring
else:
break
# Update most consecutive matches found
longest_run = max(longest_run, count)
return longest_run
main()
'Bob'
doesn't occur anywhere in the code you've shown so far - where does it come from?