annotate RepEnrich.py @ 14:bf866bedd4b4 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 205141a3f695f202d5c3e01e6ab3b2b869fe62b5
author artbio
date Sat, 20 Apr 2024 12:13:52 +0000
parents 530626b0757c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
1 import argparse
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
2 import csv
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
3 import shlex
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
4 import subprocess
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
5 import sys
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
6 from collections import defaultdict
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
7 from concurrent.futures import ProcessPoolExecutor
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
8
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
9
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
10 parser = argparse.ArgumentParser(description='''
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
11 Repenrich aligns reads to Repeat Elements pseudogenomes\
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
12 and counts aligned reads. RepEnrich_setup must be run\
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
13 before its use''')
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
14 parser.add_argument('--annotation_file', action='store',
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
15 metavar='annotation_file',
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
16 help='RepeatMasker.org annotation file for your\
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
17 organism. The file may be downloaded from\
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
18 RepeatMasker.org. E.g. hg19_repeatmasker.txt')
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
19 parser.add_argument('--alignment_bam', action='store', metavar='alignment_bam',
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
20 help='Bam alignments of unique mapper reads.')
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
21 parser.add_argument('--fastqfile', action='store', metavar='fastqfile',
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
22 help='File of fastq reads mapping to multiple\
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
23 locations. Example: /data/multimap.fastq')
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
24 parser.add_argument('--fastqfile2', action='store', dest='fastqfile2',
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
25 metavar='fastqfile2', default='',
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
26 help='fastqfile #2 when using paired-end option.\
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
27 Default none')
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
28 parser.add_argument('--cpus', action='store', dest='cpus', metavar='cpus',
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
29 default="1", type=int,
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
30 help='Number of CPUs. The more cpus the\
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
31 faster RepEnrich performs. Default: "1"')
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
32
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
33 args = parser.parse_args()
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
34
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
35 # parameters
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
36 annotation_file = args.annotation_file
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
37 unique_mapper_bam = args.alignment_bam
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
38 fastqfile_1 = args.fastqfile
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
39 fastqfile_2 = args.fastqfile2
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
40 cpus = args.cpus
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
41 # Change if simple repeats are differently annotated in your organism
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
42 simple_repeat = "Simple_repeat"
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
43 if args.fastqfile2:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
44 paired_end = True
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
45 else:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
46 paired_end = False
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
47
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
48
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
49 def starts_with_numerical(list):
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
50 try:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
51 if len(list) == 0:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
52 return False
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
53 int(list[0])
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
54 return True
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
55 except ValueError:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
56 return False
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
57
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
58
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
59 # define a text importer for .out/.txt format of repbase
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
60 def import_text(filename, separator):
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
61 csv.field_size_limit(sys.maxsize)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
62 file = csv.reader(open(filename), delimiter=separator,
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
63 skipinitialspace=True)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
64 return [line for line in file if starts_with_numerical(line)]
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
65
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
66
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
67 def run_bowtie(args):
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
68 metagenome, fastqfile = args
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
69 b_opt = "-k 1 -p 1 --quiet"
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
70 command = shlex.split(f"bowtie {b_opt} -x {metagenome} {fastqfile}")
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
71 bowtie_align = subprocess.run(command, check=True,
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
72 capture_output=True, text=True).stdout
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
73 bowtie_align = bowtie_align.rstrip('\r\n').split('\n')
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
74 readlist = [metagenome]
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
75 if paired_end:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
76 for line in bowtie_align:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
77 readlist.append(line.split("/")[0])
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
78 else:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
79 for line in bowtie_align:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
80 readlist.append(line.split("\t")[0])
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
81 return readlist
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
82
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
83
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
84 # set a reference repeat list for the script
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
85 repeat_list = [listline[9].translate(
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
86 str.maketrans(
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
87 '()/', '___')) for listline in import_text(annotation_file, ' ')]
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
88 repeat_list = sorted(list(set(repeat_list)))
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
89
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
90 # unique mapper counting
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
91 cmd = f"bedtools bamtobed -i {unique_mapper_bam} | \
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
92 bedtools coverage -b stdin -a repnames.bed"
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
93 p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
94 bedtools_counts = p.communicate()[0].decode().rstrip('\r\n').split('\n')
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
95
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
96 # parse bedtools output
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
97 counts = defaultdict(int) # key: repeat names, value: unique mapper counts
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
98 sumofrepeatreads = 0
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
99 for line in bedtools_counts:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
100 line = line.split('\t')
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
101 counts[line[3]] += int(line[4])
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
102 sumofrepeatreads += int(line[4])
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
103 print(f"Identified {sumofrepeatreads} unique reads that mapped to repeats.")
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
104
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
105 # multimapper parsing
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
106 if not paired_end:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
107 args_list = [(metagenome, fastqfile_1) for
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
108 metagenome in repeat_list]
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
109 with ProcessPoolExecutor(max_workers=cpus) as executor:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
110 results = executor.map(run_bowtie, args_list)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
111 else:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
112 args_list = [(metagenome, fastqfile_1) for
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
113 metagenome in repeat_list]
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
114 args_list.extend([(metagenome, fastqfile_2) for
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
115 metagenome in repeat_list])
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
116 with ProcessPoolExecutor(max_workers=cpus) as executor:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
117 results = executor.map(run_bowtie, args_list)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
118
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
119 # Aggregate results (avoiding race conditions)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
120 metagenome_reads = defaultdict(list) # repeat_name: list of multimap reads
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
121 for result in results:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
122 metagenome_reads[result[0]] += result[1:]
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
123
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
124 for name in metagenome_reads:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
125 # read are only once in list
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
126 metagenome_reads[name] = list(set(metagenome_reads[name]))
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
127 # remove "no read" instances
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
128 metagenome_reads[name] = [read for read in metagenome_reads[name]
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
129 if read != ""]
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
130
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
131 # implement repeats_by_reads from the inverse dictionnary metagenome_reads
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
132 repeats_by_reads = defaultdict(list) # readids: list of repeats names
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
133 for repname in metagenome_reads:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
134 for read in metagenome_reads[repname]:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
135 repeats_by_reads[read].append(repname)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
136 for repname in repeats_by_reads:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
137 repeats_by_reads[repname] = list(set(repeats_by_reads[repname]))
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
138
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
139 # 3 dictionnaries and 1 pointer variable to be populated
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
140 fractionalcounts = defaultdict(float)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
141 familyfractionalcounts = defaultdict(float)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
142 classfractionalcounts = defaultdict(float)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
143 sumofrepeatreads = 0
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
144
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
145 # Update counts dictionnary with sets of repeats (was "subfamilies")
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
146 # matched by multimappers
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
147 for repeat_set in repeats_by_reads.values():
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
148 repeat_set_string = ','.join(repeat_set)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
149 counts[repeat_set_string] += 1
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
150 sumofrepeatreads += 1
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
151
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
152 print(f'Identified more {sumofrepeatreads} mutimapper repeat reads')
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
153
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
154 # Populate fractionalcounts
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
155 for key, count in counts.items():
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
156 key_list = key.split(',')
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
157 for i in key_list:
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
158 fractionalcounts[i] += count / len(key_list)
0
f6f0f1e5e940 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/repenrich commit 61e203df0be5ed877ff92b917c7cde6eeeab8310
artbio
parents:
diff changeset
159
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
160 # build repeat_ref for easy access to rep class and rep families
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
161 repeat_ref = defaultdict(dict)
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
162 repeats = import_text(annotation_file, ' ')
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
163 for repeat in repeats:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
164 repeat_name = repeat[9].translate(str.maketrans('()/', '___'))
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
165 try:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
166 repclass = repeat[10].split('/')[0]
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
167 repfamily = repeat[10].split('/')[1]
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
168 except IndexError:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
169 repclass, repfamily = repeat[10], repeat[10]
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
170 repeat_ref[repeat_name]['class'] = repclass
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
171 repeat_ref[repeat_name]['family'] = repfamily
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
172
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
173 # Populate classfractionalcounts and familyfractionalcounts
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
174 for key, value in fractionalcounts.items():
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
175 classfractionalcounts[repeat_ref[key]['class']] += value
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
176 familyfractionalcounts[repeat_ref[key]['family']] += value
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
177
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
178 # print class-, family- and fraction-repeats counts to files
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
179 with open("class_fraction_counts.tsv", 'w') as fout:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
180 for key in sorted(classfractionalcounts):
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
181 fout.write(f"{key}\t{classfractionalcounts[key]}\n")
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
182
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
183 with open("family_fraction_counts.tsv", 'w') as fout:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
184 for key in sorted(familyfractionalcounts):
12
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
185 fout.write(f"{key}\t{familyfractionalcounts[key]}\n")
89e05f831259 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit 212b838f614f1f7b8e770473c026d9c1180722df
artbio
parents: 10
diff changeset
186
13
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
187 with open("fraction_counts.tsv", 'w') as fout:
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
188 for key in sorted(fractionalcounts):
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
189 fout.write(f"{key}\t{repeat_ref[key]['class']}\t"
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
190 f"{repeat_ref[key]['family']}\t"
530626b0757c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/repenrich commit df6b9491ad06e8a85e67c663b68db3cce3eb0115
artbio
parents: 12
diff changeset
191 f"{fractionalcounts[key]}\n")