File: adjust_seq_orientation.py

package info (click to toggle)
qiime 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 29,704 kB
  • sloc: python: 77,837; haskell: 379; sh: 113; makefile: 103
file content (65 lines) | stat: -rwxr-xr-x 2,313 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# File created on 09 Feb 2010
from __future__ import division

__author__ = "Antonio Gonzalez Pena"
__copyright__ = "Copyright 2011, The QIIME Project"
__credits__ = ["Greg Caporaso", "Antonio Gonzalez Pena"]
__license__ = "GPL"
__version__ = "1.4.0"
__maintainer__ = "Antonio Gonzalez Pena"
__email__ = "antgonza@gmail.com"
__status__ = "Release"

from qiime.util import parse_command_line_parameters, get_options_lookup
from qiime.util import make_option
from os.path import split, splitext
from cogent.parse.fasta import MinimalFastaParser
from cogent import DNA
from qiime.adjust_seq_orientation import rc_fasta_file, append_rc, null_seq_desc_mapper

options_lookup = get_options_lookup()

script_info={}
script_info['brief_description']="""Get the reverse complement of all sequences"""
script_info['script_description']="""Write the reverse complement of all seqs in seqs.fasta (-i) to seqs_rc.fasta (default, change output_fp with -o). Each sequence description line will have ' RC' appended to the end of it (default,
leave sequence description lines untouched by passing -r):"""
script_info['script_usage']=[]
script_info['script_usage'].append(("""Example:""",""" """,""" adjust_seq_orientation.py -i seqs.fasta"""))
script_info['output_description']=""""""
script_info['required_options']=[\
   options_lookup['fasta_as_primary_input']\
]
script_info['optional_options']=[\
   options_lookup['output_fp'],\
   make_option('-r','--retain_seq_id',action='store_true',\
        help='leave seq description lines untouched'+\
        ' [default: append " RC" to seq description lines]')
] 
script_info['version'] = __version__


def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)
      
    verbose = opts.verbose
    
    input_fasta_fp = opts.input_fasta_fp
    output_fp = opts.output_fp
    retain_seq_id = opts.retain_seq_id
    
    if retain_seq_id:
        seq_desc_mapper = null_seq_desc_mapper
    else:
        seq_desc_mapper = append_rc
    
    if not output_fp:
        input_file_basename, input_file_ext = \
         splitext(split(input_fasta_fp)[1])
        output_fp = '%s_rc%s' % (input_file_basename,input_file_ext)
        
    rc_fasta_file(input_fasta_fp,output_fp,seq_desc_mapper)


if __name__ == "__main__":
    main()