I am not sure what the problem is. I have a csv file that I want to filter. I want to delete all rows starting with '@' and all rows where the third column is the string “chrM”. Im basically setting my code to be like the answer here:
TypeError: character buffer object expected
But Im getting an error.
import re
import csv
inputSamFile = 'excerpt'
outSamFile = 'filternoM'
with open(inputSamFile) as inputSam, open(outSamFile, 'wt') as outSam:
inputSamCont = csv.reader(inputSam, delimiter = '\t')
outSamCont = csv.writer(outSam, delimiter = '\t')
for line in inputSamCont:
if line[0].startswith('@'):
continue
elif line[2] == 'chrM':
continue
else:
outSamCont.write(line)
Traceback (last last call): File "filterMito.py", line 19, in outSamCont.write (ProcessLine (line)) AttributeError: '_csv.writer' does not have the attribute 'write'
What am I doing wrong
source
share