Mercurial > repos > iuc > vsnp_determine_ref_from_data
annotate vsnp_statistics.py @ 5:a8560decb495 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
author | iuc |
---|---|
date | Tue, 16 Nov 2021 20:12:56 +0000 |
parents | 6853676d2bae |
children | 57bd5b859e86 |
rev | line source |
---|---|
3
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
2 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
3 import argparse |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
4 import gzip |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
5 import os |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
6 from functools import partial |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
7 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
8 import numpy |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
9 import pandas |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
10 from Bio import SeqIO |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
11 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
12 |
5
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
13 class Statistics: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
14 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
15 def __init__(self, reference, fastq_file, file_size, total_reads, mean_read_length, mean_read_quality, reads_passing_q30): |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
16 self.reference = reference |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
17 self.fastq_file = fastq_file |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
18 self.file_size = file_size |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
19 self.total_reads = total_reads |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
20 self.mean_read_length = mean_read_length |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
21 self.mean_read_quality = mean_read_quality |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
22 self.reads_passing_q30 = reads_passing_q30 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
23 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
24 |
3
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
25 def nice_size(size): |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
26 # Returns a readably formatted string with the size |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
27 words = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'] |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
28 prefix = '' |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
29 try: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
30 size = float(size) |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
31 if size < 0: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
32 size = abs(size) |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
33 prefix = '-' |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
34 except Exception: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
35 return '??? bytes' |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
36 for ind, word in enumerate(words): |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
37 step = 1024 ** (ind + 1) |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
38 if step > size: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
39 size = size / float(1024 ** ind) |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
40 if word == 'bytes': # No decimals for bytes |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
41 return "%s%d bytes" % (prefix, size) |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
42 return "%s%.1f %s" % (prefix, size, word) |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
43 return '??? bytes' |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
44 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
45 |
5
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
46 def get_statistics(dbkey, fastq_file, gzipped): |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
47 sampling_size = 10000 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
48 # Read fastq_file into a data fram to |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
49 # get the phred quality scores. |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
50 _open = partial(gzip.open, mode='rt') if gzipped else open |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
51 with _open(fastq_file) as fh: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
52 identifiers = [] |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
53 seqs = [] |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
54 letter_annotations = [] |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
55 for seq_record in SeqIO.parse(fh, "fastq"): |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
56 identifiers.append(seq_record.id) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
57 seqs.append(seq_record.seq) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
58 letter_annotations.append(seq_record.letter_annotations["phred_quality"]) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
59 # Convert lists to Pandas series. |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
60 s1 = pandas.Series(identifiers, name='id') |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
61 s2 = pandas.Series(seqs, name='seq') |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
62 # Gather Series into a data frame. |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
63 fastq_df = pandas.DataFrame(dict(id=s1, seq=s2)).set_index(['id']) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
64 # Starting at row 3, keep every 4 row |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
65 # random sample specified number of rows. |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
66 file_size = nice_size(os.path.getsize(fastq_file)) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
67 total_reads = len(seqs) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
68 # Mean Read Length |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
69 if sampling_size > total_reads: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
70 sampling_size = total_reads |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
71 try: |
3
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
72 fastq_df = fastq_df.iloc[3::4].sample(sampling_size) |
5
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
73 except ValueError: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
74 fastq_df = fastq_df.iloc[3::4].sample(sampling_size, replace=True) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
75 dict_mean = {} |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
76 list_length = [] |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
77 i = 0 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
78 for id, seq, in fastq_df.iterrows(): |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
79 dict_mean[id] = numpy.mean(letter_annotations[i]) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
80 list_length.append(len(seq.array[0])) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
81 i += 1 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
82 mean_read_length = '%.1f' % numpy.mean(list_length) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
83 # Mean Read Quality |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
84 df_mean = pandas.DataFrame.from_dict(dict_mean, orient='index', columns=['ave']) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
85 mean_read_quality = '%.1f' % df_mean['ave'].mean() |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
86 # Reads Passing Q30 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
87 reads_gt_q30 = len(df_mean[df_mean['ave'] >= 30]) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
88 reads_passing_q30 = '{:10.2f}'.format(reads_gt_q30 / sampling_size) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
89 stats = Statistics(dbkey, os.path.basename(fastq_file), file_size, total_reads, mean_read_length, |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
90 mean_read_quality, reads_passing_q30) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
91 return stats |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
92 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
93 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
94 def accrue_statistics(dbkey, read1, read2, gzipped): |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
95 read1_stats = get_statistics(dbkey, read1, gzipped) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
96 if read2 is None: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
97 read2_stats = None |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
98 else: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
99 read2_stats = get_statistics(dbkey, read2, gzipped) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
100 return read1_stats, read2_stats |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
101 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
102 |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
103 def output_statistics(read1_stats, read2_stats, idxstats_file, metrics_file, output_file): |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
104 paired_reads = read2_stats is not None |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
105 if paired_reads: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
106 columns = ['Read1 FASTQ', 'File Size', 'Reads', 'Mean Read Length', 'Mean Read Quality', |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
107 'Reads Passing Q30', 'Read2 FASTQ', 'File Size', 'Reads', 'Mean Read Length', 'Mean Read Quality', |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
108 'Reads Passing Q30', 'Total Reads', 'All Mapped Reads', 'Unmapped Reads', |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
109 'Unmapped Reads Percentage of Total', 'Reference with Coverage', 'Average Depth of Coverage', |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
110 'Good SNP Count', 'Reference'] |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
111 else: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
112 columns = ['FASTQ', 'File Size', 'Mean Read Length', 'Mean Read Quality', 'Reads Passing Q30', |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
113 'Total Reads', 'All Mapped Reads', 'Unmapped Reads', 'Unmapped Reads Percentage of Total', |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
114 'Reference with Coverage', 'Average Depth of Coverage', 'Good SNP Count', 'Reference'] |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
115 with open(output_file, "w") as outfh: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
116 # Make sure the header starts with a # so |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
117 # MultiQC can properly handle the output. |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
118 outfh.write("%s\n" % "\t".join(columns)) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
119 line_items = [] |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
120 # Get the current stats and associated files. |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
121 # Get and output the statistics. |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
122 line_items.append(read1_stats.fastq_file) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
123 line_items.append(read1_stats.file_size) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
124 if paired_reads: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
125 line_items.append(read1_stats.total_reads) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
126 line_items.append(read1_stats.mean_read_length) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
127 line_items.append(read1_stats.mean_read_quality) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
128 line_items.append(read1_stats.reads_passing_q30) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
129 if paired_reads: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
130 line_items.append(read2_stats.fastq_file) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
131 line_items.append(read2_stats.file_size) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
132 line_items.append(read2_stats.total_reads) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
133 line_items.append(read2_stats.mean_read_length) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
134 line_items.append(read2_stats.mean_read_quality) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
135 line_items.append(read2_stats.reads_passing_q30) |
3
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
136 # Total Reads |
5
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
137 if paired_reads: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
138 total_reads = read1_stats.total_reads + read2_stats.total_reads |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
139 else: |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
140 total_reads = read1_stats.total_reads |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
141 line_items.append(total_reads) |
3
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
142 # All Mapped Reads |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
143 all_mapped_reads, unmapped_reads = process_idxstats_file(idxstats_file) |
5
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
144 line_items.append(all_mapped_reads) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
145 line_items.append(unmapped_reads) |
3
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
146 # Unmapped Reads Percentage of Total |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
147 if unmapped_reads > 0: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
148 unmapped_reads_percentage = '{:10.2f}'.format(unmapped_reads / total_reads) |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
149 else: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
150 unmapped_reads_percentage = 0 |
5
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
151 line_items.append(unmapped_reads_percentage) |
3
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
152 # Reference with Coverage |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
153 ref_with_coverage, avg_depth_of_coverage, good_snp_count = process_metrics_file(metrics_file) |
5
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
154 line_items.append(ref_with_coverage) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
155 line_items.append(avg_depth_of_coverage) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
156 line_items.append(good_snp_count) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
157 line_items.append(read1_stats.reference) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
158 outfh.write('%s\n' % '\t'.join(str(x) for x in line_items)) |
3
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
159 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
160 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
161 def process_idxstats_file(idxstats_file): |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
162 all_mapped_reads = 0 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
163 unmapped_reads = 0 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
164 with open(idxstats_file, "r") as fh: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
165 for i, line in enumerate(fh): |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
166 line = line.rstrip('\r\n') |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
167 items = line.split("\t") |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
168 if i == 0: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
169 # NC_002945.4 4349904 213570 4047 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
170 all_mapped_reads = int(items[2]) |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
171 elif i == 1: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
172 # * 0 0 82774 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
173 unmapped_reads = int(items[3]) |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
174 return all_mapped_reads, unmapped_reads |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
175 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
176 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
177 def process_metrics_file(metrics_file): |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
178 ref_with_coverage = '0%' |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
179 avg_depth_of_coverage = 0 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
180 good_snp_count = 0 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
181 with open(metrics_file, "r") as ifh: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
182 for i, line in enumerate(ifh): |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
183 if i == 0: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
184 # Skip comments. |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
185 continue |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
186 line = line.rstrip('\r\n') |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
187 items = line.split("\t") |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
188 if i == 1: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
189 # MarkDuplicates 10.338671 98.74% |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
190 ref_with_coverage = items[3] |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
191 avg_depth_of_coverage = items[2] |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
192 elif i == 2: |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
193 # VCFfilter 611 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
194 good_snp_count = items[1] |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
195 return ref_with_coverage, avg_depth_of_coverage, good_snp_count |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
196 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
197 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
198 parser = argparse.ArgumentParser() |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
199 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
200 parser.add_argument('--dbkey', action='store', dest='dbkey', help='Reference dbkey') |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
201 parser.add_argument('--gzipped', action='store_true', dest='gzipped', required=False, default=False, help='Input files are gzipped') |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
202 parser.add_argument('--output', action='store', dest='output', help='Output Excel statistics file') |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
203 parser.add_argument('--read1', action='store', dest='read1', help='Required: single read') |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
204 parser.add_argument('--read2', action='store', dest='read2', required=False, default=None, help='Optional: paired read') |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
205 parser.add_argument('--samtools_idxstats', action='store', dest='samtools_idxstats', help='Output of samtools_idxstats') |
5
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
206 parser.add_argument('--vsnp_azc_metrics', action='store', dest='vsnp_azc_metrics', help='Output of vsnp_add_zero_coverage') |
3
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
207 |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
208 args = parser.parse_args() |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
209 |
5
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
210 stats_list = [] |
3
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
211 idxstats_files = [] |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
212 metrics_files = [] |
6853676d2bae
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 92f46d4bb55b582f05ac3c4b094307f114cbf98f"
iuc
parents:
diff
changeset
|
213 # Accumulate inputs. |
5
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
214 read1_stats, read2_stats = accrue_statistics(args.dbkey, args.read1, args.read2, args.gzipped) |
a8560decb495
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 2a94c64d6c7236550bf483d2ffc4e86248c63aab"
iuc
parents:
3
diff
changeset
|
215 output_statistics(read1_stats, read2_stats, args.samtools_idxstats, args.vsnp_azc_metrics, args.output) |