Mercurial > repos > iuc > nanocompore_db
annotate 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 |
| rev | line source |
|---|---|
|
0
b6eeea872fd2
"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 |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
2 |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
3 import argparse |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
4 import os |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
5 |
|
b6eeea872fd2
"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 |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
7 |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
8 |
|
b6eeea872fd2
"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): |
|
b6eeea872fd2
"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): |
|
b6eeea872fd2
"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) |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
12 else: |
|
b6eeea872fd2
"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)) |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
14 |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
15 |
|
b6eeea872fd2
"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): |
|
b6eeea872fd2
"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): |
|
b6eeea872fd2
"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) |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
19 else: |
|
b6eeea872fd2
"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)) |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
21 |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
22 |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
23 if __name__ == '__main__': |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
24 |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
25 parser = argparse.ArgumentParser( |
|
b6eeea872fd2
"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 \ |
|
b6eeea872fd2
"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 \ |
|
b6eeea872fd2
"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 \ |
|
b6eeea872fd2
"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 \ |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
30 --out-dir ./plots/') |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
31 |
|
b6eeea872fd2
"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, |
|
b6eeea872fd2
"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.') |
|
b6eeea872fd2
"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, |
|
b6eeea872fd2
"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.') |
|
b6eeea872fd2
"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, |
|
b6eeea872fd2
"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') |
|
b6eeea872fd2
"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, |
|
b6eeea872fd2
"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', |
|
b6eeea872fd2
"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') |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
41 parser.add_argument('--bedgraph', default=False, |
|
b6eeea872fd2
"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') |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
43 parser.add_argument('--pvalue-threshold', default=1.0, |
|
b6eeea872fd2
"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.') |
|
b6eeea872fd2
"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, |
|
b6eeea872fd2
"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.') |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
47 |
|
b6eeea872fd2
"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() |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
49 |
|
b6eeea872fd2
"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, |
|
b6eeea872fd2
"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) |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
52 print(db) |
|
b6eeea872fd2
"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) |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
54 |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
55 if args.annotation_bed: |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
56 for pt in args.pvalue_types.split(','): |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
57 print("bedgraph output for p-value type:", pt) |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
58 db.save_to_bed(output_fn='{}/{}.bedgraph'.format(args.out_dir, pt), |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
59 pvalue_field=pt, pvalue_thr=args.pvalue_threshold, |
|
b6eeea872fd2
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/nanocompore commit 652a872061324ba1073bfa286777ffeefa352671"
iuc
parents:
diff
changeset
|
60 bedgraph=args.bedgraph) |
