Mercurial > repos > rreumerman > snptools
comparison trams.py @ 7:8de0ffc2166f draft default tip
Uploaded
author | rreumerman |
---|---|
date | Mon, 10 Jun 2013 09:40:54 -0400 |
parents | bd5692103d5b |
children |
comparison
equal
deleted
inserted
replaced
6:e711f63e99ff | 7:8de0ffc2166f |
---|---|
2 transl_table = 11 | 2 transl_table = 11 |
3 intro_message = ''' +------------------------------------------------------------------+ | 3 intro_message = ''' +------------------------------------------------------------------+ |
4 | Tool for Rapid Annotation of Microbial SNPs (TRAMS): a simple | | 4 | Tool for Rapid Annotation of Microbial SNPs (TRAMS): a simple | |
5 | program for rapid annotation of genomic variation in prokaryotes | | 5 | program for rapid annotation of genomic variation in prokaryotes | |
6 | | | 6 | | |
7 | Developed by: Richard A. Reumerman, Paul R. Herron, | | 7 | Developed by: Richard A. Reumerman, Nick P. Tucker, Paul R. | |
8 | Paul A. Hoskisson and Vartul Sangal | | 8 | Herron, Paul A. Hoskisson and Vartul Sangal | |
9 +------------------------------------------------------------------+\n''' | 9 +------------------------------------------------------------------+\n''' |
10 ################# | 10 ################# |
11 | 11 |
12 import sys | 12 import sys |
13 import time | 13 import time |
193 straininfo[j][codon[i][j+2][0]] += 1# Counting; | 193 straininfo[j][codon[i][j+2][0]] += 1# Counting; |
194 elif strain[1] in ['a','g','c','t']: | 194 elif strain[1] in ['a','g','c','t']: |
195 codon[i][j+2] = ['MNP',strain[1],'',''] | 195 codon[i][j+2] = ['MNP',strain[1],'',''] |
196 straininfo[j]['mnps'] += 1 | 196 straininfo[j]['mnps'] += 1 |
197 new_codons[j] = new_codon_calc(new_codons[j],strain[1],pos_in_cod) | 197 new_codons[j] = new_codon_calc(new_codons[j],strain[1],pos_in_cod) |
198 elif strain[0] == 'Allele missing': codon[i][j+2] = strain | 198 elif strain[0] == 'Missing allele': |
199 codon[i][j+2] = strain | |
199 else: codon[i][j+2] = ['']*4 | 200 else: codon[i][j+2] = ['']*4 |
200 | 201 |
201 for line in codon[1:-1]: | 202 for line in codon[1:-1]: |
202 if line != '': write_output(line) | 203 if line != '': write_output(line) |
203 | 204 |
287 | 288 |
288 # Loop through SNPs from array and process them; | 289 # Loop through SNPs from array and process them; |
289 props = {}# Properties of a feature; | 290 props = {}# Properties of a feature; |
290 prev_snp = ''# Position of previous SNP; | 291 prev_snp = ''# Position of previous SNP; |
291 to_write = []# Information of current SNP; | 292 to_write = []# Information of current SNP; |
293 allowed_chars = ['g','a','t','c','','-'] | |
292 compl_bases = {'a':'t','t':'a','g':'c','c':'g'} | 294 compl_bases = {'a':'t','t':'a','g':'c','c':'g'} |
293 firstsnp = True# First snp of region, or of codon in cases of 3 positions in codon mutated; | 295 firstsnp = True# First snp of region, or of codon in cases of 3 positions in codon mutated; |
294 prev_start=j=k=0 | 296 prev_start=j=k=0 |
295 overlap_snps = [] | 297 overlap_snps = [] |
296 codon = ['']*5# Array of codon positions. First item is position of first base of codon in the gene; | 298 codon = ['']*5# Array of codon positions. First item is position of first base of codon in the gene; |
327 | 329 |
328 | 330 |
329 snp_entry[-1] = snp_entry[-1].rstrip()# Remove newline character at end of line; | 331 snp_entry[-1] = snp_entry[-1].rstrip()# Remove newline character at end of line; |
330 | 332 |
331 # Prevent crash upon encounter nonstandard base character; | 333 # Prevent crash upon encounter nonstandard base character; |
332 if snp_entry[1] not in ['a','g','c','t']:# Ref base | 334 if snp_entry[1].lower() not in allowed_chars:# Ref base |
333 i += 1 | 335 i += 1 |
334 continue | 336 continue |
335 for m,base in enumerate(snp_entry[2:],2): | 337 for m,base in enumerate(snp_entry[2:],2): |
336 if base.lower() not in ['a','g','c','t']: | 338 if base.lower() not in allowed_chars: |
337 snp_entry[m] = '' | 339 snp_entry[m] = '' |
338 # Crash prevented | 340 # Crash prevented |
339 | 341 |
340 mnp=in_feat=False | 342 mnp=in_feat=False |
341 snp_feat = region[2] | 343 snp_feat = region[2] |
407 | 409 |
408 for l, snp in enumerate(snp_entry[2:]):# Loop through SNPs/strains; | 410 for l, snp in enumerate(snp_entry[2:]):# Loop through SNPs/strains; |
409 | 411 |
410 snp = snp.lower() | 412 snp = snp.lower() |
411 if snp == '':# Empty cell; | 413 if snp == '':# Empty cell; |
412 to_write.append(['','','','']) | 414 to_write.append(['']*4) |
413 continue | 415 continue |
414 | 416 |
415 if snp == '-': # Feature not present in this strain; | 417 if snp == '-': # Feature not present in this strain; |
416 to_write.append(['Allele missing','','','']) | 418 to_write.append(['Missing allele','','','']) |
417 continue | 419 continue |
418 | 420 |
419 if snp_feat == -1:# Intergenic; | 421 if snp_feat == -1:# Intergenic; |
420 if snp == ref_base.lower(): | 422 if snp == ref_base.lower(): |
421 to_write.append(['']*4) | 423 to_write.append(['']*4) |