comparison extract_bcs.py @ 5:e841de88235c draft

Uploaded
author rnateam
date Fri, 23 Oct 2015 07:28:06 -0400
parents de4ea3aa1090
children bb59215dfd8f
comparison
equal deleted inserted replaced
4:d03c001f7c73 5:e841de88235c
4 Exract barcodes from a FASTQ file according to a user-specified pattern. 4 Exract barcodes from a FASTQ file according to a user-specified pattern.
5 5
6 By default output is written to stdout. 6 By default output is written to stdout.
7 7
8 Example usage: 8 Example usage:
9 - move nucleotides at positions 1-3 and 6-7 to FASTQ header and write to file 9 - remove barcode nucleotides at positions 1-3 and 6-7 from FASTQ; write modified
10 output.fastq: 10 FASTQ entries to output.fastq and barcode nucleotides to barcodes.fa:
11 fastq_extract_barcodes.py barcoded_input.fastq XXXNNXX --out output.fastq 11 fastq_extract_barcodes.py barcoded_input.fastq XXXNNXX --out output.fastq --bcs barcodes.fa
12 """ 12 """
13 13
14 epilog = """ 14 epilog = """
15 Author: Daniel Maticzka 15 Author: Daniel Maticzka
16 Copyright: 2015 16 Copyright: 2015
48 parser.add_argument( 48 parser.add_argument(
49 "-b", "--bcs", 49 "-b", "--bcs",
50 dest="out_bc_fasta", 50 dest="out_bc_fasta",
51 help="If set, barcodes are written to this file in FASTA format.") 51 help="If set, barcodes are written to this file in FASTA format.")
52 parser.add_argument( 52 parser.add_argument(
53 "-a", "--add-bc-to-fastq",
54 dest="add_to_head",
55 help="If set, append extracted barcodes to the FASTQ headers.",
56 action="store_true"
57 )
58 parser.add_argument(
53 "-v", "--verbose", 59 "-v", "--verbose",
54 help="Be verbose.", 60 help="Be verbose.",
55 action="store_true") 61 action="store_true")
56 parser.add_argument( 62 parser.add_argument(
57 "-d", "--debug", 63 "-d", "--debug",
58 help="Print lots of debugging information", 64 help="Print lots of debugging information",
59 action="store_true") 65 action="store_true")
60 parser.add_argument( 66 parser.add_argument(
61 '--version', 67 '--version',
62 action='version', 68 action='version',
63 version='0.1.0') 69 version='1.0.0')
64 70
65 args = parser.parse_args() 71 args = parser.parse_args()
66 if args.debug: 72 if args.debug:
67 logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(filename)s - %(levelname)s - %(message)s") 73 logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(filename)s - %(levelname)s - %(message)s")
68 elif args.verbose: 74 elif args.verbose:
151 logging.debug("seq: {}".format(seq)) 157 logging.debug("seq: {}".format(seq))
152 logging.debug("len(seq): {}".format(len(seq))) 158 logging.debug("len(seq): {}".format(len(seq)))
153 continue 159 continue
154 160
155 # write barcode nucleotides into header 161 # write barcode nucleotides into header
156 annotated_header = header + " " + barcode 162 if args.add_to_head:
163 annotated_header = " ".join([header, barcode])
164 else:
165 annotated_header = header
157 samout.write("@%s\n%s\n+\n%s\n" % (annotated_header, new_seq, new_qual)) 166 samout.write("@%s\n%s\n+\n%s\n" % (annotated_header, new_seq, new_qual))
158 167
159 # write barcode to fasta if requested 168 # write barcode to fasta if requested
160 if args.out_bc_fasta is not None: 169 if args.out_bc_fasta is not None:
161 faout.write(">{}\n{}\n".format(header, barcode)) 170 faout.write(">{}\n{}\n".format(header, barcode))