libnano / primer3-py

Simple oligo analysis and primer design
https://libnano.github.io/primer3-py
GNU General Public License v2.0
166 stars 44 forks source link

calc tm breaks with lower case input #115

Closed Tim-Kirkwood closed 1 year ago

Tim-Kirkwood commented 1 year ago

Hello, My system:

windows 10
python version 3.11.3

I am working in a conda env with these libs:

name: pip_env
dependencies:
  - python
  - spyder-kernels=2.4.1
  - biopython
  - plotly
  - pandas
  - pip
  - pip:
    - primer3-py
    - snapgene_reader

Feeding in lower case sequences seems to break the calc tm methods:

oligo_calc = p3.thermoanalysis.ThermoAnalysis(mv_conc=50, 
                                              dv_conc=1.5,
                                              dntp_conc=0.6, 
                                              dna_conc=50.0)
seq_lower = 'atgcatttcgcatctcgagatctaagaga'
seq_upper = seq_lower.upper()
print ('---OLIGO CALC---\n',
       f'TM UPPER:  {oligo_calc.calc_tm(seq_upper)}\n',
       f'TM LOWER:  {oligo_calc.calc_tm(seq_lower)}\n',
      '---BINDINGS CALC---\n',
      f'TM UPPER:  {p3.bindings.calc_tm(seq_upper)}\n',
      f'TM LOWER:  {p3.bindings.calc_tm(seq_lower)}\n'
       )

# Prints:
# ---OLIGO CALC---
# TM UPPER:  62.01093944856859
# TM LOWER:  -999999.9999
# ---BINDINGS CALC---
# TM UPPER:  62.01093944856859
# TM LOWER:  -999999.9999
benpruitt commented 1 year ago

The oligotm binary that is built w/ the native primer3 library converts lower case sequences to upper case as a matter of course (see oligotm_main.c:256). The underlying oligotm function, which we invoke directly in the primer3-py Cython code, expects a fully upper case input.

We've generally avoided adding / including input sanitization in primer3-py as a matter of course, given that the library is intended to offer a more performant alternative to command line wrappers. I would suggest that you just call .upper() on the string input to calc_tm. If additional IUPAC degenerate base sanitization is required, primer3-py includes a sanitize_sequence method in p3helpers (ref)