annotate interval_maf_to_merged_fasta.py @ 1:0cb44bd983f8 draft default tip

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