root/galaxy-central/lib/galaxy/datatypes/converters/interval_to_summary_tree_converter.py @ 2

リビジョン 2, 1.8 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#!/usr/bin/env python
2
3"""
4Convert from interval file to summary tree file. Default input file format is BED (0-based, half-open intervals).
5
6usage: %prog in_file out_file
7    -G, --gff: input is GFF format, meaning start and end coordinates are 1-based, closed interval
8"""
9from __future__ import division
10
11import sys, fileinput
12from galaxy import eggs
13import pkg_resources; pkg_resources.require( "bx-python" )
14from galaxy.visualization.tracks.summary import *
15from bx.intervals.io import *
16from bx.cookbook import doc_optparse
17from galaxy.tools.util.gff_util import GFFReaderWrapper
18
19def main():
20    # Read options, args.
21    options, args = doc_optparse.parse( __doc__ )
22    try:
23        gff_format = bool( options.gff )
24        input_fname, out_fname = args
25    except:
26        doc_optparse.exception()
27       
28    # Do conversion.
29    # TODO: take column numbers from command line.
30    if gff_format:
31        reader_wrapper_class = GFFReaderWrapper
32        chr_col, start_col, end_col, strand_col = ( 0, 3, 4, 6 )
33    else:
34        reader_wrapper_class = NiceReaderWrapper
35        chr_col, start_col, end_col, strand_col = ( 0, 1, 2, 5 )
36    reader_wrapper = reader_wrapper_class( fileinput.FileInput( input_fname ),
37                                            chrom_col=chr_col,
38                                            start_col=start_col,
39                                            end_col=end_col,
40                                            strand_col=strand_col,
41                                            fix_strand=True )
42    st = SummaryTree(block_size=25, levels=6, draw_cutoff=150, detail_cutoff=30)
43    for line in list( reader_wrapper ):
44        if type( line ) is GenomicInterval:
45            st.insert_range( line.chrom, long( line.start ), long( line.end ) )
46   
47    st.write(out_fname)
48
49if __name__ == "__main__":
50    main()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。