annotate tmap_wrapper_0.0.19/tmap_wrapper.py @ 0:de2efe4dda3f

Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
author nilshomer
date Tue, 07 Jun 2011 16:46:26 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
2
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
3 # TODO
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
5
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
6 """
de2efe4dda3f 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.
de2efe4dda3f 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.
de2efe4dda3f 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.
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
10
de2efe4dda3f 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]
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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)
de2efe4dda3f 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)
de2efe4dda3f 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)
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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")
de2efe4dda3f 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
de2efe4dda3f 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)
de2efe4dda3f 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)
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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)
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
41
de2efe4dda3f 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
de2efe4dda3f 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)
de2efe4dda3f 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
de2efe4dda3f 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)
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
55
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
61
de2efe4dda3f 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
de2efe4dda3f 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)
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
67
de2efe4dda3f 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
de2efe4dda3f 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)
de2efe4dda3f 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
de2efe4dda3f 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)
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
81
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
87
de2efe4dda3f 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
de2efe4dda3f 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)
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
93
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
94 --suppressHeader: Suppress header
de2efe4dda3f 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
de2efe4dda3f 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'
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
97 """
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
98
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
100
de2efe4dda3f 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 ):
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
103 sys.exit()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
104
de2efe4dda3f 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, \
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
106 map1SecondarySeedLength, map1NumEdits, \
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
107 map1BaseError, map1Mismatches, \
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
108 map1GapOpens, map1GapExtensions, map1MaxCALsDeletion, \
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
109 map1EndIndels, map1MaxOptimalCALs, map1MaxNodes ):
de2efe4dda3f 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' % \
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
111 (map1SeedLength, map1SeedMismatches, \
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
112 map1SecondarySeedLength, map1NumEdits, \
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
113 map1BaseError, map1Mismatches, \
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
114 map1GapOpens, map1GapExtensions, map1MaxCALsDeletion, \
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
115 map1EndIndels, map1MaxOptimalCALs, map1MaxNodes )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
116
de2efe4dda3f 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 ):
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
119
de2efe4dda3f 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 ):
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
122
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
123 def __main__():
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
124 #Parse Command Line
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
125 parser = optparse.OptionParser()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
126 # Global options
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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)' )
de2efe4dda3f 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)' )
de2efe4dda3f 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)' )
de2efe4dda3f 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')
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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)' )
de2efe4dda3f 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)' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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' )
de2efe4dda3f 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)' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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" )
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f 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)' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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)' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f 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) ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f 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)' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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)' )
de2efe4dda3f 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' )
de2efe4dda3f 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' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f 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) ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f 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 ' )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
212 # parse the options
de2efe4dda3f 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()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
214
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
216 try:
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
220 tmp_stdout.close()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
221 returncode = proc.wait()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
222 stdout = None
de2efe4dda3f 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' ):
de2efe4dda3f 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:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
225 stdout = line.strip()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
226 break
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
227 if stdout:
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
229 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
230 raise Exception
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
231 except:
de2efe4dda3f 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' )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
233
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
234 fastq = options.fastq
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
235
de2efe4dda3f 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
de2efe4dda3f 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()
de2efe4dda3f 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()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
239
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
240 # index if necessary
de2efe4dda3f 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:
de2efe4dda3f 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 )
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
244 ref_file.close()
de2efe4dda3f 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 )
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
247 try:
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f 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() )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
251 returncode = proc.wait()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
252 tmp_stderr.close()
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
255 stderr = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
256 buffsize = 1048576
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
257 try:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
258 while True:
de2efe4dda3f 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 )
de2efe4dda3f 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:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
261 break
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
262 except OverflowError:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
263 pass
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
264 tmp_stderr.close()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
265 if returncode != 0:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
266 raise Exception, stderr
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
267 except Exception, e:
de2efe4dda3f 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
de2efe4dda3f 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 ):
de2efe4dda3f 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 )
de2efe4dda3f 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 ):
de2efe4dda3f 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 )
de2efe4dda3f 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 ) )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
274 else:
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
276
de2efe4dda3f 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
de2efe4dda3f 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':
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
280 map1_options = 'map1'
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
281 map2_options = 'map2'
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
282 map3_options = 'map3'
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
283 MAP1_options = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
284 MAP2_options = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
285 MAP3_options = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
286 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
287 # mapall options
de2efe4dda3f 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':
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
289 rgTag = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
290 if options.rgTagID != '':
de2efe4dda3f 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 + '" '
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
292 if options.rgTagCN != '':
de2efe4dda3f 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 + '" '
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
294 if options.rgTagDS != '':
de2efe4dda3f 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 + '" '
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
296 if options.rgTagDT != '':
de2efe4dda3f 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 + '" '
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
298 if options.rgTagLB != '':
de2efe4dda3f 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 + '" '
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
300 if options.rgTagPI != '':
de2efe4dda3f 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 + '" '
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
302 if options.rgTagPL != '':
de2efe4dda3f 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 + '" '
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
304 if options.rgTagPU != '':
de2efe4dda3f 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 + '" '
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
306 if options.rgTagSM != '':
de2efe4dda3f 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 + '" '
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
308 rgTag.rstrip(' ')
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
309 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
310 rgTag = ''
de2efe4dda3f 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:
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
313 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
314 flowOrder = ''
de2efe4dda3f 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':
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
316 filterIndependently = '-I'
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
317 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
318 filterIndependently = ''
de2efe4dda3f 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':
de2efe4dda3f 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' % \
de2efe4dda3f 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,
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
322 options.flowPenalty, flowOrder,
de2efe4dda3f 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,
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
325 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
326 mapall_options = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
327
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
328 # map1 - stage one
de2efe4dda3f 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':
de2efe4dda3f 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' % \
de2efe4dda3f 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, \
de2efe4dda3f 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, \
de2efe4dda3f 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, \
de2efe4dda3f 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, \
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
336 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
337 map1_options = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
338 # map2 - stage one
de2efe4dda3f 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':
de2efe4dda3f 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' % \
de2efe4dda3f 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, \
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
343 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
344 map2_options = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
345 # map3 - stage one
de2efe4dda3f 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':
de2efe4dda3f 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' % \
de2efe4dda3f 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, \
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
350 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
351 map3_options = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
352 # map1 - stage two
de2efe4dda3f 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':
de2efe4dda3f 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' % \
de2efe4dda3f 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, \
de2efe4dda3f 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, \
de2efe4dda3f 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, \
de2efe4dda3f 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, \
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
360 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
361 MAP1_options = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
362 # map2 - stage two
de2efe4dda3f 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':
de2efe4dda3f 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' % \
de2efe4dda3f 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, \
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
367 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
368 MAP2_options = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
369 # map3 - stage two
de2efe4dda3f 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':
de2efe4dda3f 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' % \
de2efe4dda3f 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, \
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
374 else:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
375 MAP3_options = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
376
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
377 #mapping_cmds
de2efe4dda3f 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
de2efe4dda3f 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' % \
de2efe4dda3f 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,
de2efe4dda3f 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,
de2efe4dda3f 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,
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
383 options.output )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
384 # perform alignments
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
385 buffsize = 1048576
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
386 try:
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
388 try:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
389 # align
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
390 try:
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f 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() )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
394 returncode = proc.wait()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
395 tmp_stderr.close()
de2efe4dda3f 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
de2efe4dda3f 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' )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
398 stderr = ''
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
399 try:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
400 while True:
de2efe4dda3f 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 )
de2efe4dda3f 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:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
403 break
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
404 except OverflowError:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
405 pass
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
406 tmp_stderr.close()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
407 if returncode != 0:
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
408 raise Exception, stderr
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
409 except Exception, e:
de2efe4dda3f 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 )
de2efe4dda3f 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
de2efe4dda3f 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':
de2efe4dda3f 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)
de2efe4dda3f 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
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
415 tmp_out.close()
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
416 try:
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
418 except Exception, e:
de2efe4dda3f 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 )
de2efe4dda3f 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' )
de2efe4dda3f 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' ):
de2efe4dda3f 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' ) ):
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
423 fout.write( line )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
424 fout.close()
de2efe4dda3f 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
de2efe4dda3f 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:
de2efe4dda3f 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' )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
428 else:
de2efe4dda3f 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.'
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
430 except Exception, e:
de2efe4dda3f 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 ) )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
432 finally:
de2efe4dda3f 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
de2efe4dda3f 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 ):
de2efe4dda3f 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 )
de2efe4dda3f 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 ):
de2efe4dda3f 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 )
de2efe4dda3f Migrated tool version 0.0.19 from old tool shed archive to new tool shed repository
nilshomer
parents:
diff changeset
438
de2efe4dda3f 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__()