annotate fimo_wrapper.py @ 0:a0fa4efeeee3 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
author iuc
date Wed, 23 Aug 2017 20:57:34 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
1 #!/usr/bin/env python
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
2 import argparse
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
3 import os
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
4 import shutil
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
5 import string
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
6 import subprocess
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
7 import sys
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
8 import tempfile
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
9
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
10 BUFFSIZE = 1048576
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
11 # Translation table for reverse Complement, with ambiguity codes.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
12 DNA_COMPLEMENT = string.maketrans("ACGTRYKMBDHVacgtrykmbdhv", "TGCAYRMKVHDBtgcayrmkvhdb")
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
13
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
14
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
15 def get_stderr(tmp_stderr):
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
16 tmp_stderr.seek(0)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
17 stderr = ''
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
18 try:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
19 while True:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
20 stderr += tmp_stderr.read(BUFFSIZE)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
21 if not stderr or len(stderr) % BUFFSIZE != 0:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
22 break
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
23 except OverflowError:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
24 pass
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
25 return stderr
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
26
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
27
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
28 def reverse(sequence):
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
29 # Reverse sequence string.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
30 return sequence[::-1]
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
31
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
32
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
33 def dna_complement(sequence):
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
34 # Complement DNA sequence string.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
35 return sequence.translate(DNA_COMPLEMENT)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
36
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
37
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
38 def dna_reverse_complement(sequence):
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
39 # Returns the reverse complement of the sequence.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
40 sequence = reverse(sequence)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
41 return dna_complement(sequence)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
42
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
43
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
44 def stop_err(msg):
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
45 sys.stderr.write(msg)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
46 sys.exit(1)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
47
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
48
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
49 parser = argparse.ArgumentParser()
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
50 parser.add_argument('--input_motifs', dest='input_motifs', help='MEME output formatted files for input to fimo')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
51 parser.add_argument('--input_fasta', dest='input_fasta', help='Fassta sequence file')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
52 parser.add_argument('--options_type', dest='options_type', help='Basic or Advance options')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
53 parser.add_argument('--input_psp', dest='input_psp', default=None, help='File containing position specific priors')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
54 parser.add_argument('--input_prior_dist', dest='input_prior_dist', default=None, help='File containing binned distribution of priors')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
55 parser.add_argument('--alpha', dest='alpha', type=float, default=1.0, help='The alpha parameter for calculating position specific priors')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
56 parser.add_argument('--bgfile', dest='bgfile', default=None, help='Background file type, used only if not "default"')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
57 parser.add_argument('--max_strand', action='store_true', help='If matches on both strands at a given position satisfy the output threshold, only report the match for the strand with the higher score')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
58 parser.add_argument('--max_stored_scores', dest='max_stored_scores', type=int, help='Maximum score count to store')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
59 parser.add_argument('--motif', dest='motifs', action='append', default=[], help='Specify motif by id')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
60 parser.add_argument('--output_separate_motifs', dest='output_separate_motifs', default='no', help='Output one dataset per motif')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
61 parser.add_argument('--motif_pseudo', dest='motif_pseudo', type=float, default=0.1, help='Pseudocount to add to counts in motif matrix')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
62 parser.add_argument('--no_qvalue', action='store_true', help='Do not compute a q-value for each p-value')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
63 parser.add_argument('--norc', action='store_true', help='Do not score the reverse complement DNA strand')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
64 parser.add_argument('--output_path', dest='output_path', help='Output files directory')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
65 parser.add_argument('--parse_genomic_coord', dest='parse_genomic_coord', default='no', help='Check each sequence header for UCSC style genomic coordinates')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
66 parser.add_argument('--remove_duplicate_coords', dest='remove_duplicate_coords', default='no', help='Remove duplicate entries in unique GFF coordinates')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
67 parser.add_argument('--qv_thresh', action='store_true', help='Use q-values for the output threshold')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
68 parser.add_argument('--thresh', dest='thresh', type=float, help='p-value threshold')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
69 parser.add_argument('--gff_output', dest='gff_output', help='Gff output file')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
70 parser.add_argument('--html_output', dest='html_output', help='HTML output file')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
71 parser.add_argument('--interval_output', dest='interval_output', help='Interval output file')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
72 parser.add_argument('--txt_output', dest='txt_output', help='Text output file')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
73 parser.add_argument('--xml_output', dest='xml_output', help='XML output file')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
74 args = parser.parse_args()
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
75
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
76 fimo_cmd_list = ['fimo']
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
77 if args.options_type == 'advanced':
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
78 fimo_cmd_list.append('--alpha %4f' % args.alpha)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
79 if args.bgfile is not None:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
80 fimo_cmd_list.append('--bgfile "%s"' % args.bgfile)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
81 if args.max_strand:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
82 fimo_cmd_list.append('--max-strand')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
83 fimo_cmd_list.append('--max-stored-scores %d' % args.max_stored_scores)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
84 if len(args.motifs) > 0:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
85 for motif in args.motifs:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
86 fimo_cmd_list.append('--motif "%s"' % motif)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
87 fimo_cmd_list.append('--motif-pseudo %4f' % args.motif_pseudo)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
88 if args.no_qvalue:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
89 fimo_cmd_list.append('--no-qvalue')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
90 if args.norc:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
91 fimo_cmd_list.append('--norc')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
92 if args.parse_genomic_coord == 'yes':
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
93 fimo_cmd_list.append('--parse-genomic-coord')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
94 if args.qv_thresh:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
95 fimo_cmd_list.append('--qv-thresh')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
96 fimo_cmd_list.append('--thresh %4f' % args.thresh)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
97 if args.input_psp is not None:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
98 fimo_cmd_list.append('--psp "%s"' % args.input_psp)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
99 if args.input_prior_dist is not None:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
100 fimo_cmd_list.append('--prior-dist "%s"' % args.input_prior_dist)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
101 fimo_cmd_list.append('--o "%s"' % (args.output_path))
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
102 fimo_cmd_list.append('--verbosity 1')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
103 fimo_cmd_list.append(args.input_motifs)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
104 fimo_cmd_list.append(args.input_fasta)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
105
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
106 fimo_cmd = ' '.join(fimo_cmd_list)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
107
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
108 try:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
109 tmp_stderr = tempfile.NamedTemporaryFile()
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
110 proc = subprocess.Popen(args=fimo_cmd, shell=True, stderr=tmp_stderr)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
111 returncode = proc.wait()
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
112 if returncode != 0:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
113 stderr = get_stderr(tmp_stderr)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
114 stop_err(stderr)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
115 except Exception as e:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
116 stop_err('Error running FIMO:\n%s' % e)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
117
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
118 shutil.move(os.path.join(args.output_path, 'fimo.txt'), args.txt_output)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
119
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
120 gff_file = os.path.join(args.output_path, 'fimo.gff')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
121 if args.remove_duplicate_coords == 'yes':
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
122 tmp_stderr = tempfile.NamedTemporaryFile()
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
123 # Identify and eliminating identical motif occurrences. These
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
124 # are identical if the combination of chrom, start, end and
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
125 # motif id are identical.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
126 cmd = 'sort -k1,1 -k4,4n -k5,5n -k9.1,9.6 -u -o %s %s' % (gff_file, gff_file)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
127 proc = subprocess.Popen(args=cmd, stderr=tmp_stderr, shell=True)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
128 returncode = proc.wait()
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
129 if returncode != 0:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
130 stderr = get_stderr(tmp_stderr)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
131 stop_err(stderr)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
132 # Sort GFF output by a combination of chrom, score, start.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
133 cmd = 'sort -k1,1 -k4,4n -k6,6n -o %s %s' % (gff_file, gff_file)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
134 proc = subprocess.Popen(args=cmd, stderr=tmp_stderr, shell=True)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
135 returncode = proc.wait()
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
136 if returncode != 0:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
137 stderr = get_stderr(tmp_stderr)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
138 stop_err(stderr)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
139 if args.output_separate_motifs == 'yes':
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
140 # Create the collection output directory.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
141 collection_path = (os.path.join(os.getcwd(), 'output'))
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
142 # Keep track of motif occurrences.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
143 header_line = None
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
144 motif_ids = []
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
145 file_handles = []
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
146 for line in open(gff_file, 'r'):
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
147 if line.startswith('#'):
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
148 if header_line is None:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
149 header_line = line
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
150 continue
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
151 items = line.split('\t')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
152 attribute = items[8]
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
153 attributes = attribute.split(';')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
154 name = attributes[0]
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
155 motif_id = name.split('=')[1]
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
156 file_name = os.path.join(collection_path, 'MOTIF%s.gff' % motif_id)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
157 if motif_id in motif_ids:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
158 i = motif_ids.index(motif_id)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
159 fh = file_handles[i]
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
160 fh.write(line)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
161 else:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
162 fh = open(file_name, 'wb')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
163 if header_line is not None:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
164 fh.write(header_line)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
165 fh.write(line)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
166 motif_ids.append(motif_id)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
167 file_handles.append(fh)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
168 for file_handle in file_handles:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
169 file_handle.close()
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
170 else:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
171 shutil.move(gff_file, args.gff_output)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
172 shutil.move(os.path.join(args.output_path, 'fimo.xml'), args.xml_output)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
173 shutil.move(os.path.join(args.output_path, 'fimo.html'), args.html_output)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
174
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
175 out_file = open(args.interval_output, 'wb')
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
176 out_file.write("#%s\n" % "\t".join(("chr", "start", "end", "pattern name", "score", "strand", "matched sequence", "p-value", "q-value")))
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
177 for line in open(args.txt_output):
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
178 if line.startswith('#'):
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
179 continue
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
180 fields = line.rstrip("\n\r").split("\t")
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
181 start, end = int(fields[2]), int(fields[3])
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
182 sequence = fields[7]
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
183 if start > end:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
184 # Flip start and end and set strand.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
185 start, end = end, start
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
186 strand = "-"
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
187 # We want sequences relative to strand; FIMO always provides + stranded sequence.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
188 sequence = dna_reverse_complement(sequence)
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
189 else:
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
190 strand = "+"
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
191 # Make 0-based start position.
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
192 start -= 1
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
193 out_file.write("%s\n" % "\t".join([fields[1], str(start), str(end), fields[0], fields[4], strand, sequence, fields[5], fields[6]]))
a0fa4efeeee3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit 3f116ddc83447056068573320c148a9bfca9aa2e
iuc
parents:
diff changeset
194 out_file.close()