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