Mercurial > repos > rnateam > bctools
comparison extract_aln_ends.py @ 14:570a7de9f151 draft
read from bam; fix header issue
author | rnateam |
---|---|
date | Mon, 30 Nov 2015 07:53:36 -0500 |
parents | de4ea3aa1090 |
children | 0b9aab6aaebf |
comparison
equal
deleted
inserted
replaced
13:258b6f9e19ab | 14:570a7de9f151 |
---|---|
12 ("forward-reverse") direction. | 12 ("forward-reverse") direction. |
13 | 13 |
14 By default output is written to stdout. | 14 By default output is written to stdout. |
15 | 15 |
16 Input: | 16 Input: |
17 * sam file containing alignments (paired-end sequencing) | 17 * alignments in SAM or BAM format (paired-end sequencing) |
18 | 18 |
19 Output: | 19 Output: |
20 * bed6 file containing outer coordinates (sorted by read id) | 20 * bed6 file containing outer coordinates (sorted by read id) |
21 | 21 |
22 Example usage: | 22 Example usage: |
55 parser = argparse.ArgumentParser(description=tool_description, | 55 parser = argparse.ArgumentParser(description=tool_description, |
56 epilog=epilog, | 56 epilog=epilog, |
57 formatter_class=DefaultsRawDescriptionHelpFormatter) | 57 formatter_class=DefaultsRawDescriptionHelpFormatter) |
58 # positional arguments | 58 # positional arguments |
59 parser.add_argument( | 59 parser.add_argument( |
60 "sam", | 60 "infile", |
61 help="Path to sam file containing alignments.") | 61 help="Path to alignments in SAM or BAM format.") |
62 # optional arguments | 62 # optional arguments |
63 parser.add_argument( | 63 parser.add_argument( |
64 "-o", "--outfile", | 64 "-o", "--outfile", |
65 help="Write results to this file.") | 65 help="Write results to this file.") |
66 # misc arguments | 66 # misc arguments |
73 help="Print lots of debugging information", | 73 help="Print lots of debugging information", |
74 action="store_true") | 74 action="store_true") |
75 parser.add_argument( | 75 parser.add_argument( |
76 '--version', | 76 '--version', |
77 action='version', | 77 action='version', |
78 version='0.1.0') | 78 version='0.2.0') |
79 | 79 |
80 args = parser.parse_args() | 80 args = parser.parse_args() |
81 | 81 |
82 if args.debug: | 82 if args.debug: |
83 logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(filename)s - %(levelname)s - %(message)s") | 83 logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(filename)s - %(levelname)s - %(message)s") |
84 elif args.verbose: | 84 elif args.verbose: |
85 logging.basicConfig(level=logging.INFO, format="%(filename)s - %(levelname)s - %(message)s") | 85 logging.basicConfig(level=logging.INFO, format="%(filename)s - %(levelname)s - %(message)s") |
86 else: | 86 else: |
87 logging.basicConfig(format="%(filename)s - %(levelname)s - %(message)s") | 87 logging.basicConfig(format="%(filename)s - %(levelname)s - %(message)s") |
88 logging.info("Parsed arguments:") | 88 logging.info("Parsed arguments:") |
89 logging.info(" sam: '{}'".format(args.sam)) | 89 logging.info(" infile: '{}'".format(args.infile)) |
90 if args.outfile: | 90 if args.outfile: |
91 logging.info(" outfile: enabled writing to file") | 91 logging.info(" outfile: enabled writing to file") |
92 logging.info(" outfile: '{}'".format(args.outfile)) | 92 logging.info(" outfile: '{}'".format(args.outfile)) |
93 logging.info("") | 93 logging.info("") |
94 | 94 |
101 fn_sorted = tmpdir + "/sorted.bam" | 101 fn_sorted = tmpdir + "/sorted.bam" |
102 fn_fixedmates = tmpdir + "/fixedmates.bam" | 102 fn_fixedmates = tmpdir + "/fixedmates.bam" |
103 | 103 |
104 # sort by id | 104 # sort by id |
105 logging.debug("calling samtools sort") | 105 logging.debug("calling samtools sort") |
106 pysam.sort(args.sam, "-n", "-o{}".format(fn_sorted), "-T sortprefix") | 106 pysam.sort(args.infile, "-n", "-o{}".format(fn_sorted), "-T sortprefix") |
107 | 107 |
108 # fix mate information | 108 # fix mate information |
109 # also removes secondary and unmapped reads | 109 # also removes secondary and unmapped reads |
110 logging.debug("calling samtools fixmates") | 110 logging.debug("calling samtools fixmates") |
111 pysam.fixmate("-r", fn_sorted, fn_fixedmates) | 111 pysam.fixmate("-r", fn_sorted, fn_fixedmates) |