|
| 1 | +/* |
| 2 | + * samtools_compat.h -- Minimal struct definitions extracted from samtools |
| 3 | + * for panmap's pileup module. Avoids linking against libst.a. |
| 4 | + * |
| 5 | + * Original sources: samtools/bam_plcmd.h, samtools/sam_opts.h |
| 6 | + * Copyright (C) 2008-2024 Genome Research Ltd. |
| 7 | + * License: MIT/Expat (same as samtools) |
| 8 | + */ |
| 9 | + |
| 10 | +#ifndef SAMTOOLS_COMPAT_H |
| 11 | +#define SAMTOOLS_COMPAT_H |
| 12 | + |
| 13 | +#include <stdio.h> |
| 14 | +#include <string.h> |
| 15 | +#include <stdarg.h> |
| 16 | +#include <htslib/hts.h> |
| 17 | +#include <htslib/sam.h> |
| 18 | +#include <htslib/faidx.h> |
| 19 | +#include <htslib/kstring.h> |
| 20 | +#include <htslib/klist.h> |
| 21 | +#include <htslib/khash_str2int.h> |
| 22 | +#include <htslib/cram.h> |
| 23 | + |
| 24 | +/* --- From sam_opts.h --- */ |
| 25 | + |
| 26 | +typedef struct sam_global_args { |
| 27 | + htsFormat in; |
| 28 | + htsFormat out; |
| 29 | + char *reference; |
| 30 | + int nthreads; |
| 31 | + int write_index; |
| 32 | +} sam_global_args; |
| 33 | + |
| 34 | +static inline void sam_global_args_init(sam_global_args *ga) { |
| 35 | + if (ga) memset(ga, 0, sizeof(*ga)); |
| 36 | +} |
| 37 | + |
| 38 | +/* --- From bam_plcmd.h --- */ |
| 39 | + |
| 40 | +#define MPLP_NO_COMP (1<<2) |
| 41 | +#define MPLP_NO_ORPHAN (1<<3) |
| 42 | +#define MPLP_REALN (1<<4) |
| 43 | +#define MPLP_NO_INDEL (1<<5) |
| 44 | +#define MPLP_REDO_BAQ (1<<6) |
| 45 | +#define MPLP_ILLUMINA13 (1<<7) |
| 46 | +#define MPLP_IGNORE_RG (1<<8) |
| 47 | +#define MPLP_SMART_OVERLAPS (1<<10) |
| 48 | + |
| 49 | +#define MPLP_PRINT_MAPQ_CHAR (1<<11) |
| 50 | +#define MPLP_PRINT_QPOS (1<<12) |
| 51 | +#define MPLP_PRINT_QNAME (1<<13) |
| 52 | +#define MPLP_PRINT_FLAG (1<<14) |
| 53 | +#define MPLP_PRINT_RNAME (1<<15) |
| 54 | +#define MPLP_PRINT_POS (1<<16) |
| 55 | +#define MPLP_PRINT_MAPQ (1<<17) |
| 56 | +#define MPLP_PRINT_CIGAR (1<<18) |
| 57 | +#define MPLP_PRINT_RNEXT (1<<19) |
| 58 | +#define MPLP_PRINT_PNEXT (1<<20) |
| 59 | +#define MPLP_PRINT_TLEN (1<<21) |
| 60 | +#define MPLP_PRINT_SEQ (1<<22) |
| 61 | +#define MPLP_PRINT_QUAL (1<<23) |
| 62 | +#define MPLP_PRINT_RLEN (1<<24) |
| 63 | +#define MPLP_PRINT_MODS (1<<25) |
| 64 | +#define MPLP_PRINT_QPOS5 (1<<26) |
| 65 | +#define MPLP_PRINT_LAST (1<<27) |
| 66 | + |
| 67 | +#define MPLP_MAX_DEPTH 8000 |
| 68 | +#define MPLP_MAX_INDEL_DEPTH 250 |
| 69 | + |
| 70 | +typedef struct { |
| 71 | + int min_mq, flag, min_baseQ, capQ_thres, max_depth, max_indel_depth, all, rev_del; |
| 72 | + int rflag_require, rflag_filter; |
| 73 | + char *reg, *pl_list, *fai_fname, *output_fname; |
| 74 | + faidx_t *fai; |
| 75 | + void *bed, *rghash, *auxlist; |
| 76 | + int argc; |
| 77 | + char **argv; |
| 78 | + char sep, empty, no_ins, no_ins_mods, no_del, no_ends; |
| 79 | + sam_global_args ga; |
| 80 | +} mplp_conf_t; |
| 81 | + |
| 82 | +typedef struct { |
| 83 | + char *ref[2]; |
| 84 | + int ref_id[2]; |
| 85 | + hts_pos_t ref_len[2]; |
| 86 | +} mplp_ref_t; |
| 87 | + |
| 88 | +#define MPLP_REF_INIT {{NULL,NULL},{-1,-1},{0,0}} |
| 89 | + |
| 90 | +typedef struct { |
| 91 | + samFile *fp; |
| 92 | + hts_itr_t *iter; |
| 93 | + sam_hdr_t *h; |
| 94 | + mplp_ref_t *ref; |
| 95 | + const mplp_conf_t *conf; |
| 96 | +} mplp_aux_t; |
| 97 | + |
| 98 | +typedef struct { |
| 99 | + int n; |
| 100 | + int *n_plp, *m_plp; |
| 101 | + bam_pileup1_t **plp; |
| 102 | +} mplp_pileup_t; |
| 103 | + |
| 104 | +/* --- Inline replacements for samtools utility functions --- */ |
| 105 | + |
| 106 | +static inline void print_error(const char *subcommand, const char *fmt, ...) { |
| 107 | + va_list args; |
| 108 | + fprintf(stderr, "[%s] ", subcommand); |
| 109 | + va_start(args, fmt); |
| 110 | + vfprintf(stderr, fmt, args); |
| 111 | + va_end(args); |
| 112 | + fprintf(stderr, "\n"); |
| 113 | +} |
| 114 | + |
| 115 | +/* |
| 116 | + * bed_overlap is called in pileup.c but only when conf->bed != NULL. |
| 117 | + * panmap never sets conf->bed, so these calls are dead code. |
| 118 | + * Provide a stub that always returns 0 to satisfy the linker. |
| 119 | + */ |
| 120 | +static inline int bed_overlap(const void *bed, const char *seq, |
| 121 | + hts_pos_t start, hts_pos_t end) { |
| 122 | + (void)bed; (void)seq; (void)start; (void)end; |
| 123 | + return 0; |
| 124 | +} |
| 125 | + |
| 126 | +#endif /* SAMTOOLS_COMPAT_H */ |
0 commit comments