-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from jts/primer_snps
implement methods to identify variants that disrupt amplicons
- Loading branch information
Showing
3 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import argparse | ||
import sys | ||
import csv | ||
import os | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--primer-snp-bed', type=str, required=True) | ||
parser.add_argument('--amplicon-depth-tsv', type=str, required=True) | ||
parser.add_argument('--sample-name', type=str, default="none") | ||
args, files = parser.parse_known_args() | ||
|
||
def main(): | ||
print("\t".join(["sample", "contig", "position", "ref", "alt", "primer_name", "amplicon", "depth"])) | ||
|
||
# read in the depth of each amplicon | ||
depth_map = dict() | ||
with open(args.amplicon_depth_tsv, 'r') as ifh: | ||
reader = csv.DictReader(ifh, delimiter='\t') | ||
for record in reader: | ||
depth_map[record['amplicon_id']] = record['mean_depth'] | ||
|
||
# read in the bed file containing mutations that overlap primers | ||
seen = dict() | ||
with(open(args.primer_snp_bed, 'r')) as ifh: | ||
for line in ifh: | ||
fields = line.rstrip().split() | ||
assert(len(fields) == 16) | ||
primer_name = fields[13] | ||
primer_direction_idx = max(primer_name.find("_LEFT"), primer_name.find("_RIGHT")) | ||
if primer_direction_idx == -1: | ||
sys.stderr.write("Could not parse primer name %s" % (primer_name)) | ||
sys.exit(1) | ||
amplicon_id = primer_name[0:primer_direction_idx] | ||
|
||
# skip duplicate entries when a mutation lands in ALT versions of primers | ||
key = ":".join([fields[0], fields[1], fields[3], fields[4], amplicon_id]) | ||
if key not in seen: | ||
print("\t".join([args.sample_name, fields[0], fields[1], fields[3], fields[4], primer_name, amplicon_id, depth_map[amplicon_id]])) | ||
seen[key] = 1 | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import argparse | ||
import numpy | ||
import sys | ||
import csv | ||
import os | ||
|
||
from collections import defaultdict | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--input-tsv', type=str, required=True) | ||
args, files = parser.parse_known_args() | ||
|
||
def main(): | ||
print("\t".join(["contig", "position", "ref", "alt", "primer_name", "amplicon", "num_samples", "mean_depth", "min_depth", "max_depth"])) | ||
|
||
# read in the depth per sample | ||
depth_map = defaultdict(list) | ||
|
||
with open(args.input_tsv, 'r') as ifh: | ||
reader = csv.DictReader(ifh, delimiter='\t') | ||
for record in reader: | ||
key = ":".join([record['contig'], record['position'], record['ref'], record['alt'], record['primer_name'], record['amplicon']]) | ||
depth_map[key].append(float(record['depth'])) | ||
|
||
|
||
for key in depth_map.keys(): | ||
mean_depth = numpy.mean(depth_map[key]) | ||
min_depth = numpy.min(depth_map[key]) | ||
max_depth = numpy.max(depth_map[key]) | ||
fields = key.split(":") | ||
fields.append(str(len(depth_map[key]))) | ||
fields.append("%.2f" % mean_depth) | ||
fields.append("%.2f" % min_depth) | ||
fields.append("%.2f" % max_depth) | ||
print("\t".join(fields)) | ||
|
||
if __name__ == '__main__': | ||
main() |