eyurtsev / FlowCytometryTools

A python package for visualization and analysis of high-throughput flow cytometry data
https://eyurtsev.github.io/FlowCytometryTools/
MIT License
113 stars 46 forks source link

Issue with calling transform() on linear and glog #11

Closed dmoccia closed 7 years ago

dmoccia commented 8 years ago

Not sure if I am calling this incorrectly but I tried the following two transforms:

tsample = sample.transform('glog',  channels=['Y2-A', 'B1-A', 'V2-A'], l=10)
tsample = sample.transform('linear',  channels=['Y2-A', 'B1-A', 'V2-A'], old_range=0.5, new_range=2.5)

but I am getting back (after stack trace attached) stacktrace.txt

linear() got an unexpected keyword argument 'd' I checked the code itself and looked like these were acceptable arguments, can you confirm?

Thank you

eyurtsev commented 8 years ago

thanks for reporting this looks like something is passing an extra 'd' argument down the road

in the meantime you can define your own custom transformations if you need a workaround

http://eyurtsev.github.io/FlowCytometryTools/gallery.html#custom-transformations

dmoccia commented 8 years ago

No problem on the report, nice looking library. I will try the custom transforms out.

dmoccia commented 8 years ago

I believe I figured out why this issue is happening. In your FCMeasurement.tranform method you have the following code

`if isinstance(transform, Transformation): transformer = transform else: if auto_range: # determine transformation range if 'd' in kwargs: warnings.warn( 'Encountered both auto_range=True and user-specified range value in ' 'parameter d.\n Range value specified in parameter d is used.') else: print "in else" channel_meta = self.channels

the -1 below because the channel numbers begin from 1 instead of 0

                # (this is fragile code)
                ranges = [float(r['$PnR']) for i, r in channel_meta.iterrows() if
                          self.channel_names[i - 1] in channels]
                if not np.allclose(ranges, ranges[0]):
                    raise Exception("""Not all specified channels have the same data range,
                        therefore they cannot be transformed together.\n
                        HINT: Try transforming one channel at a time.
                        You'll need to provide the name of the channel in the transform.""")
                kwargs['d'] = np.log10(ranges[0])`

Specifically the "isinstance" check is not working and therefore everything (linear, hlog, tlog, etc) is falling through to the final line kwargs['d'] = np.log10(ranges[0])

In this case d will always be 'd': 5.4185399219516617

and therefore for hlog, tlog this is not an issue (except if you want to use another d), and linear and glog it is an issue since neither take d as an argument. I do not use isinstance that often unless referring to built in types so I am not familiar with how to properly use it in a custom class. Probably not the most elegant solution but perhaps a simple function in the transforms.py code which allows you to check from a list?

Let me know if you need any more info

eyurtsev commented 7 years ago

Thanks for looking into this... This commit should fix the issue:

https://github.com/eyurtsev/FlowCytometryTools/commit/44e83526e975279bfd61aca58485e95869c4f47b