I am attempting to use this code to parse a csv file but cannot find my way around this error:
"File "(file location)", line 438, in parser_42
position = tmp2[1]
IndexError: list index out of range"
my csv file is structured like so:
mutant coefficient Score
Q41V -0.19 0.05
Q41L -0.08 0.26
Q41T -0.21 0.43
I23V -0.02 0.45
I61V 0.01 1.12
I want to take the mutants and separate 'Q' '41' and 'V', for example. I then want to create lists of positions and wt's and put them in numerical order.
The goal is to write the string "seq" to a new csv file
obviously, I am a beginner in python and data manipulation. I imagine that I am just overlooking something silly...Can anyone steer me in the right direction?
def parser_42(csv_in, fasta_in, *args):
with open(csv_in, 'r') as tsv_in:
tsv_in = csv.reader(tsv_in, delimiter='\t')
next(tsv_in) # data starts on line 7
next(tsv_in)
next(tsv_in)
next(tsv_in)
next(tsv_in)
next(tsv_in)
for row in tsv_in:
tmp = row[0].split(',')
tmp2 = re.split('(\d+)', tmp[0])
wt = tmp2[0]
position = tmp2[1]
substitution = tmp[2]
seq = ""
current_positions = []
if position not in current_positions:
current_positions += [position]
print(current_positions)
seq += wt
else:
continue
print(seq)
tmp2[1]