Entering edit mode
4.6 years ago
anabaena
▴
10
Hey all, I am working on a script to translate a mass amount of .tsv files containing predicted ORFs using biopython. I keep running into the error that a 'module is not callable when the modules are correctly loaded. Everything works until I enter the translation phase of the script when I receive a module error. Below is the full error:
> File "./convert_tsv_fasta.py", line 34, in <module>
> SeqIO.write(proteins, inputfilepath + 'translation.faa', 'fasta')
> File "/Users/zacharyhenning/miniconda3/lib/python3.7/site-packages/Bio/SeqIO/__init__.py",
> line 556, in write
> for record in sequences:
> File "./convert_tsv_fasta.py", line 32, in <genexpr>
> for nuc_record in SeqIO.parse(outputfilepath, 'fasta')
> File "./convert_tsv_fasta.py", line 16, in make_protein_record
> id="translated_" + nuc_record.id,
> TypeError: 'module' object is not callable
Here is my code:
from Bio import SeqIO
import pandas as pd
import numpy as np
import sys
from Bio.Seq import Seq
from Bio.Alphabet import generic_dna
from Bio import SeqIO
from Bio import SeqRecord
inputfilepath = sys.argv[1]
outputfilepath = inputfilepath + "_nucleotide.fasta"
#function being used in script
def make_protein_record(nuc_record):
return SeqRecord(
seq=nuc_record.seq.translate(to_stop=True, table='Bacterial'),
id="translated_" + nuc_record.id,
)
#initialize DF skipping first few rows
df = pd.DataFrame(pd.read_csv(inputfilepath, skiprows=5, delimiter='\t'))
df = df.drop(columns=['ContigCoord'])
#create dictionary to write to file
dict_y = df['Sequence'].to_dict()
for key, value in dict_y.items():
with open(outputfilepath, 'a+') as handle:
handle.write(">" + str(key) + "\n")
handle.write(value + "\n" + "\n")
handle.close()
#generator expression to translate files
proteins = (
make_protein_record(nuc_record)
for nuc_record in SeqIO.parse(outputfilepath, 'fasta')
)
SeqIO.write(proteins, inputfilepath + 'translation.faa', 'fasta')
could you please share a few lines of the tsv file that you are using?
In
from Bio import SeqRecord
you should useBio.SeqRecord import SeqRecord
instead. Have you considered the six frame translations? you can usefrom Bio.SeqUtils import six_frame_translations