comparison NanocomporeDB_process.py @ 0:b6eeea872fd2 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
author iuc
date Mon, 08 Jun 2020 14:41:41 -0400
parents
children 2af554112418
comparison
equal deleted inserted replaced
-1:000000000000 0:b6eeea872fd2
1 #!/usr/bin/env python
2
3 import argparse
4 import os
5
6 from nanocompore.SampCompDB import SampCompDB
7
8
9 def is_valid_file(file_name):
10 if os.path.isfile(file_name):
11 return os.path.abspath(file_name)
12 else:
13 raise FileNotFoundError(os.path.abspath(file_name))
14
15
16 def is_valid_directory(dir_name):
17 if os.path.isdir(dir_name):
18 return os.path.abspath(dir_name)
19 else:
20 raise NotADirectoryError(os.path.abspath(dir_name))
21
22
23 if __name__ == '__main__':
24
25 parser = argparse.ArgumentParser(
26 description='save nanocompre sampcomp \
27 results as interval outputs \
28 \nSample call: \"python Nannocompore-plot.py --db-path \
29 ./out_SampComp.db --ref-fasta ref.fa --annotation-bed annot.bed \
30 --out-dir ./plots/')
31
32 parser.add_argument('--ref-fasta', required=True, type=is_valid_file,
33 help='The reference genome used for read alignment.')
34 parser.add_argument('--db-path', default="./out_SampComp.db", type=str,
35 help='Path to the SampCompDB database path prefix.')
36 parser.add_argument('--annotation-bed', required=False, type=is_valid_file,
37 help='BED file containing the annotation of the transcriptome used as reference when mapping')
38 parser.add_argument('--pvalue-types', type=str,
39 default='GMM_logit_pvalue,KS_dwell_pvalue,KS_intensity_pvalue',
40 help='path to the annotations')
41 parser.add_argument('--bedgraph', default=False,
42 help='write output in BEDGRAPH format instead of BED')
43 parser.add_argument('--pvalue-threshold', default=1.0,
44 help='Maximum reported p-value.')
45 parser.add_argument('--out-dir', default="./", type=is_valid_directory,
46 help='path the plotting output directory.')
47
48 args = parser.parse_args()
49
50 db = SampCompDB(args.db_path, fasta_fn=args.ref_fasta,
51 bed_fn=args.annotation_bed)
52 print(db)
53 print("DB read ids:", db.ref_id_list)
54
55 if args.annotation_bed:
56 for pt in args.pvalue_types.split(','):
57 print("bedgraph output for p-value type:", pt)
58 db.save_to_bed(output_fn='{}/{}.bedgraph'.format(args.out_dir, pt),
59 pvalue_field=pt, pvalue_thr=args.pvalue_threshold,
60 bedgraph=args.bedgraph)