Skip to content

Commit 35528d0

Browse files
committed
changed > to < for peak_distance
1 parent 0140959 commit 35528d0

File tree

3 files changed

+79
-9
lines changed

3 files changed

+79
-9
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ To generate peak area reports and a peak table for all input files, use the `fra
5858
- `name`: Name of the assay
5959
- `start`: Start of the assay in basepairs
6060
- `stop`: Stop of the assay in basepairs
61-
- `amount`: Can be left empty. Amount of peaks in assay. If left empty every peak in the interval is included.
62-
- `min_ratio`: Can be left empty. only peaks with the a ratio of the `min_ratio` of the highest peak is included, *e.g.* if `min_ratio == .02`, only peaks with a height of 20 is included, if the highest peak is 100 units
61+
- `amount`: Optional. Amount of peaks in assay. If left empty every peak in the interval is included.
62+
- `min_ratio`: Optional. Only peaks with the a ratio of the `min_ratio` of the highest peak is included, *e.g.* if `min_ratio == .02`, only peaks with a height of 20 is included, if the highest peak is 100 units
6363
- `which`: `LARGEST | FIRST`. Can be left empty. Which peak should be included if there are more peaks than the `amount`. if `FIRST` is set, then the two first peaks are chosen. If `LARGEST` are set, then the two largests peaks in the area are chosen. Defaults to `LARGEST`
64-
- `peak_distance`: Can be left empty. Distance between peaks must be above this value.
64+
- `peak_distance`: Optional. Distance between peaks must be under this value.
6565

6666

6767
#### Positional Arguments

fraggler/utils/peak_finder.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ def find_peaks_customized(
214214
.loc[lambda x: x.rank_peak <= assay.amount]
215215
.drop(columns=["rank_peak"])
216216
)
217-
if assay.peak_distance != "":
217+
if assay.peak_distance != 0:
218218
df = (
219219
df
220220
.assign(distance=lambda x: x.basepairs.diff())
221-
.assign(distance=lambda x: x.distance.fillna(999))
222-
.loc[lambda x: x.distance >= assay.peak_distance]
221+
.assign(distance=lambda x: x.distance.fillna(0))
222+
.loc[lambda x: x.distance <= assay.peak_distance]
223223
.drop(columns=["distance"])
224224
)
225225

@@ -232,12 +232,12 @@ def find_peaks_customized(
232232
.sort_values("basepairs", ascending=True)
233233
.head(assay.amount)
234234
)
235-
if assay.peak_distance != "":
235+
if assay.peak_distance != 0:
236236
df = (
237237
df
238238
.assign(distance=lambda x: x.basepairs.diff())
239-
.assign(distance=lambda x: x.distance.fillna(999))
240-
.loc[lambda x: x.distance >= assay.peak_distance]
239+
.assign(distance=lambda x: x.distance.fillna(0))
240+
.loc[lambda x: x.distance <= assay.peak_distance]
241241
.drop(columns=["distance"])
242242
)
243243
else:

tests/pytest/test_peak_finder.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import pandas as pd
2+
import numpy as np
3+
from fraggler.ladder_fitting.fit_ladder_model import FitLadderModel
4+
from fraggler.ladder_fitting.peak_ladder_assigner import PeakLadderAssigner
5+
from fraggler.utils.fsa_file import FsaFile
6+
7+
from fraggler.utils.peak_finder import is_overlapping, has_columns, PeakFinder
8+
9+
10+
def test_is_overlapping_no_overlap():
11+
df = pd.DataFrame({"start": [1, 4, 8], "stop": [3, 6, 10]})
12+
assert not is_overlapping(df)
13+
14+
15+
def test_is_overlapping_do_overlap():
16+
df = pd.DataFrame({"start": [1, 4, 5], "stop": [3, 6, 10]})
17+
assert is_overlapping(df)
18+
19+
20+
def test_has_columns_correct():
21+
df = pd.DataFrame(
22+
{
23+
"name": [],
24+
"start": [],
25+
"stop": [],
26+
"amount": [],
27+
"min_ratio": [],
28+
"which": [],
29+
"peak_distance": []
30+
}
31+
)
32+
assert has_columns(df) == True
33+
34+
35+
def test_has_columns_missing_one():
36+
df = pd.DataFrame(
37+
{"name": [], "start": [], "stop": [], "amount": [], "min_ratio": []}
38+
)
39+
assert has_columns(df) == False
40+
41+
42+
def test_has_columns_extra_one():
43+
df = pd.DataFrame(
44+
{
45+
"name": [],
46+
"start": [],
47+
"stop": [],
48+
"amount": [],
49+
"min_ratio": [],
50+
"which": [],
51+
"extra": [],
52+
}
53+
)
54+
assert has_columns(df) == False
55+
56+
57+
##### Peak finder testing
58+
fsa_multiplex = FsaFile(
59+
file="../../demo/multiplex.fsa",
60+
ladder="LIZ",
61+
)
62+
63+
ladder_assigner_multiplex = PeakLadderAssigner(fsa_multiplex)
64+
model_multiplex = FitLadderModel(ladder_assigner_multiplex)
65+
pf_multiplex = PeakFinder(model_multiplex)
66+
67+
68+
def test_peak_finder():
69+
global pf_multiplex
70+
pass

0 commit comments

Comments
 (0)