annotate STACKS_prepare_population_map.py @ 3:0e0ff9e9c761 default tip

fix inputs clean name
author cmonjeau
date Mon, 28 Sep 2015 13:21:35 +0000
parents d6ba40f6c824
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
1 #!/usr/bin/env python
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
2
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
3 import sys, re
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
4 import os
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
5 import tempfile
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
6 import shutil, subprocess, glob
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
7 import optparse
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
8 from os.path import basename
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
9 import zipfile, tarfile, gzip
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
10 from galaxy.datatypes.checkers import *
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
11 from stacks import *
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
12
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
13 """
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
14
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
15 Created by Cyril Monjeaud
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
16 Cyril.Monjeaud@irisa.fr
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
17
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
18 Last modifications : 01/10/2014
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
19
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
20 WARNING :
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
21
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
22 STACKS_denovomap.py needs:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
23
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
24 - STACKS scripts in your $PATH
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
25
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
26 These scripts are available after compiling the sources of STACKS :
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
27
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
28 http://creskolab.uoregon.edu/stacks/
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
29
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
30 or with the galaxy_stacks package in the Genouest toolshed (http://toolshed.genouest.org)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
31
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
32 """
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
33 def __main__():
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
34
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
35 # arguments recuperation
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
36 parser = optparse.OptionParser()
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
37 parser.add_option("-f")
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
38 parser.add_option("-s")
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
39 parser.add_option("-t")
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
40 parser.add_option("-o")
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
41 parser.add_option("-d")
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
42 (options, args) = parser.parse_args()
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
43
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
44 # create the working dir
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
45 tmp_dir = tempfile.mkdtemp(dir=options.d)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
46
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
47 print tmp_dir
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
48 #os.chdir(tmp_dir)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
49
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
50 # parse config files
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
51 tab_fq_files=galaxy_config_to_tabfiles_for_STACKS(options.f)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
52
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
53 # check if zipped files are into the tab and change tab content
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
54 extract_compress_files_from_tabfiles(tab_fq_files, tmp_dir)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
55
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
56 # generate population map for denovo map
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
57 if not options.s:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
58 generate_popmap_for_denovo(tab_fq_files, options.t, options.o)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
59 else:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
60 # parse config files
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
61 tab_sam_files=galaxy_config_to_tabfiles_for_STACKS(options.s)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
62 extract_compress_files_from_tabfiles(tab_sam_files, tmp_dir)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
63 generate_popmap_for_refmap(tab_fq_files, tab_sam_files, options.t, options.o)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
64
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
65
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
66 #clean up temp files
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
67 shutil.rmtree( tmp_dir )
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
68
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
69
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
70
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
71
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
72
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
73
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
74 if __name__ == "__main__": __main__()