BjornFJohansson / pydna

Clone with Python! Data structures for double stranded DNA & simulation of homologous recombination, Gibson assembly, cut & paste cloning.
Other
166 stars 45 forks source link

Gel: DimensionalityError: Cannot convert from 'pixel' to 'dimensionless' #43

Closed klprint closed 7 years ago

klprint commented 7 years ago

Hi again, sorry for opening another issue, but I came across the following, when I try to plot a gel:

Using the gel-notebook example:

from pydna.gel import weight_standard_sample, Gel
st = weight_standard_sample('1kb+_GeneRuler')
from pydna.genbank import Genbank
gb = Genbank("bjornjobb@gmail.com")
gene = gb.nucleotide("X06997")
from pydna.parsers import parse_primers
primer_f, primer_r =      parse_primers(''' >760_KlLAC12_rv (20-mer)
                                             ttaaacagattctgcctctg

                                             >759_KlLAC12_fw (19-mer)
                                             aaatggcagatcattcgag
                                         ''')

from pydna.amplify import pcr
pcr_prod = pcr(primer_f, primer_r, gene)
Gel([st, [pcr_prod]], gel_len=16).run()

output:

---------------------------------------------------------------------------
DimensionalityError                       Traceback (most recent call last)
<ipython-input-6-bda50d703fcf> in <module>()
----> 1 Gel([st, [pcr_prod]], gel_len=16).run()

/usr/local/lib/python3.6/site-packages/pydna/gel.py in run(self, till_len, till_time, exposure, plot, res, cursor_ovr, back_col, band_col, well_col, noise, detectlim, interpol, dset_name, replNANs)
   1377                                     names, gel_len, wellx, welly, wellsep, res,
   1378                                     cursor_ovr, back_col, band_col, well_col,
-> 1379                                     noise, Itol, detectlim, title, FWTM, False)
   1380             return #gelpic
   1381         return None

/usr/local/lib/python3.6/site-packages/pydna/gel.py in gelplot_imshow(distances, bandwidths, intensities, lanes, names, gel_len, wellx, welly, wellsep, res, cursor_ovr, back_col, band_col, well_col, noise, Itol, detectlim, title, FWTM, show)
    726     gel_width = sum(wellx) + (nlanes+1)*wellsep  # cm
    727     res = res.to('px/cm')
--> 728     pxl_x = int(round(gel_width * res))
    729     pxl_y = int(round(gel_len * res))
    730     lane_centers = [(l+1)*wellsep + sum(wellx[:l]) + 0.5*wellx[l]

/usr/local/lib/python3.6/site-packages/pint/quantity.py in __int__(self)
    439         if self.dimensionless:
    440             return int(self._convert_magnitude_not_inplace(UnitsContainer()))
--> 441         raise DimensionalityError(self._units, 'dimensionless')
    442 
    443     def __long__(self):

DimensionalityError: Cannot convert from 'pixel' to 'dimensionless'
BjornFJohansson commented 7 years ago

Hi, I think this has to do with the version of pint.

import pint

pint.__version__
Out[2]: '0.7.2'

I have 0.7.2 and I can run the above example.

What version do you have installed?

klprint commented 7 years ago

Hi, I've got a newer version installed:

>>> import pint
>>> pint.__version__
'0.8.1'

I'll see whether I can downgrade to your version.

BjornFJohansson commented 7 years ago

a new version of pydna is in the pipeline that should fix this issue.

klprint commented 7 years ago

Great, then I will wait patiently. Thank you for your work on this module!

BjornFJohansson commented 7 years ago

Hi, the new version 2.0.2 should work also with a newer version of pint.