annotate _modules/seq_processing.py @ 1:ee73cdf35532 draft default tip

"planemo upload"
author bioit_sciensano
date Fri, 11 Mar 2022 16:02:03 +0000
parents 69e8f12c8b31
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
1 ##@file seq_processing.py
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
2 #
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
3 # This file contains functions that are used when running phageterm on multiple machines on a calculation cluster.
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
4 # @param DR_Path directory path where to put DR content.
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
5 from __future__ import print_function
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
6
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
7 from time import gmtime, strftime
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
8 import os
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
9 import numpy as np
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
10 from _modules.utilities import checkReportTitle
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
11 from _modules.readsCoverage_res import loadRCRes
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
12 from _modules.common_readsCoverage_processing import processCovValuesForSeq
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
13 #from SeqStats import SeqStats
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
14 def sum_readsCoverage_for_seq(dir_cov_res,idx_refseq,nb_pieces,inDArgs,fParms,inRawDArgs,dir_seq_res,DR_path):
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
15 if os.path.exists(DR_path):
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
16 if not (os.path.isdir(DR_path)):
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
17 raise RuntimeError("DR_path must point to a directory")
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
18 else:
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
19 os.mkdir(DR_path)
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
20 DR = {"Headful (pac)": {}, "COS (5')": {}, "COS (3')": {}, "COS": {}, "DTR (short)": {}, "DTR (long)": {},
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
21 "Mu-like": {}, "UNKNOWN": {}, "NEW": {}}
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
22 print("going to load ",nb_pieces," files for sequence ",idx_refseq)
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
23 print(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
24 for i in range(0,nb_pieces):
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
25 fic_name = os.path.join(dir_cov_res, "coverage" + str(idx_refseq) + "_" + str(i)+".npz")
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
26 print("loading file: ",fic_name)
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
27 print(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
28 partial_res=loadRCRes(fic_name)
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
29 #npzfile=np.load(fic_name)
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
30 if i == 0:
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
31 termini_coverage = partial_res.termini_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
32 whole_coverage = partial_res.whole_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
33 paired_whole_coverage = partial_res.paired_whole_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
34 phage_hybrid_coverage = partial_res.phage_hybrid_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
35 host_hybrid_coverage = partial_res.host_hybrid_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
36 host_whole_coverage = partial_res.host_whole_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
37 list_hybrid = partial_res.list_hybrid
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
38 insert = partial_res.insert
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
39 paired_missmatch = partial_res.paired_mismatch
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
40 reads_tested = partial_res.reads_tested
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
41 else:
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
42 termini_coverage += partial_res.termini_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
43 whole_coverage += partial_res.whole_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
44 paired_whole_coverage += partial_res.paired_whole_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
45 phage_hybrid_coverage += partial_res.phage_hybrid_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
46 host_hybrid_coverage += partial_res.host_hybrid_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
47 host_whole_coverage += partial_res.host_whole_coverage
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
48 list_hybrid += partial_res.list_hybrid
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
49 insert += partial_res.insert
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
50 paired_missmatch += partial_res.paired_mismatch
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
51 reads_tested += partial_res.reads_tested
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
52
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
53 # fic_name = os.path.join(dir_seq_res, "coverage" + str(idx_refseq))
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
54 # np.savez(fic_name, termini_coverage=termini_coverage, whole_coverage=whole_coverage,
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
55 # paired_whole_coverage=paired_whole_coverage, \
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
56 # phage_hybrid_coverage=phage_hybrid_coverage, host_hybrid_coverage=host_hybrid_coverage, \
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
57 # host_whole_coverage=host_whole_coverage, list_hybrid=list_hybrid, insert=insert,
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
58 # paired_missmatch=np.array(paired_missmatch))
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
59 termini_coverage = termini_coverage.tolist()
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
60 whole_coverage = whole_coverage.tolist()
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
61 paired_whole_coverage = paired_whole_coverage.tolist()
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
62 phage_hybrid_coverage = phage_hybrid_coverage.tolist()
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
63 host_hybrid_coverage = host_hybrid_coverage.tolist()
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
64 host_whole_coverage = host_whole_coverage.tolist()
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
65 list_hybrid = list_hybrid.tolist()
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
66
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
67 if sum(termini_coverage[0]) + sum(termini_coverage[1]) == 0:
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
68 no_match_file="no_natch"+str(idx_refseq)
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
69 f=open(os.path.join(dir_seq_res,no_match_file),"w")
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
70 f.write((checkReportTitle(seq_name[idx_refseq])))
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
71 f.close()
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
72
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
73 print("finished sum, calling processCovValuesForSeq")
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
74 print(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
75 # TODO: having so many values in input and returned is ugly and bad for readibility and maintanability. Group those who are related in structures.
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
76 refseq = inDArgs.refseq_liste[idx_refseq]
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
77 S_stats=processCovValuesForSeq(refseq, inDArgs.hostseq, inDArgs.refseq_name, inDArgs.refseq_liste, fParms.seed,
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
78 inRawDArgs.analysis_name, inRawDArgs.tot_reads, \
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
79 idx_refseq, fParms.test_run, inRawDArgs.paired, fParms.edge, inRawDArgs.host,
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
80 fParms.test, fParms.surrounding, \
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
81 fParms.limit_preferred, fParms.limit_fixed, fParms.Mu_threshold, termini_coverage,
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
82 whole_coverage, \
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
83 paired_whole_coverage, phage_hybrid_coverage, host_hybrid_coverage,
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
84 host_whole_coverage, insert, list_hybrid, reads_tested, DR,DR_path)
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
85 #fic_name = os.path.join(dir_seq_res, "seq_stats" + str(idx_refseq))
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
86 # S_stats.toFile(fic_name) s_stats content is only used in the case where there is only 1 sequence. I'm not interested in this case here since sum_readsCoverage_for_seq will be used for viromes.
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
87 # so, just drop s_stat and forget it...
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
88 # Only writing DR content to file is usefuk in the case of a virome processing over several machines on a cluster.
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
89 print("exit sum_readsCoverage_for_seq")
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
90 print(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
91
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
92
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
93
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
94
69e8f12c8b31 "planemo upload"
bioit_sciensano
parents:
diff changeset
95