Mercurial > repos > rnateam > bctools
comparison convert_bc_to_binary_RY.py @ 8:17ef0e0dae68 draft
Uploaded
| author | rnateam |
|---|---|
| date | Tue, 10 Nov 2015 09:13:44 -0500 |
| parents | de4ea3aa1090 |
| children | 0b9aab6aaebf |
comparison
equal
deleted
inserted
replaced
| 7:bb59215dfd8f | 8:17ef0e0dae68 |
|---|---|
| 37 epilog=epilog, | 37 epilog=epilog, |
| 38 formatter_class=argparse.RawDescriptionHelpFormatter) | 38 formatter_class=argparse.RawDescriptionHelpFormatter) |
| 39 # positional arguments | 39 # positional arguments |
| 40 parser.add_argument( | 40 parser.add_argument( |
| 41 "infile", | 41 "infile", |
| 42 help="Path to fasta input file.") | 42 help="Path to fastq input file.") |
| 43 # optional arguments | 43 # optional arguments |
| 44 parser.add_argument( | 44 parser.add_argument( |
| 45 "-o", "--outfile", | 45 "-o", "--outfile", |
| 46 help="Write results to this file.") | 46 help="Write results to this file.") |
| 47 parser.add_argument( | |
| 48 "--fasta-format", | |
| 49 dest="fasta_format", | |
| 50 help="Read and write fasta instead of fastq format.", | |
| 51 action="store_true") | |
| 47 parser.add_argument( | 52 parser.add_argument( |
| 48 "-v", "--verbose", | 53 "-v", "--verbose", |
| 49 help="Be verbose.", | 54 help="Be verbose.", |
| 50 action="store_true") | 55 action="store_true") |
| 51 parser.add_argument( | 56 parser.add_argument( |
| 71 | 76 |
| 72 | 77 |
| 73 def translate_nt_to_RY_iterator(robj): | 78 def translate_nt_to_RY_iterator(robj): |
| 74 """Translate SeqRecords sequences to RY alphabet.""" | 79 """Translate SeqRecords sequences to RY alphabet.""" |
| 75 for record in robj: | 80 for record in robj: |
| 81 if not args.fasta_format: | |
| 82 saved_letter_annotations = record.letter_annotations | |
| 83 record.letter_annotations = {} | |
| 76 record.seq = Seq(translate_nt_to_RY(str(record.seq)), | 84 record.seq = Seq(translate_nt_to_RY(str(record.seq)), |
| 77 IUPAC.unambiguous_dna) | 85 IUPAC.unambiguous_dna) |
| 86 if not args.fasta_format: | |
| 87 record.letter_annotations = saved_letter_annotations | |
| 78 yield record | 88 yield record |
| 79 | 89 |
| 80 # handle arguments | 90 # handle arguments |
| 81 args = parser.parse_args() | 91 args = parser.parse_args() |
| 82 if args.debug: | 92 if args.debug: |
| 92 logging.info(" outfile: '{}'".format(args.outfile)) | 102 logging.info(" outfile: '{}'".format(args.outfile)) |
| 93 logging.info("") | 103 logging.info("") |
| 94 | 104 |
| 95 # get input iterator | 105 # get input iterator |
| 96 input_handle = open(args.infile, "rU") | 106 input_handle = open(args.infile, "rU") |
| 97 input_seq_iterator = SeqIO.parse(input_handle, "fasta") | 107 if args.fasta_format: |
| 108 input_seq_iterator = SeqIO.parse(input_handle, "fasta") | |
| 109 else: | |
| 110 input_seq_iterator = SeqIO.parse(input_handle, "fastq") | |
| 98 convert_seq_iterator = translate_nt_to_RY_iterator(input_seq_iterator) | 111 convert_seq_iterator = translate_nt_to_RY_iterator(input_seq_iterator) |
| 99 output_handle = (open(args.outfile, "w") if args.outfile is not None else stdout) | 112 output_handle = (open(args.outfile, "w") if args.outfile is not None else stdout) |
| 100 SeqIO.write(convert_seq_iterator, output_handle, "fasta") | 113 if args.fasta_format: |
| 114 SeqIO.write(convert_seq_iterator, output_handle, "fasta") | |
| 115 else: | |
| 116 SeqIO.write(convert_seq_iterator, output_handle, "fastq") | |
| 101 output_handle.close() | 117 output_handle.close() |
