comparison bismark_wrapper.py @ 4:427fb56f2e41 draft default tip

- new options - fixes
author bjoern-gruening
date Fri, 01 Mar 2013 13:39:22 -0500
parents 36d124f44c0a
children
comparison
equal deleted inserted replaced
3:7eefe5d6eecd 4:427fb56f2e41
117 if args.bowtie2: 117 if args.bowtie2:
118 cmd_index = 'bismark_genome_preparation --bowtie2 %s ' % ( tmp_index_dir ) 118 cmd_index = 'bismark_genome_preparation --bowtie2 %s ' % ( tmp_index_dir )
119 else: 119 else:
120 cmd_index = 'bismark_genome_preparation %s ' % ( tmp_index_dir ) 120 cmd_index = 'bismark_genome_preparation %s ' % ( tmp_index_dir )
121 if args.bismark_path: 121 if args.bismark_path:
122 # add the path to the bismark perl scripts, that is needed for galaxy 122 if os.path.exists(args.bismark_path):
123 cmd_index = '%s/%s' % (args.bismark_path, cmd_index) 123 # add the path to the bismark perl scripts, that is needed for galaxy
124 cmd_index = os.path.join(args.bismark_path, cmd_index)
125 else:
126 # assume the same directory as that script
127 cmd_index = 'perl %s' % os.path.join(os.path.realpath(os.path.dirname(__file__)), cmd_index)
124 try: 128 try:
125 tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name 129 tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name
126 tmp_stderr = open( tmp, 'wb' ) 130 tmp_stderr = open( tmp, 'wb' )
127 proc = subprocess.Popen( args=cmd_index, shell=True, cwd=tmp_index_dir, stdout=open(os.devnull, 'wb'), stderr=tmp_stderr.fileno() ) 131 proc = subprocess.Popen( args=cmd_index, shell=True, cwd=tmp_index_dir, stdout=open(os.devnull, 'wb'), stderr=tmp_stderr.fileno() )
128 returncode = proc.wait() 132 returncode = proc.wait()
145 if os.path.exists( tmp_index_dir ): 149 if os.path.exists( tmp_index_dir ):
146 shutil.rmtree( tmp_index_dir ) 150 shutil.rmtree( tmp_index_dir )
147 stop_err( 'Error indexing reference sequence\n' + str( e ) ) 151 stop_err( 'Error indexing reference sequence\n' + str( e ) )
148 index_dir = tmp_index_dir 152 index_dir = tmp_index_dir
149 else: 153 else:
150 index_dir = args.index_path 154 # bowtie path is the path to the index directory and the first path of the index file name
155 index_dir = os.path.dirname( args.index_path )
151 156
152 # Build bismark command 157 # Build bismark command
153 tmp_bismark_dir = tempfile.mkdtemp() 158 tmp_bismark_dir = tempfile.mkdtemp()
154 output_dir = os.path.join( tmp_bismark_dir, 'results') 159 output_dir = os.path.join( tmp_bismark_dir, 'results')
155 cmd = 'bismark %(args)s --temp_dir %(tmp_bismark_dir)s -o %(output_dir)s --quiet %(genome_folder)s %(reads)s' 160 cmd = 'bismark %(args)s --temp_dir %(tmp_bismark_dir)s -o %(output_dir)s --quiet %(genome_folder)s %(reads)s'
161
162 if args.fasta:
163 # he query input files (specified as mate1,mate2 or singles) are FastA
164 cmd = '%s %s' % (cmd, '--fasta')
165 elif args.fastq:
166 cmd = '%s %s' % (cmd, '--fastq')
167
156 if args.bismark_path: 168 if args.bismark_path:
157 # add the path to the bismark perl scripts, that is needed for galaxy 169 # add the path to the bismark perl scripts, that is needed for galaxy
158 cmd = '%s/%s' % (args.bismark_path, cmd) 170 if os.path.exists(args.bismark_path):
171 cmd = os.path.join(args.bismark_path, cmd)
172 else:
173 # assume the same directory as that script
174 cmd = 'perl %s' % os.path.join(os.path.realpath(os.path.dirname(__file__)), cmd)
159 175
160 arguments = { 176 arguments = {
161 'genome_folder': index_dir, 177 'genome_folder': index_dir,
162 'args': '', 178 'args': '',
163 'tmp_bismark_dir': tmp_bismark_dir, 179 'tmp_bismark_dir': tmp_bismark_dir,
176 reads = ' %s ' % ( args.single_paired ) 192 reads = ' %s ' % ( args.single_paired )
177 193
178 194
179 if not args.bowtie2: 195 if not args.bowtie2:
180 # use bowtie specific options 196 # use bowtie specific options
181 additional_opts += ' --best ' 197 #additional_opts += ' --best ' # bug in bismark, --best is not available as option. Only --non-best, best-mode is activated by default
182 if args.seed_mismatches: 198 if args.seed_mismatches:
183 # --seedmms 199 # --seedmms
184 additional_opts += ' -n %s ' % args.seed_mismatches 200 additional_opts += ' -n %s ' % args.seed_mismatches
185 if args.seed_len: 201 if args.seed_len:
186 # --seedlen 202 # --seedlen