Mercurial > repos > iuc > genebed_maf_to_fasta
annotate interval_maf_to_merged_fasta.py @ 0:f24a9ff28d3c draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
author | iuc |
---|---|
date | Fri, 21 Aug 2020 15:10:13 -0400 |
parents | |
children |
rev | line source |
---|---|
0
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
2 """ |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
3 Reads an interval or gene BED and a MAF Source. |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
4 Produces a FASTA file containing the aligned intervals/gene sequences, based upon the provided coordinates |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
5 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
6 Alignment blocks are layered ontop of each other based upon score. |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
7 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
8 usage: %prog maf_file [options] |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
9 -d, --dbkey=d: Database key, ie hg17 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
10 -c, --chromCol=c: Column of Chr |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
11 -s, --startCol=s: Column of Start |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
12 -e, --endCol=e: Column of End |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
13 -S, --strandCol=S: Column of Strand |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
14 -G, --geneBED: Input is a Gene BED file, process and join exons as one region |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
15 -t, --mafSourceType=t: Type of MAF source to use |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
16 -m, --mafSource=m: Path of source MAF file, if not using cached version |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
17 -I, --mafIndex=I: Path of precomputed source MAF file index, if not using cached version |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
18 -i, --interval_file=i: Input interval file |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
19 -o, --output_file=o: Output MAF file |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
20 -p, --species=p: Species to include in output |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
21 -O, --overwrite_with_gaps=O: Overwrite bases found in a lower-scoring block with gaps interior to the sequence for a species. |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
22 -z, --mafIndexFileDir=z: Directory of local maf_index.loc file |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
23 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
24 usage: %prog dbkey_of_BED comma_separated_list_of_additional_dbkeys_to_extract comma_separated_list_of_indexed_maf_files input_gene_bed_file output_fasta_file cached|user GALAXY_DATA_INDEX_DIR |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
25 """ |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
26 # Dan Blankenberg |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
27 from __future__ import print_function |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
28 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
29 import sys |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
30 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
31 import bx.intervals.io |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
32 from bx.cookbook import doc_optparse |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
33 from galaxy.tools.util import maf_utilities |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
34 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
35 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
36 def stop_err(msg): |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
37 sys.exit(msg) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
38 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
39 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
40 def __main__(): |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
41 # Parse Command Line |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
42 options, args = doc_optparse.parse(__doc__) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
43 mincols = 0 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
44 strand_col = -1 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
45 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
46 if options.dbkey: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
47 primary_species = options.dbkey |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
48 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
49 primary_species = None |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
50 if primary_species in [None, "?", "None"]: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
51 stop_err("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.") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
52 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
53 include_primary = True |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
54 secondary_species = maf_utilities.parse_species_option(options.species) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
55 if secondary_species: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
56 species = list(secondary_species) # make copy of species list |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
57 if primary_species in secondary_species: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
58 secondary_species.remove(primary_species) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
59 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
60 include_primary = False |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
61 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
62 species = None |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
63 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
64 if options.interval_file: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
65 interval_file = options.interval_file |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
66 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
67 stop_err("Input interval file has not been specified.") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
68 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
69 if options.output_file: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
70 output_file = options.output_file |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
71 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
72 stop_err("Output file has not been specified.") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
73 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
74 if not options.geneBED: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
75 if options.chromCol: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
76 chr_col = int(options.chromCol) - 1 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
77 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
78 stop_err("Chromosome column not set, click the pencil icon in the history item to set the metadata attributes.") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
79 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
80 if options.startCol: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
81 start_col = int(options.startCol) - 1 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
82 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
83 stop_err("Start column not set, click the pencil icon in the history item to set the metadata attributes.") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
84 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
85 if options.endCol: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
86 end_col = int(options.endCol) - 1 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
87 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
88 stop_err("End column not set, click the pencil icon in the history item to set the metadata attributes.") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
89 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
90 if options.strandCol: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
91 strand_col = int(options.strandCol) - 1 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
92 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
93 mafIndexFile = "%s/maf_indexes.loc" % options.mafIndexFileDir |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
94 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
95 overwrite_with_gaps = True |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
96 if options.overwrite_with_gaps and options.overwrite_with_gaps.lower() == 'false': |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
97 overwrite_with_gaps = False |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
98 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
99 # Finish parsing command line |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
100 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
101 # get index for mafs based on type |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
102 index = index_filename = None |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
103 # using specified uid for locally cached |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
104 if options.mafSourceType.lower() in ["cached"]: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
105 index = maf_utilities.maf_index_by_uid(options.mafSource, mafIndexFile) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
106 if index is None: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
107 stop_err("The MAF source specified (%s) appears to be invalid." % (options.mafSource)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
108 elif options.mafSourceType.lower() in ["user"]: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
109 # index maf for use here, need to remove index_file when finished |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
110 index, index_filename = maf_utilities.open_or_build_maf_index(options.mafSource, options.mafIndex, species=[primary_species]) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
111 if index is None: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
112 stop_err("Your MAF file appears to be malformed.") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
113 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
114 stop_err("Invalid MAF source type specified.") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
115 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
116 # open output file |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
117 output = open(output_file, "w") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
118 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
119 if options.geneBED: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
120 region_enumerator = maf_utilities.line_enumerator(open(interval_file, "r").readlines()) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
121 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
122 region_enumerator = enumerate(bx.intervals.io.NiceReaderWrapper( |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
123 open(interval_file, 'r'), chrom_col=chr_col, start_col=start_col, |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
124 end_col=end_col, strand_col=strand_col, fix_strand=True, |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
125 return_header=False, return_comments=False)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
126 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
127 # Step through intervals |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
128 regions_extracted = 0 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
129 line_count = 0 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
130 for line_count, line in region_enumerator: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
131 try: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
132 if options.geneBED: # Process as Gene BED |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
133 try: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
134 starts, ends, fields = maf_utilities.get_starts_ends_fields_from_gene_bed(line) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
135 # create spliced alignment object |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
136 alignment = maf_utilities.get_spliced_region_alignment( |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
137 index, primary_species, fields[0], starts, ends, |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
138 strand='+', species=species, mincols=mincols, |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
139 overwrite_with_gaps=overwrite_with_gaps) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
140 except Exception as e: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
141 print(e) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
142 try: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
143 primary_name = secondary_name = fields[3] |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
144 alignment_strand = fields[5] |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
145 except Exception as e: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
146 print("Error loading exon positions from input line %i: %s" % (line_count, e)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
147 continue |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
148 else: # Process as standard intervals |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
149 try: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
150 # create spliced alignment object |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
151 alignment = maf_utilities.get_region_alignment( |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
152 index, primary_species, line.chrom, line.start, |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
153 line.end, strand='+', species=species, mincols=mincols, |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
154 overwrite_with_gaps=overwrite_with_gaps) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
155 primary_name = "%s(%s):%s-%s" % (line.chrom, line.strand, line.start, line.end) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
156 secondary_name = "" |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
157 alignment_strand = line.strand |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
158 except Exception as e: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
159 print("Error loading region positions from input line %i: %s" % (line_count, e.__dict__)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
160 continue |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
161 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
162 # Write alignment to output file |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
163 # Output primary species first, if requested |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
164 if include_primary: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
165 output.write(">%s.%s\n" % (primary_species, primary_name)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
166 if alignment_strand == "-": |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
167 output.write(alignment.get_sequence_reverse_complement(primary_species)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
168 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
169 output.write(alignment.get_sequence(primary_species)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
170 output.write("\n") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
171 # Output all remainging species |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
172 for spec in secondary_species or alignment.get_species_names(skip=primary_species): |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
173 if secondary_name: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
174 output.write(">%s.%s\n" % (spec, secondary_name)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
175 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
176 output.write(">%s\n" % (spec)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
177 if alignment_strand == "-": |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
178 output.write(alignment.get_sequence_reverse_complement(spec)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
179 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
180 output.write(alignment.get_sequence(spec)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
181 output.write("\n") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
182 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
183 output.write("\n") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
184 regions_extracted += 1 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
185 except Exception as e: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
186 print("Unexpected error from input line %i: %s\n%s" % (line_count, e, line)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
187 raise |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
188 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
189 # close output file |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
190 output.close() |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
191 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
192 # remove index file if created during run |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
193 maf_utilities.remove_temp_index_file(index_filename) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
194 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
195 # Print message about success for user |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
196 if regions_extracted > 0: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
197 print("%i regions were processed successfully." % (regions_extracted)) |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
198 else: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
199 print("No regions were processed successfully.") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
200 if line_count > 0 and options.geneBED: |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
201 print("This tool requires your input file to conform to the 12 column BED standard.") |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
202 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
203 |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
204 if __name__ == "__main__": |
f24a9ff28d3c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genebed_maf_to_fasta/ commit 17e2194066ca843f6b2391a9632ea9de67d39351"
iuc
parents:
diff
changeset
|
205 __main__() |