-
Notifications
You must be signed in to change notification settings - Fork 3
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 #134 from c-BIG/develop
Release/0.13.0
- Loading branch information
Showing
80 changed files
with
6,006 additions
and
3,951 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
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,64 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import json | ||
import pprint as pp | ||
import subprocess | ||
import numpy as np | ||
import sys | ||
import os | ||
from pathlib import Path | ||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--sample_id", dest="sample_id", required=True, | ||
default=None, | ||
help="Sample ID") | ||
parser.add_argument("--input_aln_metrics", dest="input_aln_metrics", required=True, | ||
default=None, | ||
help="Path to input aln metrics list") | ||
parser.add_argument("--input_variants_metrics", dest="input_variants_metrics", required=True, | ||
default=None, | ||
help="Path to input variants metrics list") | ||
parser.add_argument("--output_json", dest="output_json", required=False, | ||
default="./metrics.json", | ||
help="Path to output file for variant metrics. Default: ./variant_counts.json") | ||
parser.add_argument("--scratch_dir", dest="scratch_dir", required=False, | ||
default="./", | ||
help="Path to scratch dir. Default: ./") | ||
args = parser.parse_args() | ||
|
||
# create scratch dir if it doesn't exist | ||
Path(args.scratch_dir).mkdir(parents=True, exist_ok=True) | ||
|
||
return args | ||
|
||
|
||
def data1(input_aln_metrics): | ||
aln_input = {} | ||
with open(input_aln_metrics, 'r') as f1: | ||
aln_input = json.load(f1) | ||
return aln_input | ||
|
||
def data2(input_variants_metrics): | ||
variants_input = {} | ||
with open(input_variants_metrics, 'r') as f2: | ||
variants_input = json.load(f2) | ||
return variants_input | ||
|
||
|
||
def save_output(data1, data2, outfile): | ||
with open(outfile, "w") as f: | ||
data1['wgs_qc_metrics']['variant_metrics'].update(data2['wgs_qc_metrics']['variant_metrics']) | ||
#data1['wgs_qc_metrics']['variant_metrics'] = data2['wgs_qc_metrics']['variant_metrics'] | ||
print(data1) | ||
json.dump(data1, f, sort_keys=True, indent=4) | ||
#json.dump({"biosample": data1["biosample"], "wgs_qc_metrics": {**data1["wgs_qc_metrics"], **data2["wgs_qc_metrics"]}}, f, sort_keys=True, indent=4) | ||
f.write("\n") | ||
|
||
if __name__ == "__main__": | ||
args = parse_args() | ||
|
||
aln = data1(args.input_aln_metrics) | ||
variants = data2(args.input_variants_metrics) | ||
save_output(aln, variants, args.output_json) |
This file was deleted.
Oops, something went wrong.
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,65 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import json | ||
import pprint as pp | ||
import subprocess | ||
import numpy as np | ||
import sys | ||
import os | ||
from pathlib import Path | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--sample_id", dest="sample_id", required=True, | ||
default=None, | ||
help="Sample ID") | ||
parser.add_argument("--input_metrics", dest="input_metrics", required=True, | ||
default=None, | ||
help="Path to input aln metrics list") | ||
parser.add_argument("--output_json", dest="output_json", required=False, | ||
default="./variant_counts.json", | ||
help="Path to output file for variant metrics. Default: ./variant_counts.json") | ||
parser.add_argument("--scratch_dir", dest="scratch_dir", required=False, | ||
default="./", | ||
help="Path to scratch dir. Default: ./") | ||
args = parser.parse_args() | ||
|
||
# create scratch dir if it doesn't exist | ||
Path(args.scratch_dir).mkdir(parents=True, exist_ok=True) | ||
|
||
return args | ||
|
||
def raw_data(input_metrics): | ||
d = {} | ||
with open(input_metrics) as f: | ||
for line in f: | ||
if not line.strip(): | ||
continue | ||
row = line.split('\t') | ||
key = row[0] | ||
value_str = row[1] | ||
#d[key] = value_str.replace("\n", "") | ||
try: | ||
#value = float(value_str.strip()) | ||
value = int(value_str) | ||
except ValueError: | ||
#value = value_str.strip() | ||
value = float(value_str.strip()) | ||
d[key] = value | ||
return d | ||
|
||
|
||
def save_output(data_metrics, outfile): | ||
with open(outfile, "w") as f: | ||
# data_metrics = {"biosample" : {"id" : args.sample_id}, "wgs_qc_metrics" : data_metrics} | ||
data_metrics = {"biosample" : {"id" : args.sample_id}, "wgs_qc_metrics" : {"aln_metrics" : data_metrics, "variant_metrics" : {}}} | ||
json.dump(data_metrics, f, sort_keys=True, indent=4) | ||
f.write("\n") | ||
|
||
if __name__ == "__main__": | ||
args = parse_args() | ||
|
||
data_metrics = raw_data(args.input_metrics) | ||
save_output(data_metrics, args.output_json) |
Oops, something went wrong.