annotate tmap_wrapper_0.0.19/tmap_wrapper.py @ 1:40ade4f81a30 default tip

Uploaded tool_data_table_conf.xml.sample
author nate
date Fri, 23 Sep 2011 14:53:08 -0400
parents 7cbfd271d207
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
1 #!/usr/bin/env python
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
2
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
3 # TODO
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
4 # - map1/map2/map3 specific options
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
5
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
6 """
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
7 Runs TMAP on Ion Torrent data.
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
8 Produces a SAM file containing the mappings.
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
9 Works with TMAP version 0.0.19 or higher.
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
10
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
11 usage: tmap_wrapper.py [options]
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
12 --threads: The number of threads to use
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
13 --ref: The reference genome to use or index
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
14 --fastq: The fastq file to use for the mapping
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
15 --output: The file to save the output (SAM format)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
16 --params: Parameter setting to use (pre_set or full)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
17 --fileSource: Whether to use a previously indexed reference sequence or one from history (indexed or history)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
18 --matchScore: The match score
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
19 --mismatchPenalty: The ismatch penalty
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
20 --gapOpenPenalty: The gap open penalty
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
21 --gapExtensPenalty: The gap extension penalty
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
22 --flowPenalty: The flow score penalty
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
23 --flowOrder: The flow order ([ACGT]{4+} or "sff")
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
24 --bandWidth: The band width
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
25 --globalMap: The soft-clipping type (0 - allow on the right and left, 1 - allow on the left, 2 - allow on the right, 3 - do not allow soft-clipping)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
26 --duplicateWindow: Remove duplicate alignments from different algorithms within this bp window (-1 to disable)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
27 --scoringThreshold: The score threshold divided by the match score
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
28 --queueSize: The queue size for the reads
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
29 --outputFilter: The output filter (0 - unique best hits, 1 - random best hit, 2 - all best htis, 3 - all alignments)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
30 --rgTag: The flag to specify RG tag(s) in the SAM header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
31 --rgTagID: The RG ID tag to add to the SAM header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
32 --rgTagCN: The RG CN tag to add to the SAM header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
33 --rgTagDS: The RG DS tag to add to the SAM header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
34 --rgTagDT: The RG DT tag to add to the SAM header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
35 --rgTagLB: The RG LB tag to add to the SAM header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
36 --rgTagPI: The RG PI tag to add to the SAM header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
37 --rgTagPL: The RG PL tag to add to the SAM header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
38 --rgTagPU: The RG PU tag to add to the SAM header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
39 --rgTagSM: The RG SM tag to add to the SAM header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
40 --filterIndependently: Apply the output filter for each algorithm independently
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
41
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
42 --map1: Flag to run map1 in the first stage
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
43 --map1SeedLength: The k-mer length to seed CALs (-1 to disable)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
44 --map1SeedMismatches: The maximum number of mismatches in the seed
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
45 --map1SecondarySeedLength: The secondary seed length (-1 to disable)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
46 --map1NumEdits: The maximum number of edits or false-negative probability assuming the maximum error rate
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
47 --map1BaseError: The assumed per-base maximum error rate
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
48 --map1Mismatches: The maximum number of or (read length) fraction of mismatches
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
49 --map1GapOpens: The maximum number of or (read length) fraction of indel starts
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
50 --map1GapExtensions: The maximum number of or (read length) fraction of indel extensions
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
51 --map1MaxCALsDeletion: The maximum number of CALs to extend a deletion
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
52 --map1EndIndels: Indels are not allowed within this number of bps from the end of the read
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
53 --map1MaxOptimalCALs: Stop searching when INT optimal CALs have been found
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
54 --map1MaxNodes: The maximum number of alignment nodes
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
55
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
56 --map2: Flag to run map2 in the first stage
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
57 --map2Coefficient: The coefficient of length-threshold adjustment
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
58 --map2SeedIntervalSize: The maximum seeding interval size
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
59 --map2ZBest: Keep the z-best nodes during prefix trie traversal
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
60 --map2ReverseTrigger: The # seeds to trigger reverse alignment
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
61
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
62 --map3: Flag to run map3 in the first stage
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
63 --map3SeedLength: The k-mer length to seed CALs (-1 tunes to the genome size)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
64 --map3SeedMaxHits: The maximum number of hits returned by a seed
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
65 --map3SeedWindow: The window of bases in which to group seeds
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
66 --map3HPEnumeration: The single homopolymer error difference for enumeration
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
67
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
68 --MAP1: Flag to run MAP1 in the second stage
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
69 --MAP1SeedLength: The k-mer length to seed CALs (-1 to disable)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
70 --MAP1SeedMismatches: The maximum number of mismatches in the seed
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
71 --MAP1SecondarySeedLength: The secondary seed length (-1 to disable)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
72 --MAP1NumEdits: The maximum number of edits or false-negative probability assuming the maximum error rate
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
73 --MAP1BaseError: The assumed per-base maximum error rate
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
74 --MAP1Mismatches: The maximum number of or (read length) fraction of mismatches
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
75 --MAP1GapOpens: The maximum number of or (read length) fraction of indel starts
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
76 --MAP1GapExtensions: The maximum number of or (read length) fraction of indel extensions
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
77 --MAP1MaxCALsDeletion: The maximum number of CALs to extend a deletion
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
78 --MAP1EndIndels: Indels are not allowed within this number of bps from the end of the read
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
79 --MAP1MaxOptimalCALs: Stop searching when INT optimal CALs have been found
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
80 --MAP1MaxNodes: The maximum number of alignment nodes
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
81
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
82 --MAP2: Flag to run MAP2 in the second stage
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
83 --MAP2Coefficient: The coefficient of length-threshold adjustment
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
84 --MAP2SeedIntervalSize: The maximum seeding interval size
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
85 --MAP2ZBest: Keep the z-best nodes during prefix trie traversal
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
86 --MAP2ReverseTrigger: The # seeds to trigger reverse alignment
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
87
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
88 --MAP3: Flag to run MAP3 in the second stage
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
89 --MAP3SeedLength: The k-mer length to seed CALs (-1 tunes to the genome size)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
90 --MAP3SeedMaxHits: The maximum number of hits returned by a seed
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
91 --MAP3SeedWindow: The window of bases in which to group seeds
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
92 --MAP3HPEnumeration: The single homopolymer error difference for enumeration
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
93
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
94 --suppressHeader: Suppress header
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
95 --dbkey: Dbkey for reference genome
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
96 --do_not_build_index: Flag to specify that provided file is already indexed and to just use 'as is'
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
97 """
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
98
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
99 import optparse, os, shutil, subprocess, sys, tempfile
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
100
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
101 def stop_err( msg ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
102 sys.stderr.write( '%s\n' % msg )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
103 sys.exit()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
104
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
105 def map1_parse( map1SeedLength, map1SeedMismatches, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
106 map1SecondarySeedLength, map1NumEdits, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
107 map1BaseError, map1Mismatches, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
108 map1GapOpens, map1GapExtensions, map1MaxCALsDeletion, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
109 map1EndIndels, map1MaxOptimalCALs, map1MaxNodes ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
110 return '-l %s -s %s -L %s -p %s -P %s -m %s -o %s -e %s -d %s -i %s -b %s -Q %s' % \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
111 (map1SeedLength, map1SeedMismatches, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
112 map1SecondarySeedLength, map1NumEdits, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
113 map1BaseError, map1Mismatches, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
114 map1GapOpens, map1GapExtensions, map1MaxCALsDeletion, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
115 map1EndIndels, map1MaxOptimalCALs, map1MaxNodes )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
116
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
117 def map2_parse( map2Coefficient, map2SeedIntervalSize, map2ZBest, map2ReverseTrigger ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
118 return '-c %s -S %s -b %s -N %s' % ( map2Coefficient, map2SeedIntervalSize, map2ZBest, map2ReverseTrigger )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
119
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
120 def map3_parse( map3SeedLength, map3SeedMaxHits, map3SeedWindow, map3HPEnumeration ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
121 return '-l %s -S %s -b %s -H %s' % ( map3SeedLength, map3SeedMaxHits, map3SeedWindow, map3HPEnumeration )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
122
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
123 def __main__():
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
124 #Parse Command Line
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
125 parser = optparse.OptionParser()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
126 # Global options
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
127 parser.add_option( '--threads', dest='threads', help='The number of threads to use' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
128 parser.add_option( '--ref', dest='ref', help='The reference genome to use or index' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
129 parser.add_option( '--fastq', dest='fastq', help='The fastq file to use for the mapping' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
130 parser.add_option( '--output', dest='output', help='The file to save the output (SAM format)' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
131 parser.add_option( '--params', dest='params', help='Parameter setting to use (pre_set or full)' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
132 parser.add_option( '--fileSource', dest='fileSource', help='Whether to use a previously indexed reference sequence or one from history (indexed or history)' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
133 parser.add_option( '--mapall', dest='mapall', help='Flag indicating if mapall options are present')
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
134 parser.add_option( '--matchScore', dest='matchScore', help='The match score' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
135 parser.add_option( '--mismatchPenalty', dest='mismatchPenalty', help='Mismatch penalty' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
136 parser.add_option( '--gapOpenPenalty', dest='gapOpenPenalty', help='Gap open penalty' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
137 parser.add_option( '--gapExtensPenalty', dest='gapExtensPenalty', help='Gap extension penalty' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
138 parser.add_option( '--flowPenalty', dest='flowPenalty', help='Flow score penalty' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
139 parser.add_option( '--flowOrder', dest='flowOrder', help='Flow order' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
140 parser.add_option( '--bandWidth', dest='bandWidth', help='The band width' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
141 parser.add_option( '--globalMap', dest='globalMap', help='Map the full read (no soft-clipping)' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
142 parser.add_option( '--duplicateWindow', dest='duplicateWindow', help='Remove duplicate alignments from different algorithms within this bp window (-1 to disable)' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
143 parser.add_option( '--scoringThreshold', dest='scoringThreshold', help='The score threshold divided by the match score ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
144 parser.add_option( '--queueSize', dest='queueSize', help='The queue size for the reads' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
145 parser.add_option( '--outputFilter', dest='outputFilter', help='The output filter (0 - unique best hits, 1 - random best hit, 2 - all best htis, 3 - all alignments)' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
146 parser.add_option( '--rgTag', dest='rgTag', help='The flag to specify RG tag(s) in the SAM header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
147 parser.add_option( '--rgTagID', dest='rgTagID', default='', help='The RG ID to add to the SAM header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
148 parser.add_option( '--rgTagCN', dest='rgTagCN', default='', help='The RG CN to add to the SAM header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
149 parser.add_option( '--rgTagDS', dest='rgTagDS', default='', help='The RG DS to add to the SAM header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
150 parser.add_option( '--rgTagDT', dest='rgTagDT', default='', help='The RG DT to add to the SAM header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
151 parser.add_option( '--rgTagLB', dest='rgTagLB', default='', help='The RG LB to add to the SAM header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
152 parser.add_option( '--rgTagPI', dest='rgTagPI', default='', help='The RG PI to add to the SAM header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
153 parser.add_option( '--rgTagPL', dest='rgTagPL', default='', help='The RG PL to add to the SAM header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
154 parser.add_option( '--rgTagPU', dest='rgTagPU', default='', help='The RG PU to add to the SAM header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
155 parser.add_option( '--rgTagSM', dest='rgTagSM', default='', help='The RG SM to add to the SAM header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
156 parser.add_option( '--filterIndependently', dest='filterIndependently', help='Apply the output filter for each algorithm independently' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
157 parser.add_option( '--suppressHeader', dest='suppressHeader', help='Suppress header' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
158 parser.add_option( '--dbkey', dest='dbkey', help='Dbkey for reference genome' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
159 parser.add_option( '--do_not_build_index', dest='do_not_build_index', action='store_true', help="Don't build index" )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
160 # map 1 - stage 1
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
161 parser.add_option( '--map1', dest='map1', help='True if map1 should be run in the first stage' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
162 parser.add_option( '--map1SeedLength', dest='map1SeedLength', help='The k-mer length to seed CALs (-1 to disable)' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
163 parser.add_option( '--map1SeedMismatches', dest='map1SeedMismatches', help='The maximum number of mismatches in the seed ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
164 parser.add_option( '--map1SecondarySeedLength', dest='map1SecondarySeedLength', help='The secondary seed length (-1 to disable)' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
165 parser.add_option( '--map1NumEdits', dest='map1NumEdits', help='The maximum number of edits or false-negative probability assuming the maximum error rate' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
166 parser.add_option( '--map1BaseError', dest='map1BaseError', help='The assumed per-base maximum error rate' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
167 parser.add_option( '--map1Mismatches', dest='map1Mismatches', help='The maximum number of or (read length) fraction of mismatches ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
168 parser.add_option( '--map1GapOpens', dest='map1GapOpens', help='The maximum number of or (read length) fraction of indel starts ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
169 parser.add_option( '--map1GapExtensions', dest='map1GapExtensions', help='The maximum number of or (read length) fraction of indel extensions ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
170 parser.add_option( '--map1MaxCALsDeletion', dest='map1MaxCALsDeletion', help='The maximum number of CALs to extend a deletion ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
171 parser.add_option( '--map1EndIndels', dest='map1EndIndels', help='Indels are not allowed within this number of bps from the end of the read ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
172 parser.add_option( '--map1MaxOptimalCALs', dest='map1MaxOptimalCALs', help='Stop searching when INT optimal CALs have been found ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
173 parser.add_option( '--map1MaxNodes', dest='map1MaxNodes', help='The maximum number of alignment nodes ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
174 # map 2 - stage 1
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
175 parser.add_option( '--map2', dest='map2', help='True if map2 should be run in the first stage' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
176 parser.add_option( '--map2Coefficient', dest='map2Coefficient', help='The coefficient of length-threshold adjustment ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
177 parser.add_option( '--map2SeedIntervalSize', dest='map2SeedIntervalSize', help='The maximum seeding interval size ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
178 parser.add_option( '--map2ZBest', dest='map2ZBest', help='Keep the z-best nodes during prefix trie traversal' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
179 parser.add_option( '--map2ReverseTrigger', dest='map2ReverseTrigger', help='The # seeds to trigger reverse alignment ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
180 # map 3 - stage 1
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
181 parser.add_option( '--map3', dest='map3', help='True if map3 should be run in the first stage' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
182 parser.add_option( '--map3SeedLength', dest='map3SeedLength', help='The k-mer length to seed CALs (-1 tunes to the genome size) ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
183 parser.add_option( '--map3SeedMaxHits', dest='map3SeedMaxHits', help='The maximum number of hits returned by a seed ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
184 parser.add_option( '--map3SeedWindow', dest='map3SeedWindow', help='The window of bases in which to group seeds ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
185 parser.add_option( '--map3HPEnumeration', dest='map3HPEnumeration', help='The single homopolymer error difference for enumeration ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
186 # map 1 - stage 2
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
187 parser.add_option( '--MAP1', dest='MAP1', help='True if map1 should be run in the second stage' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
188 parser.add_option( '--MAP1SeedLength', dest='MAP1SeedLength', help='The k-mer length to seed CALs (-1 to disable)' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
189 parser.add_option( '--MAP1SeedMismatches', dest='MAP1SeedMismatches', help='The maximum number of mismatches in the seed ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
190 parser.add_option( '--MAP1SecondarySeedLength', dest='MAP1SecondarySeedLength', help='The secondary seed length (-1 to disable)' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
191 parser.add_option( '--MAP1NumEdits', dest='MAP1NumEdits', help='The maximum number of edits or false-negative probability assuming the maximum error rate' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
192 parser.add_option( '--MAP1BaseError', dest='MAP1BaseError', help='The assumed per-base maximum error rate' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
193 parser.add_option( '--MAP1Mismatches', dest='MAP1Mismatches', help='The maximum number of or (read length) fraction of mismatches ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
194 parser.add_option( '--MAP1GapOpens', dest='MAP1GapOpens', help='The maximum number of or (read length) fraction of indel starts ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
195 parser.add_option( '--MAP1GapExtensions', dest='MAP1GapExtensions', help='The maximum number of or (read length) fraction of indel extensions ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
196 parser.add_option( '--MAP1MaxCALsDeletion', dest='MAP1MaxCALsDeletion', help='The maximum number of CALs to extend a deletion ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
197 parser.add_option( '--MAP1EndIndels', dest='MAP1EndIndels', help='Indels are not allowed within this number of bps from the end of the read ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
198 parser.add_option( '--MAP1MaxOptimalCALs', dest='MAP1MaxOptimalCALs', help='Stop searching when INT optimal CALs have been found ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
199 parser.add_option( '--MAP1MaxNodes', dest='MAP1MaxNodes', help='The maximum number of alignment nodes ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
200 # map 2 - stage 2
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
201 parser.add_option( '--MAP2', dest='MAP2', help='True if map2 should be run in the second stage' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
202 parser.add_option( '--MAP2Coefficient', dest='MAP2Coefficient', help='The coefficient of length-threshold adjustment ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
203 parser.add_option( '--MAP2SeedIntervalSize', dest='MAP2SeedIntervalSize', help='The maximum seeding interval size ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
204 parser.add_option( '--MAP2ZBest', dest='MAP2ZBest', help='Keep the z-best nodes during prefix trie traversal' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
205 parser.add_option( '--MAP2ReverseTrigger', dest='MAP2ReverseTrigger', help='The # seeds to trigger reverse alignment ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
206 # map 3 - stage 2
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
207 parser.add_option( '--MAP3', dest='MAP3', help='True if map3 should be run in the second stage' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
208 parser.add_option( '--MAP3SeedLength', dest='MAP3SeedLength', help='The k-mer length to seed CALs (-1 tunes to the genome size) ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
209 parser.add_option( '--MAP3SeedMaxHits', dest='MAP3SeedMaxHits', help='The maximum number of hits returned by a seed ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
210 parser.add_option( '--MAP3SeedWindow', dest='MAP3SeedWindow', help='The window of bases in which to group seeds ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
211 parser.add_option( '--MAP3HPEnumeration', dest='MAP3HPEnumeration', help='The single homopolymer error difference for enumeration ' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
212 # parse the options
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
213 (options, args) = parser.parse_args()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
214
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
215 # output version # of tool
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
216 try:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
217 tmp = tempfile.NamedTemporaryFile().name
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
218 tmp_stdout = open( tmp, 'wb' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
219 proc = subprocess.Popen( args='tmap --version 2>&1', shell=True, stdout=tmp_stdout )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
220 tmp_stdout.close()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
221 returncode = proc.wait()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
222 stdout = None
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
223 for line in open( tmp_stdout.name, 'rb' ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
224 if line.lower().find( 'version' ) >= 0:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
225 stdout = line.strip()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
226 break
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
227 if stdout:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
228 sys.stdout.write( 'TMAP %s\n' % stdout )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
229 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
230 raise Exception
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
231 except:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
232 sys.stdout.write( 'Could not determine TMAP version\n' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
233
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
234 fastq = options.fastq
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
235
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
236 # make temp directory for placement of indices
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
237 tmp_index_dir = tempfile.mkdtemp()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
238 tmp_dir = tempfile.mkdtemp()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
239
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
240 # index if necessary
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
241 if options.fileSource == 'history' and not options.do_not_build_index:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
242 ref_file = tempfile.NamedTemporaryFile( dir=tmp_index_dir )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
243 ref_file_name = ref_file.name
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
244 ref_file.close()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
245 os.symlink( options.ref, ref_file_name )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
246 cmd1 = 'tmap index -f %s -v ' % ( ref_file_name )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
247 try:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
248 tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
249 tmp_stderr = open( tmp, 'wb' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
250 proc = subprocess.Popen( args=cmd1, shell=True, cwd=tmp_index_dir, stderr=tmp_stderr.fileno() )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
251 returncode = proc.wait()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
252 tmp_stderr.close()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
253 # get stderr, allowing for case where it's very large
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
254 tmp_stderr = open( tmp, 'rb' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
255 stderr = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
256 buffsize = 1048576
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
257 try:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
258 while True:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
259 stderr += tmp_stderr.read( buffsize )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
260 if not stderr or len( stderr ) % buffsize != 0:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
261 break
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
262 except OverflowError:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
263 pass
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
264 tmp_stderr.close()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
265 if returncode != 0:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
266 raise Exception, stderr
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
267 except Exception, e:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
268 # clean up temp dirs
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
269 if os.path.exists( tmp_index_dir ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
270 shutil.rmtree( tmp_index_dir )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
271 if os.path.exists( tmp_dir ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
272 shutil.rmtree( tmp_dir )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
273 stop_err( 'Error indexing reference sequence. ' + str( e ) )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
274 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
275 ref_file_name = options.ref
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
276
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
277 # set up mapping and generate mapping command options
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
278 if options.params == 'pre_set':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
279 mapall_options = '-n %s' % ( options.threads )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
280 map1_options = 'map1'
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
281 map2_options = 'map2'
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
282 map3_options = 'map3'
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
283 MAP1_options = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
284 MAP2_options = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
285 MAP3_options = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
286 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
287 # mapall options
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
288 if options.rgTag == 'true':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
289 rgTag = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
290 if options.rgTagID != '':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
291 rgTag += '-R "ID:' + options.rgTagID + '" '
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
292 if options.rgTagCN != '':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
293 rgTag += '-R "CN:' + options.rgTagCN + '" '
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
294 if options.rgTagDS != '':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
295 rgTag += '-R "DS:' + options.rgTagDS + '" '
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
296 if options.rgTagDT != '':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
297 rgTag += '-R "DT:' + options.rgTagDT + '" '
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
298 if options.rgTagLB != '':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
299 rgTag += '-R "LB:' + options.rgTagLB + '" '
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
300 if options.rgTagPI != '':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
301 rgTag += '-R "PI:' + options.rgTagPI + '" '
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
302 if options.rgTagPL != '':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
303 rgTag += '-R "PL:' + options.rgTagPL + '" '
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
304 if options.rgTagPU != '':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
305 rgTag += '-R "PU:' + options.rgTagPU + '" '
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
306 if options.rgTagSM != '':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
307 rgTag += '-R "SM:' + options.rgTagSM + '" '
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
308 rgTag.rstrip(' ')
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
309 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
310 rgTag = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
311 if None != options.flowOrder and '' != options.flowOrder:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
312 flowOrder = '-x ' + options.flowOrder
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
313 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
314 flowOrder = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
315 if options.filterIndependently == 'true':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
316 filterIndependently = '-I'
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
317 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
318 filterIndependently = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
319 if options.mapall == 'true':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
320 mapall_options = '-A %s -M %s -O %s -E %s -X %s %s %s -W %s -T %s -q %s -n %s -a %s %s %s' % \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
321 ( options.matchScore, options.mismatchPenalty, options.gapOpenPenalty, options.gapExtensPenalty,
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
322 options.flowPenalty, flowOrder,
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
323 options.globalMap, options.duplicateWindow, options.scoringThreshold, options.queueSize,
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
324 options.threads, options.outputFilter, rgTag, filterIndependently )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
325 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
326 mapall_options = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
327
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
328 # map1 - stage one
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
329 if options.map1 == 'true':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
330 map1_options = 'map1 %s' % \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
331 map1_parse( options.map1SeedLength, options.map1SeedMismatches, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
332 options.map1SecondarySeedLength, options.map1NumEdits, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
333 options.map1BaseError, options.map1Mismatches, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
334 options.map1GapOpens, options.map1GapExtensions, options.map1MaxCALsDeletion, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
335 options.map1EndIndels, options.map1MaxOptimalCALs, options.map1MaxNodes )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
336 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
337 map1_options = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
338 # map2 - stage one
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
339 if options.map2 == 'true':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
340 map2_options = 'map2 %s' % \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
341 map2_parse( options.map2Coefficient, options.map2SeedIntervalSize, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
342 options.map2ZBest, options.map2ReverseTrigger )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
343 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
344 map2_options = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
345 # map3 - stage one
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
346 if options.map3 == 'true':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
347 map3_options = 'map3 %s' % \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
348 map3_parse( options.map3SeedLength, options.map3SeedMaxHits, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
349 options.map3SeedWindow, options.map3HPEnumeration )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
350 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
351 map3_options = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
352 # map1 - stage two
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
353 if options.MAP1== 'true':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
354 MAP1_options = 'MAP1 %s' % \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
355 map1_parse( options.MAP1SeedLength, options.MAP1SeedMismatches, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
356 options.MAP1SecondarySeedLength, options.MAP1NumEdits, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
357 options.MAP1BaseError, options.MAP1Mismatches, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
358 options.MAP1GapOpens, options.MAP1GapExtensions, options.MAP1MaxCALsDeletion, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
359 options.MAP1EndIndels, options.MAP1MaxOptimalCALs, options.MAP1MaxNodes )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
360 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
361 MAP1_options = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
362 # map2 - stage two
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
363 if options.MAP2 == 'true':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
364 MAP2_options = 'MAP2 %s' % \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
365 map2_parse( options.MAP2Coefficient, options.MAP2SeedIntervalSize, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
366 options.MAP2ZBest, options.MAP2ReverseTrigger )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
367 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
368 MAP2_options = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
369 # map3 - stage two
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
370 if options.MAP3 == 'true':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
371 MAP3_options = 'MAP3 %s' % \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
372 MAP3_parse( options.MAP3SeedLength, options.MAP3SeedMaxHits, \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
373 options.MAP3SeedWindow, options.MAP3HPEnumeration )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
374 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
375 MAP3_options = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
376
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
377 #mapping_cmds
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
378 # prepare actual mapping and generate mapping commands
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
379 cmd2 = 'tmap mapall -f %s -r %s -F fastq %s -v %s %s %s %s %s %s > %s' % \
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
380 ( ref_file_name, fastq, mapall_options,
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
381 map1_options, map2_options, map3_options,
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
382 MAP1_options, MAP2_options, MAP3_options,
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
383 options.output )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
384 # perform alignments
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
385 buffsize = 1048576
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
386 try:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
387 # need to nest try-except in try-finally to handle 2.4
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
388 try:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
389 # align
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
390 try:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
391 tmp = tempfile.NamedTemporaryFile( dir=tmp_dir ).name
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
392 tmp_stderr = open( tmp, 'wb' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
393 proc = subprocess.Popen( args=cmd2, shell=True, cwd=tmp_dir, stderr=tmp_stderr.fileno() )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
394 returncode = proc.wait()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
395 tmp_stderr.close()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
396 # get stderr, allowing for case where it's very large
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
397 tmp_stderr = open( tmp, 'rb' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
398 stderr = ''
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
399 try:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
400 while True:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
401 stderr += tmp_stderr.read( buffsize )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
402 if not stderr or len( stderr ) % buffsize != 0:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
403 break
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
404 except OverflowError:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
405 pass
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
406 tmp_stderr.close()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
407 if returncode != 0:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
408 raise Exception, stderr
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
409 except Exception, e:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
410 raise Exception, 'Error mapping sequence. ' + str( e )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
411 # remove header if necessary
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
412 if options.suppressHeader == 'true':
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
413 tmp_out = tempfile.NamedTemporaryFile( dir=tmp_dir)
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
414 tmp_out_name = tmp_out.name
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
415 tmp_out.close()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
416 try:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
417 shutil.move( options.output, tmp_out_name )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
418 except Exception, e:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
419 raise Exception, 'Error moving output file before removing headers. ' + str( e )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
420 fout = file( options.output, 'w' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
421 for line in file( tmp_out.name, 'r' ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
422 if not ( line.startswith( '@HD' ) or line.startswith( '@SQ' ) or line.startswith( '@RG' ) or line.startswith( '@PG' ) or line.startswith( '@CO' ) ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
423 fout.write( line )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
424 fout.close()
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
425 # check that there are results in the output file
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
426 if os.path.getsize( options.output ) > 0:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
427 sys.stdout.write( 'TMAP completed' )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
428 else:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
429 raise Exception, 'The output file is empty. You may simply have no matches, or there may be an error with your input file or settings.'
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
430 except Exception, e:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
431 stop_err( 'The alignment failed.\n' + str( e ) )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
432 finally:
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
433 # clean up temp dir
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
434 if os.path.exists( tmp_index_dir ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
435 shutil.rmtree( tmp_index_dir )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
436 if os.path.exists( tmp_dir ):
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
437 shutil.rmtree( tmp_dir )
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
438
7cbfd271d207 Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
439 if __name__=="__main__": __main__()