annotate fimo_wrapper.py @ 1:d20e391eb22f draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
author iuc
date Tue, 22 Dec 2015 17:02:11 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
1 #!/usr/bin/env python
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
2 import argparse
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
3 import os
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
4 import shutil
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
5 import string
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
6 import subprocess
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
7 import sys
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
8 import tempfile
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
9
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
10 BUFFSIZE = 1048576
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
11 # Translation table for reverse Complement, with ambiguity codes.
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
12 DNA_COMPLEMENT = string.maketrans("ACGTRYKMBDHVacgtrykmbdhv", "TGCAYRMKVHDBtgcayrmkvhdb")
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
13
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
14
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
15 def reverse(sequence):
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
16 # Reverse sequence string.
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
17 return sequence[::-1]
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
18
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
19
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
20 def dna_complement(sequence):
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
21 # Complement DNA sequence string.
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
22 return sequence.translate(DNA_COMPLEMENT)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
23
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
24
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
25 def dna_reverse_complement(sequence):
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
26 # Returns the reverse complement of the sequence.
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
27 sequence = reverse(sequence)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
28 return dna_complement(sequence)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
29
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
30
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
31 def stop_err(msg):
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
32 sys.stderr.write(msg)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
33 sys.exit(1)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
34
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
35 parser = argparse.ArgumentParser()
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
36 parser.add_argument('--input_motifs', dest='input_motifs', help='MEME output formatted files for input to fimo')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
37 parser.add_argument('--input_fasta', dest='input_fasta', help='Fassta sequence file')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
38 parser.add_argument('--options_type', dest='options_type', help='Basic or Advance options')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
39 parser.add_argument('--input_psp', dest='input_psp', default=None, help='File containing position specific priors')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
40 parser.add_argument('--input_prior_dist', dest='input_prior_dist', default=None, help='File containing binned distribution of priors')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
41 parser.add_argument('--alpha', dest='alpha', type=float, default=1.0, help='The alpha parameter for calculating position specific priors')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
42 parser.add_argument('--bgfile', dest='bgfile', default=None, help='Background file type, used only if not "default"')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
43 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')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
44 parser.add_argument('--max_stored_scores', dest='max_stored_scores', type=int, help='Maximum score count to store')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
45 parser.add_argument('--motif', dest='motifs', action='append', default=[], help='Specify motif by id')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
46 parser.add_argument('--motif_pseudo', dest='motif_pseudo', type=float, default=0.1, help='Pseudocount to add to counts in motif matrix')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
47 parser.add_argument('--no_qvalue', action='store_true', help='Do not compute a q-value for each p-value')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
48 parser.add_argument('--norc', action='store_true', help='Do not score the reverse complement DNA strand')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
49 parser.add_argument('--output_path', dest='output_path', help='Output files directory')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
50 parser.add_argument('--parse_genomic_coord', action='store_true', help='Check each sequence header for UCSC style genomic coordinates')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
51 parser.add_argument('--qv_thresh', action='store_true', help='Use q-values for the output threshold')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
52 parser.add_argument('--thresh', dest='thresh', type=float, help='p-value threshold')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
53 parser.add_argument('--gff_output', dest='gff_output', help='Gff output file')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
54 parser.add_argument('--html_output', dest='html_output', help='HTML output file')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
55 parser.add_argument('--interval_output', dest='interval_output', help='Interval output file')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
56 parser.add_argument('--txt_output', dest='txt_output', help='Text output file')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
57 parser.add_argument('--xml_output', dest='xml_output', help='XML output file')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
58 args = parser.parse_args()
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
59
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
60 fimo_cmd_list = ['fimo']
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
61 if args.options_type == 'advanced':
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
62 fimo_cmd_list.append('--alpha %4f' % args.alpha)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
63 if args.bgfile is not None:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
64 fimo_cmd_list.append('--bgfile "%s"' % args.bgfile)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
65 if args.max_strand:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
66 fimo_cmd_list.append('--max-strand')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
67 fimo_cmd_list.append('--max-stored-scores %d' % args.max_stored_scores)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
68 if len(args.motifs) > 0:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
69 for motif in args.motifs:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
70 fimo_cmd_list.append('--motif "%s"' % motif)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
71 fimo_cmd_list.append('--motif-pseudo %4f' % args.motif_pseudo)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
72 if args.no_qvalue:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
73 fimo_cmd_list.append('--no-qvalue')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
74 if args.norc:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
75 fimo_cmd_list.append('--norc')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
76 if args.parse_genomic_coord:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
77 fimo_cmd_list.append('--parse-genomic-coord')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
78 if args.qv_thresh:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
79 fimo_cmd_list.append('--qv-thresh')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
80 fimo_cmd_list.append('--thresh %4f' % args.thresh)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
81 if args.input_psp is not None:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
82 fimo_cmd_list.append('--psp "%s"' % args.input_psp)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
83 if args.input_prior_dist is not None:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
84 fimo_cmd_list.append('--prior-dist "%s"' % args.input_prior_dist)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
85 fimo_cmd_list.append('--o "%s"' % (args.output_path))
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
86 fimo_cmd_list.append('--verbosity 1')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
87 fimo_cmd_list.append(args.input_motifs)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
88 fimo_cmd_list.append(args.input_fasta)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
89
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
90 fimo_cmd = ' '.join(fimo_cmd_list)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
91
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
92 try:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
93 tmp_stderr = tempfile.NamedTemporaryFile()
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
94 proc = subprocess.Popen(args=fimo_cmd, shell=True, stderr=tmp_stderr)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
95 returncode = proc.wait()
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
96 tmp_stderr.seek(0)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
97 stderr = ''
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
98 try:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
99 while True:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
100 stderr += tmp_stderr.read(BUFFSIZE)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
101 if not stderr or len(stderr) % BUFFSIZE != 0:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
102 break
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
103 except OverflowError:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
104 pass
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
105 if returncode != 0:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
106 stop_err(stderr)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
107 except Exception, e:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
108 stop_err('Error running FIMO:\n%s' % str(e))
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
109
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
110 shutil.move(os.path.join(args.output_path, 'fimo.txt'), args.txt_output)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
111 shutil.move(os.path.join(args.output_path, 'fimo.gff'), args.gff_output)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
112 shutil.move(os.path.join(args.output_path, 'fimo.xml'), args.xml_output)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
113 shutil.move(os.path.join(args.output_path, 'fimo.html'), args.html_output)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
114
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
115 out_file = open(args.interval_output, 'wb')
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
116 out_file.write("#%s\n" % "\t".join(("chr", "start", "end", "pattern name", "score", "strand", "matched sequence", "p-value", "q-value")))
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
117 for line in open(args.txt_output):
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
118 if line.startswith('#'):
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
119 continue
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
120 fields = line.rstrip("\n\r").split("\t")
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
121 start, end = int(fields[2]), int(fields[3])
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
122 sequence = fields[7]
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
123 if start > end:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
124 # Flip start and end and set strand.
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
125 start, end = end, start
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
126 strand = "-"
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
127 # We want sequences relative to strand; FIMO always provides + stranded sequence.
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
128 sequence = dna_reverse_complement(sequence)
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
129 else:
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
130 strand = "+"
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
131 # Make 0-based start position.
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
132 start -= 1
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
133 out_file.write("%s\n" % "\t".join([fields[1], str(start), str(end), fields[0], fields[4], strand, sequence, fields[5], fields[6]]))
d20e391eb22f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/meme commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
134 out_file.close()