Samtools tview as a library to display the BAM
I've forked samtools and modified the code of tview to use it as a library to display the alignments. The original code is an inreractive interface using the ncurses library. I've modified the original code and changed the structure of the C 'struct tview' with a few callbacks to make it more object-oriented:
(...) typedef struct AbstractTview { int mrow, mcol; (...) khash_t(kh_rg) *rg_hash; /* callbacks */ void (*my_destroy)(struct AbstractTview* ); void (*my_mvprintw)(struct AbstractTview* ,int,int,const char*,...); void (*my_mvaddch)(struct AbstractTview*,int,int,int); void (*my_attron)(struct AbstractTview*,int); void (*my_attroff)(struct AbstractTview*,int); void (*my_clear)(struct AbstractTview*); int (*my_colorpair)(struct AbstractTview*,int); int (*my_drawaln)(struct AbstractTview*,int,int); int (*my_loop)(struct AbstractTview*); int (*my_underline)(struct AbstractTview*); } tview_t;With those callbacks, there is a strong separation between the 'view' and the 'model'. Tview can now be used as a library and it's now easy to create any kind of view you need by extending the 'struct tview_t'. I've created two new interfaces: one for HTML:
samtools tview -d H examples/sorted.bam -p seq1:20
21 31 41 51 61 71 81 NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN ATGTGTGGTTTAACTCGTCCATGGCCCAGCATTAGGGAGCTGTGGACCCTGCAGCCTGGCTGTGGGGGCCGCAGTGGSTG ATGTGTGGTTTAACTCGTACATGGCCCAGCATTAGGGAGCTGTGGACCCCG GCCTGGCTGTGGGGGCACCAGCCGCTG ATGTGTGGTTTAACTCGTACATGGCCCAGCATTAGGGAGCTGTGGACCCCG GCCTGGCTGTGGGGGCACCAGCCGCTG ATGTGTGGTTTAACTCGTACATGGCCCAGCATTAGGGAGCTGTGGACCCCG GCCTGGCTGTGGGGGCACCAGCCGCTG ATGTGTGGTTTAACTCGTCCATGGCCCAGCATTAGGGCGCTGTGGACCCTGC CTGTGGGGGCCGCAGTGGCTG ATGTGTGGTTTAACTCGT GCCCAGCATTAGGGAGCTGTGGACCCTGCAGCCTG CTGTGGGGGCCGCAGTGG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GGGCGCCG ATGTGTGGTTTAACTCGTCCATTGCCCAGC TGTGGACCCTGCAGCCTGGCTGTGGGGGCCGCAGTG ATGTGTGGTTTAACTCGTCCATTGCCCAGC TGTGGACCCTGCAGCCTGGCTGGGGGGGGCGCAGT atgtgtggtttaactcgtccatggcccagcatt TGTGGACCCTGCAGCCTGGCTGTGGGGGCCGCAGTG atgtgtggtttaactcgtccatggcccagcatt TGTGGACCCTGCAGCCTGGCTGGGGGGGGCGCAGT atgtgtggtttaactcgtccatggcccagcatt TGTGGACCCTGCAGCCTGGCTGTGGGGGCCGCAGTG GTGTGGTTTAACTCGTCCATGGCCCAGCATTTGGG TGTGGACCCTGCAGCCTGGCTGGGGGGGGCGCAGT GTGTGGTTTAACTCGTCCATGGCCCAGCATTAGGG GTGGACCCTGCAGCCTGGCTGGGGGGGGCACGGGG GTGTGGTTTAACTCGTCCATGGCCCAGCATTTGGG GTGGACCCTGCAGCCTGGCTGTGGGGGCCGCAGTG GTGTGGTTTAACTCGTCCATGGCCCAGCATTAGGG GTGGACCCTGCAGCCTGGCTGGGGGGGGCACGGGG GTGTGGTTTAACTCGTCCATGGCCCAGCATTTGGG GTGGACCCTGCAGCCTGGCTGTGGGGGCCGCAGTG GTGTGGTTTAACTCGTCCATGGCCCAGCATTAGGG GTGGACCCTGCAGCCTGGCTGGGGGGGGCACGGGG GTGGTTTAACTCGTCCATGGCCCAGCATTAGGGAGC GTGGACCCTGCAGCCTGGCTGTGGGGGCCGCAGTG GTGGTTTAACTCGTCCATGGCCCAGCATTAGGGAGC GGACCCTGCAGCCTGGCTGTGGGGGCCGCTGTGGG GTGGTTTAACTCGTCCATGGCCCAGCATTAGGGAGC GGACCCTGCAGCCTGGCTGTGGGGGCCGCTGTGGG TTTAACTCGTCCATGGCCCAGCATTAGGGATCTGT CCTGCAGCCTGGCTGTGGGGGCCGCAGCGGGTG TTTAACTCGTCCATGGCCCAGCATTAGGGATCTGT CCTGCAGCCTGGCTGTGGGGGCCGCAGCGGGTG TTTAACTCGTCCATGGCCCAGCATTAGGGATCTGT CCTGCAGCCTGGCTGTGGGGGCCGCAGCGGGTG TTAACTCGTCCATGGCCCAGCATTAGGGAGCTGTG GCAGCCTGGCTGTGGGGGCCGCAGTGGCTG TTAACTCGTCCATGGCCCAGCATTAGGGAGCTGTG GCAGCCTGGCTGTGGGGGCCGCAGTGGCTG TTAACTCGTCCATGGCCCAGCATTAGGGAGCTGTG GCAGCCTGGCTGTGGGGGCCGCAGTGGCTG AACTCGTCCATGGCCCAGCATTAGGGAGCTGTGGA CTGTGGGGGCCGCAGTGGGTG AACTCGTCCATGGCCCAGCATTAGGGAGCTGTGGA CTGTGGGGGCCGCAGTGGCTG AACTCGTCCATGGCCCAGCATTAGGGAGCTGTGGA CTGTGGGGGCCGCAGTGGCTG TCCATGGCCCAGCATTAGGGCGCTGTGGACCCTGC CTGTGGGGGCCGCAGTGGGTG TCCATGGCCCAGCATTAGGGCGCTGTGGACCCTGC CTGTGGGGGCCGCAGTGGCTG GGACCCTGCAGCCTGGCTGTGGGGGCCGCTGTGGG TGTGGGGGCCGCAGTGGCTG TGTGGGGGCCGCAGTGGCTG TGTGGGGGCCGCAGTGGCTG
And another one for TEXT (with colors on a terminal):
samtools tview -d t examples/sorted.bam -p seq1:23
31 41 51 61 71 81 91
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
TGTGGTTTAACTCGTCCATGGCCCAGCATTAGGGAGCTGTGGACCCTGCAGCCTGGCTGTGGGGGCCGCAGTGGSTGAGG
TGTGGTTTAACTCGTACATGGCCCAGCATTAGGGAGCTGTGGACCCCG GCCTGGCTGTGGGGGCACCAGCCGCTGCGG
TGTGGTTTAACTCGTACATGGCCCAGCATTAGGGAGCTGTGGACCCCG GCCTGGCTGTGGGGGCACCAGCCGCTGCGG
TGTGGTTTAACTCGTACATGGCCCAGCATTAGGGAGCTGTGGACCCCG GCCTGGCTGTGGGGGCACCAGCCGCTGCGG
TGTGGTTTAACTCGTCCATGGCCCAGCATTAGGGCGCTGTGGACCCTGC CTGTGGGGGCCGCAGTGGCTGAGG
TGTGGTTTAACTCGT GCCCAGCATTAGGGAGCTGTGGACCCTGCAGCCTG CTGTGGGGGCCGCAGTGGCTGAGG
TGTGGTTTAACTCGT GCCCAGCATTAGGGAGCTGTGGACCCTGCAGCCTG CTGTGGGGGCCGCAGTGGGTGAGG
TGTGGTTTAACTCGTCC GCCCAGCATTAGGGAGCTGTGGACCCTGCAGCCTG CTGTGGGGGCCGCAGTGGCTGAGG
TGTGGTTTAACTCGTCC CATTAGGGAGCTGTGGACCCTGCAGCCTGGCTGTTG GGCTGAGG
TGTGGTTTAACTCGTCC CATTAGGGAGCTGTGGACCCTGCAGCCTGGCTGTTG GGCTGAGG
TTTGTTTTAACTCTTCTCT CATTAGGGAGCTGTGGACCCTGCAGCCTGGCTGTTG GGCTGAGG
TTTGTTTTAACTCTTCTCT ATTAGGGAGCTGTGGACCCTGCAGCCTGGCTGGGG AGG
TTTGTTTTAACTCTTCTCT ATTAGGGAGCTGTGGACCCTGCAGCCTGGCTGGGG AGG
TGTGGTTTAACTCGTCCATGG ATTAGGGAGCTGTGGACCCTGCAGCCTGGCTGGGG AGG
The code is available on github:
That's it,
Pierre