align_trim 1.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
align_trim/__init__.py ADDED
File without changes
align_trim/main.py ADDED
@@ -0,0 +1,1179 @@
1
+ from copy import copy
2
+ import csv
3
+ import pysam
4
+ import sys
5
+ import numpy as np
6
+ import random
7
+ import argparse
8
+ from collections import defaultdict
9
+ from typing import Optional
10
+ from pathlib import Path
11
+ import itertools
12
+ from typing import Union
13
+
14
+ from importlib.metadata import version
15
+
16
+ from primalbedtools.scheme import Scheme
17
+ from primalbedtools.bedfiles import BedLine, merge_primers
18
+ from primalbedtools.amplicons import Amplicon, create_amplicons
19
+
20
+ RANDOM_SEED = 42
21
+
22
+
23
+ # consumesReference lookup for if a CIGAR operation consumes the reference sequence
24
+ consumesReference = [True, False, True, True, False, False, False, True]
25
+
26
+ # consumesQuery lookup for if a CIGAR operation consumes the query sequence
27
+ consumesQuery = [True, True, False, False, True, False, False, True]
28
+
29
+
30
+ def find_primer_with_lookup(lookup, pos, direction, chrom) -> Optional[BedLine]:
31
+ pos_amps = lookup[chrom][:, pos] # Search both pools for amplicons at this position
32
+ closest_dist = float("inf")
33
+ closest_p = None
34
+ if direction == "+":
35
+ # Loops over pool O(N)
36
+ for amp in pos_amps:
37
+ if amp is None:
38
+ continue
39
+ dist = abs(amp.coverage_start - pos)
40
+ if dist < closest_dist:
41
+ closest_p = amp.left[0]
42
+ closest_dist = dist
43
+ elif direction == "-":
44
+ for amp in pos_amps:
45
+ if amp is None:
46
+ continue
47
+ dist = abs(amp.coverage_end - pos)
48
+ if dist < closest_dist:
49
+ closest_p = amp.right[0]
50
+ closest_dist = dist
51
+ else:
52
+ pass
53
+ return closest_p
54
+
55
+
56
+ def find_primer(primers: list[BedLine], pos, direction, chrom, threshold=35):
57
+ """Given a reference position and a direction of travel, walk out and find the nearest primer site.
58
+
59
+ Parameters
60
+ ----------
61
+ bed : list
62
+ A list of dictionaries, where each dictionary contains a row of bedfile data
63
+ pos : int
64
+ The position in the reference sequence to start from
65
+ direction : string
66
+ The direction to search along the reference sequence
67
+
68
+ Returns
69
+ -------
70
+ tuple[int, int, dict] | bool
71
+ A tuple containing the distance to the primer, the relative position of the primer, and the primer site, or False if no primer found
72
+ """
73
+ from operator import itemgetter
74
+
75
+ if direction == "+":
76
+ primer_distances = [
77
+ (abs(bl.start - pos), bl.start - pos, bl)
78
+ for bl in primers
79
+ if (pos >= (bl.start - threshold)) and chrom == bl.chrom
80
+ ]
81
+
82
+ else:
83
+ primer_distances = [
84
+ (abs(bl.end - pos), bl.end - pos, bl)
85
+ for bl in primers
86
+ if (pos <= (bl.end + threshold)) and chrom == bl.chrom
87
+ ]
88
+
89
+ if not primer_distances:
90
+ return False
91
+
92
+ closest = min(
93
+ primer_distances,
94
+ key=itemgetter(0),
95
+ )
96
+
97
+ return closest
98
+
99
+
100
+ def trim(segment, primer_pos, end, verbose=False):
101
+ """Soft mask an alignment to fit within primer start/end sites.
102
+
103
+ Parameters
104
+ ----------
105
+ segment : pysam.AlignedSegment
106
+ The aligned segment to mask
107
+ primer_pos : int
108
+ The position in the reference to soft mask up to (equates to the start/end position of the primer in the reference)
109
+ end : bool
110
+ If True, the segment is being masked from the end (i.e. for the reverse primer)
111
+ verbose : bool
112
+ If True, will print soft masking info during trimming
113
+ """
114
+ if verbose:
115
+ print(
116
+ f"{segment.query_name}: Trimming {'end' if end else 'start'} of read to primer position {primer_pos}",
117
+ file=sys.stderr,
118
+ )
119
+ # get a copy of the cigar tuples to work with
120
+ cigar = copy(segment.cigartuples)
121
+
122
+ # get the segment position in the reference (depends on if start or end of the segment is being processed)
123
+ if not end:
124
+ pos = segment.pos
125
+ else:
126
+ pos = segment.reference_end
127
+
128
+ # process the CIGAR to determine how much softmasking is required
129
+ eaten = 0
130
+ while 1:
131
+ # chomp CIGAR operations from the start/end of the CIGAR
132
+ try:
133
+ if end:
134
+ flag, length = cigar.pop()
135
+ else:
136
+ flag, length = cigar.pop(0)
137
+ if verbose:
138
+ print(
139
+ f"{segment.query_name}: Chomped a {flag}, {length}",
140
+ file=sys.stderr,
141
+ )
142
+ except IndexError:
143
+ if verbose:
144
+ print(
145
+ f"{segment.query_name}: Ran out of cigar during soft masking - completely masked read will be ignored",
146
+ file=sys.stderr,
147
+ )
148
+ break
149
+
150
+ # if the CIGAR operation consumes the reference sequence, increment/decrement the position by the CIGAR operation length
151
+ if consumesReference[flag]:
152
+ if not end:
153
+ pos += length
154
+ else:
155
+ pos -= length
156
+
157
+ # if the CIGAR operation consumes the query sequence, increment the number of CIGAR operations eaten by the CIGAR operation length
158
+ if consumesQuery[flag]:
159
+ eaten += length
160
+
161
+ # stop processing the CIGAR if we've gone far enough to mask the primer
162
+ if not end and pos >= primer_pos and flag == 0:
163
+ break
164
+ if end and pos <= primer_pos and flag == 0:
165
+ break
166
+
167
+ # calculate how many extra matches are needed in the CIGAR
168
+ extra = abs(pos - primer_pos)
169
+ if verbose:
170
+ print(f"{segment.query_name}: extra {extra}", file=sys.stderr)
171
+ if extra:
172
+ if verbose:
173
+ print(
174
+ f"{segment.query_name}: Inserted a 0, {extra}",
175
+ file=sys.stderr,
176
+ )
177
+ if end:
178
+ cigar.append((0, extra))
179
+ else:
180
+ cigar.insert(0, (0, extra))
181
+ eaten -= extra
182
+
183
+ # softmask the left primer
184
+ if not end:
185
+ # update the position of the leftmost mapping base
186
+ segment.pos = pos - extra
187
+ if verbose:
188
+ print(
189
+ f"{segment.query_name}: New pos - {segment.pos}",
190
+ file=sys.stderr,
191
+ )
192
+
193
+ # if proposed softmask leads straight into a deletion, shuffle leftmost mapping base along and ignore the deletion
194
+ if cigar[0][0] == 2:
195
+ if verbose:
196
+ print(
197
+ f"{segment.query_name}: softmask created a leading deletion in the CIGAR, shuffling the alignment",
198
+ file=sys.stderr,
199
+ )
200
+ while 1:
201
+ if cigar[0][0] != 2:
202
+ break
203
+ _, length = cigar.pop(0)
204
+ segment.pos += length
205
+
206
+ # now add the leading softmask
207
+ cigar.insert(0, (4, eaten))
208
+
209
+ # softmask the right primer
210
+ else:
211
+ cigar.append((4, eaten))
212
+
213
+ # check the new CIGAR and replace the old one
214
+ if cigar[0][1] <= 0 or cigar[-1][1] <= 0:
215
+ if verbose:
216
+ print(
217
+ f"{segment.query_name}: invalid cigar operation created - possibly due to INDEL in primer",
218
+ file=sys.stderr,
219
+ )
220
+ return
221
+
222
+ segment.cigartuples = cigar
223
+ return
224
+
225
+
226
+ def handle_segments(
227
+ segment: Union[
228
+ pysam.AlignedSegment, tuple[pysam.AlignedSegment, pysam.AlignedSegment]
229
+ ],
230
+ lookup: dict,
231
+ args: argparse.Namespace,
232
+ min_mapq: int,
233
+ outfile_writer: pysam.AlignmentFile,
234
+ amp_depths: dict,
235
+ report_writer: csv.DictWriter = False, # type: ignore
236
+ ):
237
+ """Handle the alignment segment(s) including filtering, soft masking, and reporting.
238
+
239
+ Args:
240
+ segment (pysam.AlignedSegment | tuple): The alignment segment to process, can be a single segment or a tuple of paired segments
241
+ bed (dict): The primer scheme
242
+ reportfh (typing.IO): The report file handle
243
+ args (argparse.Namespace): The command line arguments
244
+
245
+ Returns:
246
+ tuple [int, pysam.AlignedSegment | bool] | bool: A tuple containing the amplicon number and the alignment segment, or False if the segment is to be skipped
247
+ """
248
+ paired = isinstance(segment, tuple)
249
+ if paired:
250
+ segment1, segment2 = segment
251
+ if not segment1 or not segment2:
252
+ segment = segment1 if segment1 else segment2
253
+ if args.verbose:
254
+ print(
255
+ f"{segment.query_name}: Pair skipped as at least one segment in pair does not exist",
256
+ file=sys.stderr,
257
+ )
258
+ return False
259
+
260
+ # filter out unmapped and supplementary alignment segments
261
+ if not paired:
262
+ if segment.is_unmapped:
263
+ if args.verbose:
264
+ print(
265
+ f"{segment.query_name}: skipped as unmapped",
266
+ file=sys.stderr,
267
+ )
268
+ return False
269
+ else:
270
+ if segment1.is_unmapped or segment2.is_unmapped:
271
+ if args.verbose:
272
+ print(
273
+ f"{segment1.query_name}: skipped as unmapped",
274
+ file=sys.stderr,
275
+ )
276
+ return False
277
+
278
+ if not paired:
279
+ if segment.is_supplementary:
280
+ if args.verbose:
281
+ print(
282
+ f"{segment.query_name}: skipped as supplementary",
283
+ file=sys.stderr,
284
+ )
285
+ return False
286
+ else:
287
+ if segment1.is_supplementary or segment2.is_supplementary:
288
+ if args.verbose:
289
+ print(
290
+ f"{segment1.query_name}: skipped as supplementary",
291
+ file=sys.stderr,
292
+ )
293
+ return False
294
+
295
+ if not paired:
296
+ if segment.mapping_quality < min_mapq:
297
+ if args.verbose:
298
+ print(
299
+ f"{segment.query_name}: skipped as mapping quality below threshold",
300
+ file=sys.stderr,
301
+ )
302
+ return False
303
+ else:
304
+ if segment1.mapping_quality < min_mapq or segment2.mapping_quality < min_mapq:
305
+ if args.verbose:
306
+ print(
307
+ f"{segment1.query_name}: skipped as mapping quality below threshold",
308
+ file=sys.stderr,
309
+ )
310
+ return False
311
+
312
+ if not paired:
313
+ if segment.reference_end is None:
314
+ if args.verbose:
315
+ print(
316
+ f"{segment.query_name}: skipped as no mapping data",
317
+ file=sys.stderr,
318
+ )
319
+ return False
320
+ else:
321
+ if segment1.reference_end is None or segment2.reference_end is None:
322
+ if args.verbose:
323
+ print(
324
+ f"{segment1.query_name}: skipped as no mapping data",
325
+ file=sys.stderr,
326
+ )
327
+ return False
328
+ if not paired:
329
+ # locate the nearest primers to this alignment segment
330
+ p1 = find_primer_with_lookup(
331
+ lookup=lookup,
332
+ pos=segment.reference_start,
333
+ direction="+",
334
+ chrom=segment.reference_name,
335
+ )
336
+
337
+ p2 = find_primer_with_lookup(
338
+ lookup=lookup,
339
+ pos=segment.reference_end,
340
+ direction="-",
341
+ chrom=segment.reference_name,
342
+ )
343
+ else:
344
+ # locate the nearest primers to this alignment segment pair
345
+ if segment1.reference_start < segment2.reference_start:
346
+ # if segment1 starts before segment2, then segment1 is the left segment relative to the reference
347
+ p1 = find_primer_with_lookup(
348
+ lookup=lookup,
349
+ pos=segment1.reference_start,
350
+ direction="+",
351
+ chrom=segment1.reference_name,
352
+ )
353
+ p2 = find_primer_with_lookup(
354
+ lookup=lookup,
355
+ pos=segment2.reference_end,
356
+ direction="-",
357
+ chrom=segment2.reference_name,
358
+ )
359
+ else:
360
+ # otherwise then segment2 is the left segment relative to the reference
361
+ p1 = find_primer_with_lookup(
362
+ lookup=lookup,
363
+ pos=segment2.reference_start,
364
+ direction="+",
365
+ chrom=segment2.reference_name,
366
+ )
367
+ p2 = find_primer_with_lookup(
368
+ lookup=lookup,
369
+ pos=segment1.reference_end,
370
+ direction="-",
371
+ chrom=segment1.reference_name,
372
+ )
373
+
374
+ if not p1 or not p2:
375
+ if paired:
376
+ segment = segment1 if segment1 else segment2
377
+ if args.verbose:
378
+ print(
379
+ f"{segment.query_name}: skipped as no primer found for segment",
380
+ file=sys.stderr,
381
+ )
382
+ return False
383
+
384
+ # check if primers are correctly paired and then assign read group
385
+ correctly_paired = p1.amplicon_number == p2.amplicon_number
386
+
387
+ if not paired:
388
+ if not args.no_read_groups:
389
+ if correctly_paired:
390
+ segment.set_tag("RG", str(p1.pool))
391
+ else:
392
+ segment.set_tag("RG", "unmatched")
393
+ else:
394
+ if not args.no_read_groups:
395
+ if correctly_paired:
396
+ segment1.set_tag("RG", str(p1.pool))
397
+ segment2.set_tag("RG", str(p2.pool))
398
+ else:
399
+ segment1.set_tag("RG", "unmatched")
400
+ segment2.set_tag("RG", "unmatched")
401
+
402
+ # get the amplicon number
403
+ amplicon = p1.amplicon_number
404
+
405
+ if args.report:
406
+ # update the report with this alignment segment + primer details
407
+ report_segment = segment if not paired else segment1
408
+ report = {
409
+ "chrom": report_segment.reference_name,
410
+ "QueryName": report_segment.query_name,
411
+ "ReferenceStart": report_segment.reference_start,
412
+ "ReferenceEnd": report_segment.reference_end,
413
+ "PrimerPair": f"{p1.primername}_{p2.primername}",
414
+ "Primer1": p1.primername,
415
+ "Primer1Start": p1.start,
416
+ "Primer2": p2.primername,
417
+ "Primer2Start": p2.start,
418
+ "IsSecondary": report_segment.is_secondary,
419
+ "IsSupplementary": report_segment.is_supplementary,
420
+ "Start": p1.start,
421
+ "End": p2.end,
422
+ "CorrectlyPaired": correctly_paired,
423
+ }
424
+ report_writer.writerow(report)
425
+
426
+ if not args.allow_incorrect_pairs and not correctly_paired:
427
+ segment = segment if not paired else segment1
428
+ if args.verbose:
429
+ print(
430
+ f"{segment.query_name}: skipped as not correctly paired",
431
+ file=sys.stderr,
432
+ )
433
+ return False
434
+
435
+ # get the primer positions
436
+ if not args.no_trim_primers:
437
+ p1_position = p1.end
438
+ p2_position = p2.start
439
+ else:
440
+ p1_position = p1.start
441
+ p2_position = p2.end
442
+
443
+ # softmask the alignment if left primer start/end inside alignment
444
+ if not paired:
445
+ if segment.reference_start < p1_position:
446
+ try:
447
+ trim(segment, p1_position, False, args.verbose)
448
+ if args.verbose:
449
+ print(
450
+ f"{segment.query_name}: ref start {segment.reference_start} >= primer_position {p1_position}",
451
+ file=sys.stderr,
452
+ )
453
+ except Exception as e:
454
+ print(
455
+ f"{segment.query_name}: problem soft masking left primer (error: {e}), skipping",
456
+ file=sys.stderr,
457
+ )
458
+ return False
459
+
460
+ # softmask the alignment if right primer start/end inside alignment
461
+ if segment.reference_end > p2_position:
462
+ try:
463
+ trim(segment, p2_position, True, args.verbose)
464
+ if args.verbose:
465
+ print(
466
+ f"{segment.query_name}: ref start {segment.reference_start} >= primer_position {p2_position}",
467
+ file=sys.stderr,
468
+ )
469
+ except Exception as e:
470
+ print(
471
+ f"{segment.query_name}: problem soft masking right primer (error: {e}), skipping",
472
+ file=sys.stderr,
473
+ )
474
+ return False
475
+
476
+ # check the the alignment still contains bases matching the reference
477
+ if "M" not in segment.cigarstring: # type: ignore
478
+ if args.verbose:
479
+ print(
480
+ f"{segment.query_name}: dropped as does not match reference post masking",
481
+ file=sys.stderr,
482
+ )
483
+ return False
484
+
485
+ # Check require-full-length
486
+ if args.require_full_length:
487
+ if segment.reference_start > p1.end or segment.reference_end < p2.start:
488
+ if args.verbose:
489
+ print(
490
+ f"{segment.query_name}: ref_start {segment.reference_start} > p1.end {p1.end} or ref_end {segment.reference_end} < p2.start {p2.start}, does not span a full amplicon, skipping",
491
+ file=sys.stderr,
492
+ )
493
+ return False
494
+
495
+ # If not normalising, write the segment to the output file and add it to amplicon depth numpy array
496
+ if not args.normalise:
497
+ outfile_writer.write(segment)
498
+ segment_amp_relative_start = segment.reference_start - p1.start
499
+ segment_amp_relative_end = segment.reference_end - p1.start
500
+ if segment_amp_relative_start < 0:
501
+ segment_amp_relative_start = 0
502
+
503
+ amp_depths[segment.reference_name][amplicon][
504
+ segment_amp_relative_start:segment_amp_relative_end
505
+ ] += 1
506
+
507
+ return (amplicon, False)
508
+
509
+ return (amplicon, segment)
510
+
511
+ else:
512
+ for segment_of_pair in (segment1, segment2):
513
+ if segment_of_pair.reference_start < p1_position:
514
+ try:
515
+ trim(
516
+ segment=segment_of_pair,
517
+ primer_pos=p1_position,
518
+ end=False,
519
+ verbose=args.verbose,
520
+ )
521
+ if args.verbose:
522
+ print(
523
+ f"{segment_of_pair.query_name}: ref start {segment_of_pair.reference_start} >= primer_position {p1_position}",
524
+ file=sys.stderr,
525
+ )
526
+ except Exception as e:
527
+ print(
528
+ f"{segment_of_pair.query_name}: Problem soft masking left primer (error: {e}), skipping",
529
+ file=sys.stderr,
530
+ )
531
+ return False
532
+
533
+ if segment_of_pair.reference_end > p2_position: # type: ignore
534
+ try:
535
+ trim(
536
+ segment=segment_of_pair,
537
+ primer_pos=p2_position,
538
+ end=True,
539
+ verbose=args.verbose,
540
+ )
541
+ if args.verbose:
542
+ print(
543
+ f"{segment_of_pair.query_name}: ref_end {segment_of_pair.reference_end} >= primer_position {p2_position}",
544
+ file=sys.stderr,
545
+ )
546
+ except Exception as e:
547
+ print(
548
+ f"{segment_of_pair.query_name}: Problem soft masking right primer (error: {e}), skipping",
549
+ file=sys.stderr,
550
+ )
551
+ return False
552
+
553
+ # check the the alignment still contains bases matching the reference
554
+ if "M" not in segment1.cigarstring or "M" not in segment2.cigarstring: # type: ignore
555
+ if args.verbose:
556
+ print(
557
+ f"{segment1.query_name}: Paired segment dropped as does not match reference post masking",
558
+ file=sys.stderr,
559
+ )
560
+ return False
561
+
562
+ if args.require_full_length:
563
+ if segment1.reference_start < segment2.reference_start:
564
+ if (
565
+ segment1.reference_start > p1.end
566
+ or segment2.reference_end < p2.start
567
+ ):
568
+ if args.verbose:
569
+ print(
570
+ f"{segment1.query_name}: ref_start {segment1.reference_start} > p1.end {p1.end} or ref_end {segment2.reference_end} < p2.start {p2.start}, does not span a full amplicon, skipping",
571
+ file=sys.stderr,
572
+ )
573
+ return False
574
+ else:
575
+ if (
576
+ segment2.reference_start > p1.end
577
+ or segment1.reference_end < p2.start
578
+ ):
579
+ if args.verbose:
580
+ print(
581
+ f"{segment1.query_name}: ref_end {segment1.reference_end} < p2.start {p2.start} or ref_start {segment2.reference_start} > p1.end {p1.end}, does not span a full amplicon, skipping",
582
+ file=sys.stderr,
583
+ )
584
+ return False
585
+
586
+ # If not normalising, write the segments to the output file and add them to amplicon depth numpy array
587
+ if not args.normalise:
588
+ outfile_writer.write(segment1)
589
+ outfile_writer.write(segment2)
590
+ for segment_in_pair in (segment1, segment2):
591
+ segment_amp_relative_start = segment_in_pair.reference_start - p1.start
592
+ segment_amp_relative_end = segment_in_pair.reference_end - p1.start
593
+ if segment_amp_relative_start < 0:
594
+ segment_amp_relative_start = 0
595
+ amp_depths[segment1.reference_name][amplicon][
596
+ segment_amp_relative_start:segment_amp_relative_end
597
+ ] += 1
598
+
599
+ return (amplicon, False)
600
+
601
+ return (amplicon, segment)
602
+
603
+
604
+ def normalise(
605
+ trimmed_segments: dict,
606
+ normalise: int,
607
+ primers: list[BedLine],
608
+ outfile: pysam.AlignmentFile,
609
+ verbose: bool = False,
610
+ ):
611
+ """Normalise the depth of the trimmed segments to a given value. Perform per-amplicon normalisation using numpy vector maths to determine whether the segment in question would take the depth closer to the desired depth across the amplicon.
612
+
613
+ Args:
614
+ trimmed_segments (dict): Dict containing amplicon number as key and list of pysam.AlignedSegment as value, if paired segments are used, the value will be a list of tuples containing the two segments.
615
+ normalise (int): Desired normalised depth
616
+ bed (list): Primer scheme as a list of BedLine objects
617
+ outfile (pysam.AlignmentFile): Output file handle to write the normalised segments to
618
+ verbose (bool): If True, will print normalisation info during processing
619
+
620
+ Raises:
621
+ ValueError: Amplicon assigned to segment not found in primer scheme file
622
+
623
+ Returns:
624
+ dict: A dictionary containing the mean depth for each amplicon post normalisation
625
+ """
626
+ amplicons = {}
627
+
628
+ for amplicon in create_amplicons(primers):
629
+ amplicons.setdefault(amplicon.chrom, {})
630
+ amplicons[amplicon.chrom].setdefault(
631
+ amplicon.amplicon_number,
632
+ {
633
+ "length": amplicon.amplicon_end - amplicon.amplicon_start,
634
+ "p_start": amplicon.amplicon_start,
635
+ },
636
+ )
637
+
638
+ # mean_depths = {x: {} for x in amplicons}
639
+ mean_depths = {}
640
+ for chrom in amplicons:
641
+ for amplicon in amplicons[chrom]:
642
+ mean_depths[(chrom, amplicon)] = 0
643
+
644
+ for chrom, amplicon_dict in trimmed_segments.items():
645
+ for amplicon, segments in amplicon_dict.items():
646
+ if amplicon not in amplicons[chrom]:
647
+ raise ValueError(f"Amplicon {amplicon} not found in primer scheme file")
648
+
649
+ desired_depth = np.full_like(
650
+ (amplicons[chrom][amplicon]["length"],), normalise, dtype=int
651
+ )
652
+
653
+ amplicon_depth = np.zeros(
654
+ (amplicons[chrom][amplicon]["length"],), dtype=int
655
+ )
656
+
657
+ if not segments:
658
+ if verbose:
659
+ print(
660
+ f"No segments assigned to amplicon {amplicon}, skipping",
661
+ file=sys.stderr,
662
+ )
663
+ continue
664
+
665
+ random.Random(RANDOM_SEED).shuffle(segments)
666
+
667
+ distance = np.mean(np.abs(amplicon_depth - desired_depth))
668
+
669
+ for segment in segments:
670
+ paired = isinstance(segment, tuple)
671
+
672
+ if paired:
673
+ test_depths = np.copy(amplicon_depth)
674
+ segment1, segment2 = segment
675
+ for segment in (segment1, segment2):
676
+ relative_start = (
677
+ segment.reference_start
678
+ - amplicons[chrom][amplicon]["p_start"]
679
+ )
680
+
681
+ if relative_start < 0:
682
+ relative_start = 0
683
+
684
+ relative_end = (
685
+ segment.reference_end
686
+ - amplicons[chrom][amplicon]["p_start"]
687
+ )
688
+
689
+ test_depths[relative_start:relative_end] += 1
690
+
691
+ test_distance = np.mean(np.abs(test_depths - desired_depth))
692
+
693
+ if test_distance < distance:
694
+ amplicon_depth = test_depths
695
+ distance = test_distance
696
+ # write the segments to the output file
697
+ outfile.write(segment1)
698
+ outfile.write(segment2)
699
+ else:
700
+ test_depths = np.copy(amplicon_depth)
701
+
702
+ relative_start = (
703
+ segment.reference_start - amplicons[chrom][amplicon]["p_start"]
704
+ )
705
+
706
+ if relative_start < 0:
707
+ relative_start = 0
708
+
709
+ relative_end = (
710
+ segment.reference_end - amplicons[chrom][amplicon]["p_start"]
711
+ )
712
+
713
+ test_depths[relative_start:relative_end] += 1
714
+
715
+ test_distance = np.mean(np.abs(test_depths - desired_depth))
716
+
717
+ if test_distance < distance:
718
+ amplicon_depth = test_depths
719
+ distance = test_distance
720
+ outfile.write(segment)
721
+
722
+ mean_depths[(chrom, amplicon)] = np.mean(amplicon_depth)
723
+
724
+ return mean_depths
725
+
726
+
727
+ def read_pair_generator(bam, region_string=None):
728
+ """
729
+ Generate read pairs in a BAM file or within a region string.
730
+ Reads are added to read_dict until a pair is found.
731
+ """
732
+ read_dict = defaultdict(lambda: [None, None])
733
+ for read in bam:
734
+ if not read.is_proper_pair:
735
+ continue
736
+ qname = read.query_name
737
+ if qname not in read_dict:
738
+ if read.is_read1:
739
+ read_dict[qname][0] = read
740
+ else:
741
+ read_dict[qname][1] = read
742
+ else:
743
+ if read.is_read1:
744
+ yield read, read_dict[qname][1]
745
+ else:
746
+ yield read_dict[qname][0], read
747
+ del read_dict[qname]
748
+
749
+
750
+ def create_primer_lookup(ref_len_tuple, amplicons: list[Amplicon], padding=35):
751
+ """
752
+ Create a lookup table for efficient primer position queries across reference genomes.
753
+
754
+ Each chromosome gets its own 2D lookup array where:
755
+ - Rows represent non-overlapping "pools"* of amplicons at their corresponding positions.
756
+ - Columns represent genomic positions
757
+ - Values are Amplicon objects or None
758
+
759
+ The function automatically determines the minimum number of rows needed to ensure
760
+ no amplicons overlap within the same row when accounting for padding.
761
+
762
+ * Amplicons are placed in the first available row where they don't overlap, not their pool index.
763
+
764
+ Parameters
765
+ ----------
766
+ ref_len_tuple : list[tuple[str, int]]
767
+ List of tuples containing (chromosome_name, chromosome_length) pairs
768
+ from the reference genome
769
+ amplicons : list[Amplicon]
770
+ List of Amplicon objects containing primer scheme information
771
+ padding : int, optional
772
+ Number of bases to extend amplicon boundaries on both sides to allow
773
+ for fuzzy matching of reads with barcodes/adapters (default: 35)
774
+
775
+ Returns
776
+ -------
777
+ dict[str, np.ndarray]
778
+ Dictionary mapping chromosome names to 2D numpy arrays of shape (N, chrom_len+1)
779
+ where N is the minimum number of rows needed to prevent amplicon overlap.
780
+ Array elements are either Amplicon objects or None.
781
+
782
+
783
+ """
784
+ lookups = {}
785
+ for chrom, chromlen in ref_len_tuple:
786
+ lookup_array = np.empty_like(None, shape=(1, chromlen + 1))
787
+ for amp in amplicons:
788
+ added = False
789
+ if amp.chrom == chrom:
790
+ # If amplicon clashes with any in same pool add new row
791
+ amp_slice = lookup_array[
792
+ :,
793
+ max(amp.amplicon_start - padding, 0) : min(
794
+ amp.amplicon_end + padding, chromlen
795
+ ),
796
+ ]
797
+ for i, row in enumerate(amp_slice): # Check each row for collision
798
+ if row[row != None].size == 0:
799
+ lookup_array[
800
+ i,
801
+ max(amp.amplicon_start - padding, 0) : min(
802
+ amp.amplicon_end + padding, chromlen
803
+ ),
804
+ ] = amp
805
+ added = True
806
+ # If not added, create new row, add the amplicon to that then add back to original array
807
+ if not added:
808
+ new_row = np.empty_like(None, shape=(1, chromlen + 1))
809
+ new_row[
810
+ 0,
811
+ max(amp.amplicon_start - padding, 0) : min(
812
+ amp.amplicon_end + padding, chromlen
813
+ ),
814
+ ] = amp
815
+ lookup_array = np.vstack((lookup_array, new_row))
816
+
817
+ lookups[chrom] = lookup_array
818
+ return lookups
819
+
820
+
821
+ def go(args):
822
+ """Filter and soft mask an alignment file so that the alignment boundaries match the primer start and end sites.
823
+
824
+ Based on the most likely primer position, based on the alignment coordinates.
825
+ """
826
+ # prepare the report outfile
827
+ if args.report:
828
+ reportfh = open(args.report, "w")
829
+ report_headers = [
830
+ "chrom",
831
+ "QueryName",
832
+ "ReferenceStart",
833
+ "ReferenceEnd",
834
+ "PrimerPair",
835
+ "Primer1",
836
+ "Primer1Start",
837
+ "Primer2",
838
+ "Primer2Start",
839
+ "IsSecondary",
840
+ "IsSupplementary",
841
+ "Start",
842
+ "End",
843
+ "CorrectlyPaired",
844
+ ]
845
+ report_writer = csv.DictWriter(
846
+ reportfh, fieldnames=report_headers, delimiter="\t"
847
+ )
848
+ report_writer.writeheader()
849
+
850
+ # open the primer scheme and get the pools
851
+ scheme = Scheme.from_file(args.bedfile)
852
+
853
+ # Merge the primers
854
+ scheme.bedlines = merge_primers(scheme.bedlines)
855
+
856
+ amplicon_list = create_amplicons(scheme.bedlines)
857
+ amplicons = {}
858
+ for amplicon in amplicon_list:
859
+ amplicon.length = amplicon.amplicon_end - amplicon.amplicon_start
860
+ amplicons.setdefault(amplicon.chrom, {})[amplicon.amplicon_number] = amplicon
861
+
862
+ pools = set([bl.pool for bl in scheme.bedlines])
863
+ chroms = set([bl.chrom for bl in scheme.bedlines])
864
+
865
+ pools_str = {str(x) for x in pools}
866
+ pools_str.add("unmatched")
867
+
868
+ # open the input samfile and process read groups
869
+ if args.samfile and args.samfile != "-":
870
+ infile = pysam.AlignmentFile(args.samfile, "rb")
871
+ else:
872
+ infile = pysam.AlignmentFile("-", "rb")
873
+
874
+ first_segment = next(infile, None)
875
+ if not first_segment:
876
+ print("No segments found in the input file, exiting.", file=sys.stderr)
877
+ sys.exit(1)
878
+
879
+ # check if the first segment is paired, then chain the saved first segment with the infile iterator so nothing is lost
880
+ paired = first_segment.is_paired
881
+ chained_iterator = itertools.chain([first_segment], infile)
882
+
883
+ bam_header = infile.header.copy().to_dict()
884
+ if not args.no_read_groups:
885
+ bam_header["RG"] = []
886
+ for pool in sorted(pools_str): # set order can be non deterministic
887
+ read_group = {}
888
+ read_group["ID"] = pool
889
+ bam_header["RG"].append(read_group)
890
+
891
+ cli_cmd = " ".join(sys.argv)
892
+ bam_header["PG"].append(
893
+ {
894
+ "PN": "align_trim",
895
+ "ID": "align_trim",
896
+ "VN": version("align_trim"),
897
+ "CL": cli_cmd,
898
+ }
899
+ )
900
+
901
+ # prepare the alignment outfile
902
+ if args.output and args.output != "-":
903
+ if args.output.name.endswith(".bam"):
904
+ outfile = pysam.AlignmentFile(args.output, "wb", header=bam_header)
905
+ elif args.output.name.endswith(".sam"):
906
+ outfile = pysam.AlignmentFile(args.output, "wh", header=bam_header)
907
+ else:
908
+ print(
909
+ "Output file path must end with either .bam or .sam, exiting.",
910
+ file=sys.stderr,
911
+ )
912
+ sys.exit(1)
913
+
914
+ else:
915
+ outfile = pysam.AlignmentFile("-", "wh", header=bam_header)
916
+
917
+ # Initialise the amplicon depth dict
918
+ amp_depths = {}
919
+ for amp in amplicon_list:
920
+ amp_depths.setdefault(amp.chrom, {})
921
+ amp_depths[amp.chrom].setdefault(
922
+ amp.amplicon_number, np.zeros(amp.length, dtype=int)
923
+ )
924
+
925
+ # Initialise the mean depths dictionary, this will get stomped over if normalisation is requested
926
+ mean_amp_depths = {}
927
+ for chrom in amplicons:
928
+ for amplicon in amplicons[chrom]:
929
+ mean_amp_depths[(chrom, amplicon)] = 0
930
+
931
+ # Create a lookup table for primer location
932
+ ref_lengths = [(r, infile.get_reference_length(r)) for r in infile.references]
933
+ primer_lookup = create_primer_lookup(
934
+ ref_len_tuple=ref_lengths,
935
+ amplicons=amplicon_list,
936
+ padding=args.primer_match_threshold,
937
+ )
938
+
939
+ trimmed_segments = {x: {} for x in chroms}
940
+
941
+ if paired:
942
+ read_pairs = read_pair_generator(chained_iterator)
943
+
944
+ for segments in read_pairs:
945
+ if args.report:
946
+ trimming_tuple = handle_segments(
947
+ segment=segments, # type: ignore
948
+ lookup=primer_lookup,
949
+ args=args,
950
+ report_writer=report_writer, # type: ignore
951
+ min_mapq=args.min_mapq,
952
+ outfile_writer=outfile,
953
+ amp_depths=amp_depths,
954
+ )
955
+ else:
956
+ trimming_tuple = handle_segments(
957
+ segment=segments, # type: ignore
958
+ lookup=primer_lookup,
959
+ args=args,
960
+ min_mapq=args.min_mapq,
961
+ outfile_writer=outfile,
962
+ amp_depths=amp_depths,
963
+ )
964
+
965
+ if not trimming_tuple:
966
+ continue
967
+
968
+ # unpack the trimming tuple since segment passed trimming
969
+ amplicon, trimmed_pair = trimming_tuple
970
+
971
+ # If we aren't normalising the segments will have already been written to the outfile
972
+ if not args.normalise and not trimmed_pair:
973
+ continue
974
+
975
+ trimmed_segments[trimmed_pair[0].reference_name].setdefault(amplicon, []) # type: ignore
976
+
977
+ if trimmed_segments:
978
+ trimmed_segments[trimmed_pair[0].reference_name][amplicon].append( # type: ignore
979
+ trimmed_pair
980
+ )
981
+
982
+ # normalise if requested and write normalised segments to outfile
983
+ if args.normalise:
984
+ mean_amp_depths = normalise(
985
+ trimmed_segments=trimmed_segments,
986
+ normalise=args.normalise,
987
+ primers=scheme.bedlines,
988
+ outfile=outfile,
989
+ verbose=args.verbose,
990
+ )
991
+ else:
992
+ mean_amp_depths = {}
993
+ for chrom, chrom_amps in amp_depths.items():
994
+ for amplicon, depths in chrom_amps.items():
995
+ mean_amp_depths[(chrom, amplicon)] = np.mean(depths)
996
+
997
+ # write mean amplicon depths to file
998
+ if args.amp_depth_report:
999
+ with open(args.amp_depth_report, "w") as amp_depth_report_fh:
1000
+ writer = csv.DictWriter(
1001
+ amp_depth_report_fh,
1002
+ fieldnames=["chrom", "amplicon", "mean_depth"],
1003
+ delimiter="\t",
1004
+ )
1005
+ writer.writeheader()
1006
+ for (chrom, amplicon), depth in mean_amp_depths.items():
1007
+ writer.writerow(
1008
+ {"chrom": chrom, "amplicon": amplicon, "mean_depth": depth}
1009
+ )
1010
+
1011
+ else:
1012
+ # iterate over the alignment segments in the input SAM file
1013
+ for segment in chained_iterator:
1014
+ if args.report:
1015
+ trimming_tuple = handle_segments(
1016
+ segment=segment,
1017
+ args=args,
1018
+ report_writer=report_writer, # type: ignore
1019
+ min_mapq=args.min_mapq,
1020
+ lookup=primer_lookup,
1021
+ outfile_writer=outfile,
1022
+ amp_depths=amp_depths,
1023
+ )
1024
+
1025
+ else:
1026
+ trimming_tuple = handle_segments(
1027
+ segment=segment,
1028
+ args=args,
1029
+ min_mapq=args.min_mapq,
1030
+ lookup=primer_lookup,
1031
+ outfile_writer=outfile,
1032
+ amp_depths=amp_depths,
1033
+ )
1034
+
1035
+ if not trimming_tuple:
1036
+ continue
1037
+
1038
+ # unpack the trimming tuple since segment passed trimming
1039
+ amplicon, trimmed_segment = trimming_tuple
1040
+
1041
+ # If we aren't normalising the segments will have already been written to the outfile
1042
+ if not args.normalise and not trimmed_segment:
1043
+ continue
1044
+
1045
+ trimmed_segments[trimmed_segment.reference_name].setdefault(amplicon, []) # type: ignore
1046
+
1047
+ if trimmed_segment and args.normalise:
1048
+ trimmed_segments[trimmed_segment.reference_name][amplicon].append( # type: ignore
1049
+ trimmed_segment
1050
+ )
1051
+
1052
+ # normalise if requested
1053
+ if args.normalise:
1054
+ mean_amp_depths = normalise(
1055
+ trimmed_segments=trimmed_segments,
1056
+ normalise=args.normalise,
1057
+ primers=scheme.bedlines,
1058
+ outfile=outfile,
1059
+ verbose=args.verbose,
1060
+ )
1061
+
1062
+ else:
1063
+ mean_amp_depths = {}
1064
+ for chrom, chrom_amps in amp_depths.items():
1065
+ for amplicon, depths in chrom_amps.items():
1066
+ mean_amp_depths[(chrom, amplicon)] = np.mean(depths)
1067
+
1068
+ # write mean amplicon depths to file
1069
+ if args.amp_depth_report:
1070
+ with open(args.amp_depth_report, "w") as amp_depth_report_fh:
1071
+ writer = csv.DictWriter(
1072
+ amp_depth_report_fh,
1073
+ fieldnames=["chrom", "amplicon", "mean_depth"],
1074
+ delimiter="\t",
1075
+ )
1076
+ writer.writeheader()
1077
+
1078
+ for (chrom, amplicon), depth in mean_amp_depths.items():
1079
+ writer.writerow(
1080
+ {"chrom": chrom, "amplicon": amplicon, "mean_depth": depth}
1081
+ )
1082
+
1083
+ # close up the file handles
1084
+ infile.close()
1085
+ outfile.close()
1086
+ if args.report:
1087
+ reportfh.close() # type: ignore
1088
+
1089
+
1090
+ def main():
1091
+ parser = argparse.ArgumentParser(
1092
+ description="Trim alignments from an amplicon scheme. Bam (input) can be provided by --samfile or stdin"
1093
+ )
1094
+ parser.add_argument(
1095
+ "bedfile",
1096
+ help="BED file containing the amplicon scheme",
1097
+ type=Path,
1098
+ metavar="BEDFILE",
1099
+ )
1100
+ parser.add_argument(
1101
+ "--samfile",
1102
+ "-s",
1103
+ help="Sorted SAM/BAM file containing the aligned reads, if this is not provided (or '-') then 'align_trim' will read from stdin.",
1104
+ required=False,
1105
+ )
1106
+ parser.add_argument(
1107
+ "--normalise",
1108
+ "-n",
1109
+ type=int,
1110
+ help="Subsample to N coverage per amplicon. Use 0 for no normalisation. (default: %(default)s)",
1111
+ default=0,
1112
+ )
1113
+ parser.add_argument(
1114
+ "--min-mapq",
1115
+ "-m",
1116
+ type=int,
1117
+ default=20,
1118
+ help="Minimum mapping quality to keep an aligned read (default: %(default)s)",
1119
+ )
1120
+ parser.add_argument(
1121
+ "--primer-match-threshold",
1122
+ "-p",
1123
+ type=int,
1124
+ default=35,
1125
+ help="Add -p bases of padding to the outside (5' end of primer) of primer coordinates to allow fuzzy matching for reads with barcodes/adapters. (default: %(default)s)",
1126
+ )
1127
+ parser.add_argument(
1128
+ "--report", "-r", type=Path, help="Output report TSV to filepath"
1129
+ )
1130
+ parser.add_argument(
1131
+ "--amp-depth-report",
1132
+ "-a",
1133
+ type=Path,
1134
+ help="Output amplicon depth TSV to filepath",
1135
+ )
1136
+ parser.add_argument(
1137
+ "--no-trim-primers",
1138
+ action="store_true",
1139
+ help="Do not trim primers from reads",
1140
+ )
1141
+ parser.add_argument(
1142
+ "--no-read-groups",
1143
+ dest="no_read_groups",
1144
+ help="Do not divide reads into groups in samfile output",
1145
+ action="store_true",
1146
+ )
1147
+ parser.add_argument(
1148
+ "--allow-incorrect-pairs",
1149
+ action="store_true",
1150
+ help="Allow reads to be assigned to amplicons even if the primers are not correctly paired, i.e. primer1 and primer2 are not from the same amplicon.",
1151
+ )
1152
+ parser.add_argument(
1153
+ "--require-full-length",
1154
+ action="store_true",
1155
+ help="Requires all reads to start and stop in a primer site, do not use this option if you are using rapid barcoding since the reads will not be full length.",
1156
+ )
1157
+ parser.add_argument(
1158
+ "--output",
1159
+ "-o",
1160
+ type=Path,
1161
+ default=None,
1162
+ metavar="OUTPUT",
1163
+ help="Location to write the output samfile to, the output type will be determined by the file extension. If no <OUTPUT> or '-' provided, will write plaintext samfile to stdout",
1164
+ )
1165
+ parser.add_argument("--verbose", "-v", action="store_true", help="Debug mode")
1166
+ parser.add_argument(
1167
+ "--version",
1168
+ action="version",
1169
+ version=f"%(prog)s {version('align_trim')}",
1170
+ help="Show the version of align_trim",
1171
+ )
1172
+
1173
+ args = parser.parse_args()
1174
+
1175
+ go(args)
1176
+
1177
+
1178
+ if __name__ == "__main__":
1179
+ main()
@@ -0,0 +1,133 @@
1
+ Metadata-Version: 2.4
2
+ Name: align_trim
3
+ Version: 1.0.2
4
+ Summary: Soft-clip primer sites for SAM/BAM files generated from amplicon sequencing runs
5
+ Project-URL: Repository, https://github.com/artic-network/align_trim.git
6
+ Project-URL: Issues, https://github.com/artic-network/align_trim/issues
7
+ Author-email: Nick Loman <n.j.loman@bham.ac.uk>, Sam Wilkinson <s.a.j.wilkinson@bham.ac.uk>, Chris Kent <c.g.kent@bham.ac.uk>
8
+ Maintainer-email: Sam Wilkinson <s.a.j.wilkinson@bham.ac.uk>, Chris Kent <c.g.kent@bham.ac.uk>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Requires-Python: >=3.9
12
+ Requires-Dist: numpy
13
+ Requires-Dist: primalbedtools>=0.10.1
14
+ Requires-Dist: pysam
15
+ Description-Content-Type: text/markdown
16
+
17
+ # align_trim
18
+
19
+ Stand alone version of ARTIC's fieldbioinfomatics align_trim.py
20
+
21
+ ## Installation
22
+
23
+ From conda
24
+ ```bash
25
+ conda install bioconda::align_trim
26
+ ```
27
+ from pypi
28
+ ```bash
29
+ pip install align_trim
30
+ ```
31
+ from source
32
+ ```bash
33
+ git clone https://github.com/artic-network/align_trim.git
34
+ cd align_trim
35
+ uv sync
36
+ uv run align_trim --help
37
+ ```
38
+
39
+ ## Command Line Interface
40
+
41
+ ### Basic Usage
42
+
43
+ ```bash
44
+ aligntrim [OPTIONS] BEDFILE
45
+ ```
46
+
47
+ The tool reads alignment data from either a SAM file or stdin and outputs trimmed alignments to stdout in SAM format by default.
48
+
49
+ ### Required Arguments
50
+
51
+ - `BEDFILE`: BED file containing the amplicon primer scheme in [v3](https://doi.org/10.5281/zenodo.16366659) format.
52
+
53
+ ### Optional Arguments
54
+
55
+ #### Input/Output Options
56
+
57
+ - `--samfile`, `-s` : Sorted SAM/BAM file containing the aligned reads, if this is not provided (or '-') then 'align_trim' will read from stdin.
58
+ - `--output`, `-o` : Output file path. Format determined by extension (.sam/.bam). If not provided or '-', writes SAM to stdout
59
+
60
+ #### Processing Options
61
+
62
+ - `--normalise`, `-n` : Subsample to N coverage per amplicon. Use 0 for no normalisation (default: 0)
63
+ - `--min-mapq`, `-m` : Minimum mapping quality to keep an aligned read (default: 20)
64
+ - `--primer-match-threshold`, `-p` : Fuzzy match primer positions within this threshold (default: 35)
65
+
66
+ #### Primer and Read Handling
67
+
68
+ - `--no-trim-primers` : Do not trim primers from reads (by default, primers are trimmed)
69
+ - `--allow-incorrect-pairs` : Allow reads to be assigned to amplicons even if primers are not correctly paired
70
+ - `--require-full-length` : Require all reads to start and stop in primer sites (do not use with rapid barcoding)
71
+
72
+ #### Output and Reporting
73
+
74
+ - `--report`, `-r` : Output detailed report TSV to specified filepath
75
+ - `--amp-depth-report`, `-a` : Output mean depth for each amplicon as TSV to specified filepath
76
+ - `--no-read-groups` : Do not divide reads into pool-based read groups in SAM/BAM output
77
+
78
+ #### General Options
79
+
80
+ - `--verbose`, `-v` : Enable debug mode with detailed logging to stderr
81
+ - `--version` : Show version information
82
+ - `--help` : Show help message
83
+
84
+ ### Examples
85
+
86
+ #### Basic trimming with primer removal
87
+ ```bash
88
+ aligntrim primers.bed --bamfile input.bam --output trimmed.bam
89
+ ```
90
+
91
+ #### Normalize coverage and generate reports
92
+ ```bash
93
+ aligntrim primers.bed --bamfile input.bam --normalise 100 \
94
+ --report alignment_report.tsv --amp-depth-report depth_report.tsv \
95
+ --output normalized.bam
96
+ ```
97
+
98
+ #### Process from stdin with verbose output
99
+ ```bash
100
+ samtools view -h input.bam | aligntrim primers.bed --verbose > trimmed.sam 2> verbose.out.txt
101
+ ```
102
+
103
+ #### Strict full-length read filtering
104
+ ```bash
105
+ aligntrim primers.bed --bamfile input.bam --require-full-length \
106
+ --min-mapq 30 --output filtered.bam
107
+ ```
108
+
109
+ #### Allow mismatched primer pairs with custom threshold
110
+ ```bash
111
+ aligntrim primers.bed --bamfile input.bam --allow-incorrect-pairs \
112
+ --primer-match-threshold 50 --output relaxed.bam
113
+ ```
114
+
115
+ ### Output Formats
116
+
117
+ The tool supports multiple output formats based on file extension:
118
+ - `.sam` - SAM format (text)
119
+ - `.bam` - BAM format (binary, compressed)
120
+ - No extension or `-` - SAM format to stdout
121
+
122
+ ### Report Files
123
+
124
+ When using `--report`, a tab-separated file is generated with the following columns:
125
+ - `chrom`: Reference chromosome/contig
126
+ - `QueryName`: Read name
127
+ - `ReferenceStart`/`ReferenceEnd`: Alignment coordinates
128
+ - `PrimerPair`: Primer pair assignment
129
+ - `Primer1`/`Primer2`: Individual primer information
130
+ - `CorrectlyPaired`: Boolean indicating proper primer pairing
131
+ - Additional alignment metrics
132
+
133
+ The `--amp-depth-report` generates a summary of coverage depth per amplicon.
@@ -0,0 +1,7 @@
1
+ align_trim/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ align_trim/main.py,sha256=p4RuPiZOXFfApQRyIZmks8fXdwxLFmVskiwFuqmihM4,42927
3
+ align_trim-1.0.2.dist-info/METADATA,sha256=0u6-vCn30-eyo_9-XsducgqRQGfU1Yt5DVmkGgkbOX0,4358
4
+ align_trim-1.0.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ align_trim-1.0.2.dist-info/entry_points.txt,sha256=ZUSdteDVarhMD6c3JcQQcpcsotuuzDZVPfiHdRATYN4,52
6
+ align_trim-1.0.2.dist-info/licenses/LICENSE,sha256=E-00BwKTV_FGdgp-4TbWXU1LRY8Mbxxj6Ab9a_SqctE,1099
7
+ align_trim-1.0.2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ align_trim = align_trim.main:main
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2017-2018 Nick Loman & the ZiBRA Project & the ARTIC project
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.