annotate NanocomporeDB_process.py @ 2:d193d0e411bd draft default tip

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