annotate interval2maf.py @ 0:cfea1d6354db draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
author iuc
date Fri, 17 Jul 2020 10:56:42 -0400
parents
children 1080e07a2233
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
1 #!/usr/bin/env python
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
2 """
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
3 Reads a list of intervals and a maf. Produces a new maf containing the
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
4 blocks or parts of blocks in the original that overlapped the intervals.
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
5
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
6 If a MAF file, not UID, is provided the MAF file is indexed before being processed.
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
7
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
8 NOTE: If two intervals overlap the same block it will be written twice.
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
9
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
10 usage: %prog maf_file [options]
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
11 -d, --dbkey=d: Database key, ie hg17
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
12 -c, --chromCol=c: Column of Chr
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
13 -s, --startCol=s: Column of Start
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
14 -e, --endCol=e: Column of End
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
15 -S, --strandCol=S: Column of Strand
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
16 -t, --mafType=t: Type of MAF source to use
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
17 -m, --mafFile=m: Path of source MAF file, if not using cached version
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
18 -s, --mafFiles=s: Path of source MAF files, if using cached version
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
19 -I, --mafIndex=I: Path of precomputed source MAF file index, if not using cached version
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
20 -i, --interval_file=i: Input interval file
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
21 -o, --output_file=o: Output MAF file
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
22 -p, --species=p: Species to include in output
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
23 -P, --split_blocks_by_species=P: Split blocks by species
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
24 -r, --remove_all_gap_columns=r: Remove all Gap columns
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
25 -l, --indexLocation=l: Override default maf_index.loc file
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
26 -z, --mafIndexFile=z: Directory of local maf index file ( maf_index.loc or maf_pairwise.loc )
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
27 """
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
28 # Dan Blankenberg
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
29 from __future__ import print_function
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
30
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
31 import bx.align.maf
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
32 import bx.intervals.io
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
33 from bx.cookbook import doc_optparse
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
34 from galaxy.tools.util import maf_utilities
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
35
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
36
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
37 def __main__():
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
38 index = index_filename = None
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
39
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
40 # Parse Command Line
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
41 options, args = doc_optparse.parse(__doc__)
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
42
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
43 if options.dbkey:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
44 dbkey = options.dbkey
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
45 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
46 dbkey = None
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
47 if dbkey in [None, "?"]:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
48 maf_utilities.tool_fail("You must specify a proper build in order to extract alignments. You can specify your genome build by clicking on the pencil icon associated with your interval file.")
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
49
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
50 species = maf_utilities.parse_species_option(options.species)
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
51
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
52 if options.chromCol:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
53 chromCol = int(options.chromCol) - 1
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
54 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
55 maf_utilities.tool_fail("Chromosome column not set, click the pencil icon in the history item to set the metadata attributes.")
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
56
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
57 if options.startCol:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
58 startCol = int(options.startCol) - 1
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
59 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
60 maf_utilities.tool_fail("Start column not set, click the pencil icon in the history item to set the metadata attributes.")
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
61
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
62 if options.endCol:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
63 endCol = int(options.endCol) - 1
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
64 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
65 maf_utilities.tool_fail("End column not set, click the pencil icon in the history item to set the metadata attributes.")
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
66
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
67 if options.strandCol:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
68 strandCol = int(options.strandCol) - 1
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
69 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
70 strandCol = -1
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
71
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
72 if options.interval_file:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
73 interval_file = options.interval_file
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
74 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
75 maf_utilities.tool_fail("Input interval file has not been specified.")
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
76
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
77 if options.output_file:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
78 output_file = options.output_file
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
79 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
80 maf_utilities.tool_fail("Output file has not been specified.")
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
81
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
82 split_blocks_by_species = remove_all_gap_columns = False
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
83 if options.split_blocks_by_species and options.split_blocks_by_species == 'split_blocks_by_species':
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
84 split_blocks_by_species = True
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
85 if options.remove_all_gap_columns and options.remove_all_gap_columns == 'remove_all_gap_columns':
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
86 remove_all_gap_columns = True
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
87 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
88 remove_all_gap_columns = True
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
89 # Finish parsing command line
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
90
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
91 # Open indexed access to MAFs
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
92 if options.mafType:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
93 if options.indexLocation:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
94 index = maf_utilities.maf_index_by_uid(options.mafType, options.indexLocation)
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
95 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
96 index = maf_utilities.maf_index_by_uid(options.mafType, options.mafIndexFile)
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
97 if index is None:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
98 maf_utilities.tool_fail("The MAF source specified (%s) appears to be invalid." % (options.mafType))
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
99 elif options.mafFile:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
100 index, index_filename = maf_utilities.open_or_build_maf_index(options.mafFile, options.mafIndex, species=[dbkey])
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
101 if index is None:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
102 maf_utilities.tool_fail("Your MAF file appears to be malformed.")
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
103 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
104 maf_utilities.tool_fail("Desired source MAF type has not been specified.")
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
105
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
106 # Create MAF writter
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
107 out = bx.align.maf.Writer(open(output_file, "w"))
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
108
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
109 # Iterate over input regions
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
110 num_blocks = 0
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
111 num_regions = None
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
112 for num_regions, region in enumerate(bx.intervals.io.NiceReaderWrapper(open(interval_file, 'r'), chrom_col=chromCol, start_col=startCol, end_col=endCol, strand_col=strandCol, fix_strand=True, return_header=False, return_comments=False)):
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
113 src = maf_utilities.src_merge(dbkey, region.chrom)
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
114 for block in index.get_as_iterator(src, region.start, region.end):
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
115 if split_blocks_by_species:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
116 blocks = [new_block for new_block in maf_utilities.iter_blocks_split_by_species(block) if maf_utilities.component_overlaps_region(new_block.get_component_by_src_start(dbkey), region)]
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
117 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
118 blocks = [block]
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
119 for block in blocks:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
120 block = maf_utilities.chop_block_by_region(block, src, region)
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
121 if block is not None:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
122 if species is not None:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
123 block = block.limit_to_species(species)
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
124 block = maf_utilities.orient_block_by_region(block, src, region)
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
125 if remove_all_gap_columns:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
126 block.remove_all_gap_columns()
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
127 out.write(block)
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
128 num_blocks += 1
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
129
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
130 # Close output MAF
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
131 out.close()
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
132
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
133 # remove index file if created during run
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
134 maf_utilities.remove_temp_index_file(index_filename)
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
135
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
136 if num_blocks:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
137 print("%i MAF blocks extracted for %i regions." % (num_blocks, (num_regions + 1)))
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
138 elif num_regions is not None:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
139 print("No MAF blocks could be extracted for %i regions." % (num_regions + 1))
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
140 else:
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
141 print("No valid regions have been provided.")
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
142
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
143
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
144 if __name__ == "__main__":
cfea1d6354db "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/interval2maf/ commit 1db2b3ee758847b8b63f58fb2075961003ff8c22"
iuc
parents:
diff changeset
145 __main__()