comparison gops_complement.py @ 3:e0a23ab32d7f draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/complement commit a1517c9d22029095120643bbe2c8fa53754dd2b7
author devteam
date Wed, 11 Nov 2015 12:47:38 -0500
parents d958d5a0d1e8
children 38c8bb402872
comparison
equal deleted inserted replaced
2:2221cf5f59aa 3:e0a23ab32d7f
6 -1, --cols1=N,N,N,N: Columns for chrom, start, end, strand in file 6 -1, --cols1=N,N,N,N: Columns for chrom, start, end, strand in file
7 -l, --lengths=N: Filename of .len file for species (chromosome lengths) 7 -l, --lengths=N: Filename of .len file for species (chromosome lengths)
8 -a, --all: Complement all chromosomes (Genome-wide complement) 8 -a, --all: Complement all chromosomes (Genome-wide complement)
9 """ 9 """
10 10
11 import sys, traceback, fileinput 11 import sys
12 from warnings import warn 12 import fileinput
13 from bx.intervals import * 13 from bx.intervals.io import GenomicInterval, GenomicIntervalReader, NiceReaderWrapper
14 from bx.intervals.io import *
15 from bx.intervals.operations.complement import complement 14 from bx.intervals.operations.complement import complement
16 from bx.intervals.operations.subtract import subtract 15 from bx.intervals.operations.subtract import subtract
17 from bx.cookbook import doc_optparse 16 from bx.cookbook import doc_optparse
18 from galaxy.tools.util.galaxyops import * 17 from bx.tabular.io import ParseError
18 from galaxy.tools.util.galaxyops import fail, parse_cols_arg, skipped
19 19
20 assert sys.version_info[:2] >= ( 2, 4 ) 20 assert sys.version_info[:2] >= ( 2, 4 )
21 21
22
22 def main(): 23 def main():
23 allchroms = False 24 allchroms = False
24 upstream_pad = 0
25 downstream_pad = 0
26 25
27 options, args = doc_optparse.parse( __doc__ ) 26 options, args = doc_optparse.parse( __doc__ )
28 try: 27 try:
29 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 ) 28 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 )
30 lengths = options.lengths 29 lengths = options.lengths
31 if options.all: allchroms = True 30 if options.all:
31 allchroms = True
32 in_fname, out_fname = args 32 in_fname, out_fname = args
33 except: 33 except:
34 doc_optparse.exception() 34 doc_optparse.exception()
35 35
36 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), 36 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
43 lens = dict() 43 lens = dict()
44 chroms = list() 44 chroms = list()
45 # dbfile is used to determine the length of each chromosome. The lengths 45 # dbfile is used to determine the length of each chromosome. The lengths
46 # are added to the lens dict and passed copmlement operation code in bx. 46 # are added to the lens dict and passed copmlement operation code in bx.
47 dbfile = fileinput.FileInput( lengths ) 47 dbfile = fileinput.FileInput( lengths )
48 48
49 if dbfile: 49 if dbfile:
50 if not allchroms: 50 if not allchroms:
51 try: 51 try:
52 for line in dbfile: 52 for line in dbfile:
53 fields = line.split("\t") 53 fields = line.split("\t")
58 elif allchroms: 58 elif allchroms:
59 try: 59 try:
60 for line in dbfile: 60 for line in dbfile:
61 fields = line.split("\t") 61 fields = line.split("\t")
62 end = int(fields[1]) 62 end = int(fields[1])
63 chroms.append("\t".join([fields[0],"0",str(end)])) 63 chroms.append("\t".join([fields[0], "0", str(end)]))
64 except: 64 except:
65 pass 65 pass
66 66
67 # Safety...if the dbfile didn't exist and we're on allchroms, then 67 # Safety...if the dbfile didn't exist and we're on allchroms, then
68 # default to generic complement 68 # default to generic complement