Skip to content

Commit c13c3c2

Browse files
author
Chad Curtis
authored
Merge pull request #15 from ccurtis7/Chad
Chad - merged
2 parents 0121d2f + 49c5bb6 commit c13c3c2

32 files changed

Lines changed: 34382 additions & 153 deletions

CONTRIBUTING.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Contributing
2+
3+
Contributions are welcome, and they are greatly appreciated! Every little bit
4+
helps, and credit will always be given.
5+
6+
You can contribute in many ways:
7+
8+
## Types of Contributions
9+
10+
### Report Bugs
11+
12+
Report bugs at https://github.com/ccurtis7/diff_classifier/issues.
13+
14+
If you are reporting a bug, please include:
15+
16+
- Your operating system name and version.
17+
- Any details about your local setup that might be helpful in troubleshooting.
18+
- Detailed steps to reproduce the bug.
19+
20+
### Work on "good first issues"
21+
22+
Look through the GitHub issues for anything labelled "good first issue." These
23+
are issues that we think would be especially appropriate for those new to
24+
open-source software contribution.
25+
26+
### Fix Bugs
27+
28+
Look through the GitHub issues for bugs. Anything tagged with "bug" and "help
29+
wanted" is open to whoever wants to implement it.
30+
31+
### Implement Features
32+
33+
Look through the GitHub issues for features. Anything tagged with "enhancement"
34+
and "help wanted" is open to whoever wants to implement it.
35+
36+
### Write Documentation
37+
38+
Diff_classifier could always use more documentation, whether as part of the
39+
official afq-insight docs, in docstrings, or even on the web in blog posts,
40+
articles, and such.
41+
42+
### Submit Feedback
43+
44+
The best way to send feedback is to file an issue at
45+
https://github.com/ccurtis7/diff_classifier/issues.
46+
47+
If you are proposing a feature:
48+
49+
- Explain in detail how it would work.
50+
- Keep the scope as narrow as possible, to make it easier to implement.
51+
- Remember that this is a volunteer-driven project, and that contributions
52+
are welcome :)

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@ parallelization on AWS.
1919
This is the diff_classifier development site. You can view the source code and
2020
file new issues. If you are just getting started, you should look at the
2121
[diff_classifier documentation](https://ccurtis7.github.io/diff_classifier/)
22+
23+
## Contributing
24+
25+
Contributions are welcome! Diff_classifier is open source, built on open source,
26+
and we love any input, suggestions, and problems.
27+
28+
[Guidelines](CONTRIBUTING.md) for contributing are included for your convenience.
29+
30+
## Credits
31+
32+
This package was created with [shablona](https://github.com/uwescience/shablona).
33+
34+
Guidelines for contributions were based off the
35+
[CONTRIBUTIONS](https://github.com/richford/cloudknot/blob/master/CONTRIBUTING.md)
36+
file developed by [Adam Richie-Halford](https://github.com/richford).

diff_classifier/features.py

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,20 @@ def unmask_track(track):
4343
comp_y = ma.compressed(ma.masked_where(x_mask, track['Y']))
4444
comp_msd = ma.compressed(ma.masked_where(msd_mask, track['MSDs']))
4545
comp_gauss = ma.compressed(ma.masked_where(msd_mask, track['Gauss']))
46+
comp_qual = ma.compressed(ma.masked_where(x_mask, track['Quality']))
47+
comp_snr = ma.compressed(ma.masked_where(x_mask, track['SN_Ratio']))
48+
comp_meani = ma.compressed(ma.masked_where(x_mask,
49+
track['Mean_Intensity']))
4650

4751
data1 = {'Frame': comp_frame,
4852
'Track_ID': compid,
4953
'X': comp_x,
5054
'Y': comp_y,
5155
'MSDs': comp_msd,
52-
'Gauss': comp_gauss
56+
'Gauss': comp_gauss,
57+
'Quality': comp_qual,
58+
'SN_Ratio': comp_snr,
59+
'Mean_Intensity': comp_meani
5360
}
5461
comp_track = pd.DataFrame(data=data1)
5562
return comp_track
@@ -712,7 +719,7 @@ def msd_ratio(track, fram1=3, fram2=100):
712719
return ratio
713720

714721

715-
def calculate_features(dframe, framerate=1):
722+
def calculate_features(dframe, framerate=1, frame=(10, 100)):
716723
"""Calculates multiple features from input MSD dataset and stores in pandas
717724
dataframe.
718725
@@ -727,6 +734,8 @@ def calculate_features(dframe, framerate=1):
727734
Required for accurate calculation of some features. Default is 1.
728735
Possibly not required. Ignore if performing all calcuations without
729736
units.
737+
frame : int
738+
Frame at which to calculate Deff
730739
731740
Returns
732741
-------
@@ -763,7 +772,12 @@ def calculate_features(dframe, framerate=1):
763772
'MSD_ratio': holder,
764773
'frames': holder,
765774
'X': holder,
766-
'Y': holder}
775+
'Y': holder,
776+
'Quality': holder,
777+
'Mean_Intensity': holder,
778+
'SN_Ratio': holder,
779+
'Deff1': holder,
780+
'Deff2': holder}
767781

768782
datai = pd.DataFrame(data=die)
769783

@@ -799,14 +813,31 @@ def calculate_features(dframe, framerate=1):
799813
else:
800814
datai['MSD_ratio'][particle] = np.nan
801815

816+
try:
817+
datai['Deff1'][particle] = single_track['MSDs'][frame[0]] / (4*frame[0])
818+
except:
819+
datai['Deff1'][particle] = np.nan
820+
821+
try:
822+
datai['Deff2'][particle] = single_track['MSDs'][frame[1]] / (4*frame[1])
823+
except:
824+
datai['Deff2'][particle] = np.nan
825+
826+
datai['Mean_Intensity'][particle] = np.nanmean(single_track[
827+
'Mean_Intensity'].replace([np.inf, -np.inf], np.nan).dropna(how="all").values)
828+
datai['Quality'][particle] = np.nanmean(single_track[
829+
'Quality'].replace([np.inf, -np.inf], np.nan).dropna(how="all").values)
830+
datai['SN_Ratio'][particle] = np.nanmean(single_track[
831+
'SN_Ratio'].replace([np.inf, -np.inf], np.nan).dropna(how="all").values)
832+
802833
return datai
803834

804835

805836
def feature_violin(tgroups, feature='boundedness',
806837
labels=['sample 1', 'sample 2', 'sample 3'],
807-
points=40, ylim=[0, 1]):
838+
points=40, ylim=[0, 1], nticks=11):
808839
'''Plots violin plots of features in comparison groups
809-
840+
810841
Parameters
811842
----------
812843
tgroups : dict of pandas.core.frames.DataFrame
@@ -820,33 +851,33 @@ def feature_violin(tgroups, feature='boundedness',
820851
Determines resolution of violin plot
821852
ylim : list of int
822853
Y range of output plot
823-
854+
824855
'''
825856

826-
majorticks = np.linspace(0, ylim[1], 11)
857+
majorticks = np.linspace(ylim[0], ylim[1], nticks)
827858
to_graph = []
828859
pos = []
829860
counter = 1
830861
for key in tgroups:
831-
to_graph.append(tgroups[key][feature].dropna().tolist())
862+
to_graph.append(tgroups[key][feature][tgroups[key][feature] < 10000].replace([np.inf, -np.inf], np.nan).dropna().values)
832863
pos.append(counter)
833864
counter = counter + 1
834-
865+
835866
def set_axis_style(ax, labels):
836867
ax.get_xaxis().set_tick_params(direction='out')
837868
ax.xaxis.set_ticks_position('bottom')
838869
ax.set_xticks(np.arange(1, len(labels) + 1))
839870
ax.set_xticklabels(labels)
840871
ax.set_xlim(0.25, len(labels) + 0.75)
841-
872+
842873
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(6, 6))
843874

844875
axes.violinplot(to_graph, pos, points=points, widths=0.9,
845876
showmeans=True, showextrema=False)
846877
set_axis_style(axes, labels)
847-
axes.tick_params(axis = 'both', which = 'major',
848-
labelsize = 16)
878+
axes.tick_params(axis='both', which='major',
879+
labelsize=16)
849880
axes.set_ylim(ylim)
850881
axes.set_yticks(majorticks)
851-
852-
plt.show()
882+
883+
plt.show()

diff_classifier/imagej.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ def track(target, out_file, template=None, fiji_bin=None,
185185
fid.close()
186186

187187

188-
def regress_sys(folder, all_videos, yfit, training_size, frame=0,
189-
have_output=True, download=True, bucket_name='ccurtis.data'):
188+
def regress_sys(folder, all_videos, yfit, training_size, randselect=True,
189+
trainingdata=[], frame=0, have_output=True, download=True,
190+
bucket_name='ccurtis.data'):
190191
"""Uses regression based on image intensities to select tracking parameters.
191192
192193
This function uses regression methods from the scikit-learn module to
@@ -211,8 +212,14 @@ def regress_sys(folder, all_videos, yfit, training_size, frame=0,
211212
yfit: numpy.ndarray
212213
Contains manually acquired quality levels using Trackmate for the
213214
files contained in the training dataset.
214-
training_size: int
215+
training_size : int
215216
Number of files in training dataset.
217+
randselect : bool
218+
If True, will randomly select training videos from all_videos.
219+
If False, will use trainingdata as input training dataset.
220+
trainingdata : list of str
221+
Optional manually selected prefixes of video filenames to be
222+
used as training dataset.
216223
have_output: bool
217224
If you have already acquired the quality values (yfit) for the
218225
training dataset, set to True. If False, it will output the files
@@ -234,12 +241,15 @@ def regress_sys(folder, all_videos, yfit, training_size, frame=0,
234241
235242
"""
236243

237-
tprefix = []
238-
for i in range(0, training_size):
239-
random.seed(i+1)
240-
tprefix.append(all_videos[random.randint(0, len(all_videos))])
241-
if have_output is False:
242-
print("Get parameters for: {}".format(tprefix[i]))
244+
if randselect:
245+
tprefix = []
246+
for i in range(0, training_size):
247+
random.seed(i+1)
248+
tprefix.append(all_videos[random.randint(0, len(all_videos))])
249+
if have_output is False:
250+
print("Get parameters for: {}".format(tprefix[i]))
251+
else:
252+
tprefix = trainingdata
243253

244254
if have_output is True:
245255
# Define descriptors

0 commit comments

Comments
 (0)