src/gstruct/src/bamread.h
5659f096
 /* $Id: bamread.h 178960 2015-11-16 19:52:26Z twu $ */
36cb64f8
 #ifndef BAMREAD_INCLUDED
 #define BAMREAD_INCLUDED
 /* Cannot use bool, since it appears to conflict with samtools */
 #include <stdio.h>
 #include "genomicpos.h"
 #include "intlist.h"
 #include "uintlist.h"
 #include "genome.h"
 #include "iit-read.h"
 
 #include "table.h"
 #include "uinttable.h"
 #include "chrom.h"
 #include "list.h"
 
 
 #define T Bamreader_T
 typedef struct T *T;
 
 extern void
 Bamread_free (T *old);
 
 extern T
 Bamread_new (char *filename);
 
 extern void
 Bamread_write_header (T this);
 
 extern Genomicpos_T
 Bamread_chrlength (T this, char *chr);
 
 extern bool
 Bamread_limit_region (T this, char *chr, Genomicpos_T chrstart, Genomicpos_T chrend);
 
 extern void
 Bamread_unlimit_region (T this);
 
 extern int
 Bamread_nreads (int *npositions, T this, char *chr, Genomicpos_T chrpos1, Genomicpos_T chrpos2);
 
 extern int
 Bamread_next_line (T this, char **acc, unsigned int *flag, int *mapq, char **chr, Genomicpos_T *chrpos,
 		   char **mate_chr, Genomicpos_T *mate_chrpos,
 		   Intlist_T *cigartypes, Uintlist_T *cigarlengths, int *cigarlength,
8418591e
 		   int *readlength, char **read, char **quality_string, char **hardclip, char **hardclip_quality,
 		   char **read_group, bool *terminalp);
36cb64f8
 
 typedef struct Bamline_T *Bamline_T;
 
 extern char *
 Bamline_acc (Bamline_T this);
 extern unsigned int
 Bamline_flag (Bamline_T this);
 extern int
 Bamline_concordantp (Bamline_T this);
 extern int
 Bamline_lowend_p (Bamline_T this);
 extern int
 Bamline_paired_read_p (Bamline_T this);
 extern int
 Bamline_firstend_p (Bamline_T this);
 extern int
5659f096
 Bamline_hiti (Bamline_T this);
 extern int
36cb64f8
 Bamline_nhits (Bamline_T this);
 extern bool
 Bamline_good_unique_p (Bamline_T this);
c78be696
 extern bool
 Bamline_perfect_match_p (Bamline_T this);
36cb64f8
 extern int
 Bamline_mapq (Bamline_T this);
 extern char *
 Bamline_chr (Bamline_T this);
 extern Genomicpos_T
 Bamline_chrpos_low (Bamline_T this);
144f6bb1
 extern Genomicpos_T
 Bamline_chrpos_low_noclip (Bamline_T this);
36cb64f8
 extern char *
 Bamline_mate_chr (Bamline_T this);
 extern Genomicpos_T
 Bamline_mate_chrpos_low (Bamline_T this);
 extern int
 Bamline_insert_length (Bamline_T this);
 extern Intlist_T
 Bamline_cigar_types (Bamline_T this);
 extern Uintlist_T
 Bamline_cigar_npositions (Bamline_T this);
52b3ca64
 extern Intlist_T
8418591e
 Bamline_diffcigar (int *min_overhang, Uintlist_T *npositions, Uintlist_T *chrpositions, Bamline_T this);
36cb64f8
 extern int
 Bamline_cigar_querylength (Bamline_T this);
 extern void
95e6ece6
 Bamread_print_cigar (FILE *fp, Bamline_T this);
4d5cc806
 extern char *
 Bamline_cigar_string (Bamline_T this);
36cb64f8
 extern int
 Bamline_readlength (Bamline_T this);
 extern char *
 Bamline_read (Bamline_T this);
 extern char *
 Bamline_quality_string (Bamline_T this);
8418591e
 extern char *
 Bamline_hardclip (Bamline_T this);
 extern char *
 Bamline_hardclip_quality (Bamline_T this);
17db5e75
 extern bool
 Bamline_terminalp (Bamline_T this);
4d5cc806
 extern char *
 Bamline_read_group (Bamline_T this);
36cb64f8
 extern void
95e6ece6
 Bamline_print (FILE *fp, Bamline_T this, unsigned int newflag, int quality_score_adj);
144f6bb1
 extern void
 Bamline_print_new_cigar (FILE *fp, Bamline_T this, Genomicpos_T chrpos_low, char *new_cigar,
c78be696
 			 char *new_md_string, int quality_score_adj);
52b3ca64
 extern void
 Bamline_print_new_mate (FILE *fp, Bamline_T this, char *mate_chr, Genomicpos_T mate_chrpos_low,
 			int insert_length);
36cb64f8
 
8418591e
 extern int
 Bamline_nm (Bamline_T this);
36cb64f8
 extern char
 Bamline_splice_strand (Bamline_T this);
 
 extern char
 Bamline_strand (Bamline_T this, Genome_T genome, IIT_T chromosome_iit);
 extern Genomicpos_T
 Bamline_chrpos_high (Bamline_T this);
c78be696
 extern Genomicpos_T
 Bamline_chrpos_high_noclip (Bamline_T this);
 extern Genomicpos_T
 Bamline_total_ins (Bamline_T this);
 extern int
 Bamline_nmismatches (Bamline_T this);
36cb64f8
 
 
 extern void
 Bamline_free (Bamline_T *old);
 extern Bamline_T
4d5cc806
 Bamread_next_bamline (T this, char *desired_read_group, int minimum_mapq, int good_unique_mapq, int maximum_nhits,
95e6ece6
 		      bool need_unique_p, bool need_primary_p, bool ignore_duplicates_p,
 		      bool need_concordant_p);
 extern Bamline_T
c78be696
 Bamread_next_indel_bamline (T this, char *desired_read_group, int minimum_mapq, int good_unique_mapq, int maximum_nhits,
 			    bool need_unique_p, bool need_primary_p, bool ignore_duplicates_p,
 			    bool need_concordant_p);
 
 extern Bamline_T *
 Bamread_next_bamline_set (int *nlines, Bamline_T *prev_bamline,
 			  T this, char *desired_read_group, int minimum_mapq, int good_unique_mapq, int maximum_nhits,
 			  bool need_unique_p, bool need_primary_p, bool ignore_duplicates_p,
 			  bool need_concordant_p);
 
8418591e
 extern Bamline_T **
 Bamread_block (int **nlines, Genomicpos_T chrstart, Genomicpos_T chrend,
 	       T this, char *desired_read_group, int minimum_mapq, int good_unique_mapq, int maximum_nhits,
 	       bool need_unique_p, bool need_primary_p, bool ignore_duplicates_p,
 	       bool need_concordant_p);
 
c78be696
 extern Bamline_T
95e6ece6
 Bamread_get_acc (T this, char *desired_chr, Genomicpos_T desired_chrpos, char *desired_acc);
36cb64f8
 
 
 typedef struct Bamstore_T *Bamstore_T;
 
 extern void
 Bamstore_free (Bamstore_T *old);
 
 extern Bamstore_T
 Bamstore_new (Genomicpos_T chrpos);
 
 extern Bamline_T
 Bamstore_get (Table_T bamstore_chrtable, char *chr, Genomicpos_T low, char *acc,
5659f096
 	      Genomicpos_T mate_low, int hiti);
36cb64f8
 
 extern void
 Bamstore_add_at_low (Table_T bamstore_chrtable, char *chr, Genomicpos_T low,
 		     Bamline_T bamline);
 
 extern void
 Bamstore_table_free (Uinttable_T *bamstore_table);
 
 
 typedef struct Bampair_T *Bampair_T;
 
8418591e
 extern char *
 Bampair_acc (Bampair_T this);
95e6ece6
 extern Bamline_T
 Bampair_bamline_low (Bampair_T this);
 extern Bamline_T
 Bampair_bamline_high (Bampair_T this);
36cb64f8
 extern Genomicpos_T
 Bampair_chrpos_low (Bampair_T this);
 extern Genomicpos_T
 Bampair_chrpos_high (Bampair_T this);
5659f096
 extern Genomicpos_T
 Bampair_chrpos_low_noclip (Bampair_T this);
 extern Genomicpos_T
 Bampair_chrpos_high_noclip (Bampair_T this);
 
36cb64f8
 extern int
 Bampair_level (Bampair_T this);
 extern bool
5659f096
 Bampair_plusp (Bampair_T this);
 extern bool
36cb64f8
 Bampair_good_unique_p (Bampair_T this);
 extern bool
 Bampair_uniquep (Bampair_T this);
 extern bool
 Bampair_primaryp (Bampair_T this);
 
 extern void
 Bampair_free (Bampair_T *old);
 extern void
95e6ece6
 Bampair_print (FILE *fp, Bampair_T this, int quality_score_adj);
36cb64f8
 extern void
5659f096
 Bampair_details (Uintlist_T *chrpos_first_lows, Uintlist_T *chrpos_first_highs,
 		 Uintlist_T *chrpos_second_lows, Uintlist_T *chrpos_second_highs,
 		 Uintlist_T *chrpos_overlap_lows, Uintlist_T *chrpos_overlap_highs,
36cb64f8
 		 Uintlist_T *splice_lows, Uintlist_T *splice_highs, Intlist_T *splice_signs,
 		 Bampair_T this);
 
 extern List_T
4d5cc806
 Bamread_all_pairs (T bamreader, char *desired_read_group, int minimum_mapq, int good_unique_mapq, int maximum_nhits,
95e6ece6
 		   bool need_unique_p, bool need_primary_p, bool ignore_duplicates_p,
 		   bool need_concordant_p);
36cb64f8
 
 extern int
 Bampair_compute_levels (List_T bampairs, Genomicpos_T mincoord,
 			Genomicpos_T maxcoord, int max_allowed_levels,
4d5cc806
 			double xfactor, Genomicpos_T min_pairlength, bool only_internal_p);
36cb64f8
 
 
 #undef T
 #endif