Skip to content

Commit 4160a67

Browse files
committed
done tests on subset data
1 parent 7b0a160 commit 4160a67

4 files changed

Lines changed: 51 additions & 719 deletions

File tree

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ pixi run \
6161
--reference examples/muc1/data/muc1.fa \
6262
--trf examples/muc1/data/muc1.trf.bed \
6363
--mononucleotides examples/muc1/data/muc1.mononucleotides.lt6.bed \
64-
--lamassemble-mat data/lamassemble-mats/promethion.mat \
65-
--unique-regions examples/muc1/data/muc1.unique.bed
64+
--lamassemble-mat data/lamassemble-mats/promethion.mat
6665
```
6766

6867
The directory `/tmp/workdir/result` will contain a number of files. The most important one is the file `/tmp/svirltile.db` that is necessary for the subsequent (potentially joint) SV calling and creation of a VCF file.
@@ -145,7 +144,6 @@ THREADS=16
145144
TRF=$DATADIR/pbsv-annotations/human_hs37d5.trf.bed
146145
MAT=$SVIRLPOOLDIR/data/lamassemble-mats/promethion.mat
147146
MNNTS=$DATADIR/HG19/hs37d5.mononucleotides.lt6.bed.gz
148-
UNIQUER=$DATADIR/HG19/hs37d5.unique.bed.gz
149147
```
150148

151149
Now cd into a directory of your choice, where your data shall be processed, e.g.
@@ -166,7 +164,6 @@ svirlpool run \
166164
--trf $TRF \
167165
--lamassemble-mat $MAT \
168166
--mononucleotides $ MNNTS \
169-
--unique-regions UNIQUER \
170167
--threads $THREADS \
171168
--min-sv-size 30
172169
```
@@ -183,7 +180,6 @@ svirlpool run \
183180
--trf $TRF \
184181
--lamassemble-mat $MAT \
185182
--mononucleotides $ MNNTS \
186-
--unique-regions UNIQUER \
187183
--threads $THREADS \
188184
--min-sv-size 30
189185
```

src/svirlpool/localassembly/consensus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ def consensus_while_clustering(
12641264
bamout=tmp_all_vs_all_sam.name,
12651265
reads=tmp_all_reads.name,
12661266
reference=tmp_all_reads.name,
1267-
aln_args=" --sam-hit-only --secondary=yes -U 25,75 -H -r500,500",
1267+
aln_args=" --sam-hit-only --secondary=yes -U 25,75 -H",
12681268
tech="ava-ont",
12691269
threads=threads,
12701270
)

src/svirlpool/signalprocessing/alignments_to_rafs.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from tqdm import tqdm
1616

1717
from ..util import datatypes, util
18-
from . import filter_nonseparated, filter_rafs
18+
from . import filter_nonseparated
1919

2020
log = logging.getLogger(__name__)
2121

@@ -257,6 +257,53 @@ def parse_SVsignals_from_alignment(
257257
return sv_signals
258258

259259

260+
def sv_signals_densities(svSignals: list[datatypes.SVsignal], radius: int) -> list[int]:
261+
"""Returns"""
262+
if len(svSignals) == 0:
263+
return []
264+
# check if list is sorted
265+
if not all(
266+
svSignals[i].ref_start <= svSignals[i + 1].ref_start
267+
for i in range(len(svSignals) - 1)
268+
):
269+
raise ValueError("List of SVsignals is not sorted by ref_start.")
270+
271+
# build a mask. The mask keeps the density of each signal. The mask has the length of svSignals
272+
mask = [0] * len(svSignals)
273+
left: int = 0
274+
right: int = 0
275+
for mid, midSvSignal in enumerate(svSignals):
276+
# move right until right is out of radius (svSignals[right].ref_start - midSvSignal.ref_end > radius)
277+
while (
278+
right < len(svSignals)
279+
and svSignals[right].ref_start - midSvSignal.ref_end <= radius
280+
):
281+
right += 1
282+
# right is now the the first signal that is out of radius
283+
# move left until left is in radius (midSvSignal.ref_start - svSignals[left].ref_end <= radius)
284+
while left < mid and midSvSignal.ref_start - svSignals[left].ref_end > radius:
285+
left += 1
286+
# left is now the first signal that is in the radius
287+
# sum all signals sizes of the same type as midSvSignal that are in the radius
288+
mask[mid] = sum(
289+
s.size for s in svSignals[left:right] if s.sv_type == midSvSignal.sv_type
290+
)
291+
# filter all signals that have a mask value below min_signal_bp
292+
return mask
293+
294+
295+
def filter_signals_for_minimum_density(
296+
svSignals: list[datatypes.SVsignal], min_signal_bp: int, radius: int
297+
) -> list[datatypes.SVsignal]:
298+
"""filters any signal that fails to accumulate another min_signal_bp within radius. The returned list is sorted by ref_start."""
299+
densities = sv_signals_densities(
300+
svSignals=sorted(svSignals, key=lambda x: x.ref_start), radius=radius
301+
)
302+
return [
303+
svSignals[i] for i in range(len(svSignals)) if densities[i] >= min_signal_bp
304+
]
305+
306+
260307
def parse_ReadAlignmentFragment_from_alignment(
261308
alignment: pysam.AlignedSegment,
262309
samplename: str,
@@ -282,7 +329,7 @@ def parse_ReadAlignmentFragment_from_alignment(
282329
sv_signals_density_filtered = sv_signals
283330
if filter_density_radius > 0 and filter_density_min_bp > 0:
284331
sv_signals_density_filtered = sorted(
285-
filter_rafs.filter_signals_for_minimum_density(
332+
filter_signals_for_minimum_density(
286333
svSignals=sv_signals,
287334
min_signal_bp=filter_density_min_bp,
288335
radius=filter_density_radius,

0 commit comments

Comments
 (0)