Skip to content
Snippets Groups Projects
Commit 82c465dc authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Allow to use custom frequencies for variants

parent 46eedc90
No related branches found
No related tags found
No related merge requests found
......@@ -69,6 +69,10 @@ def parse_args():
const=True, default=False)
parser.add_argument("-pd", "--proba-del", help="Probabilty to have a deletion", type=float, default=0.000001)
parser.add_argument("-pi", "--proba-inv", help="Probablity to have an insertion", type=float, default=0.000001)
parser.add_argument('-fd', '--freq-del', type=float, required=False,
help="Frequencies choices for deletions, space separated", nargs="+", default=[0.2, 0.5])
parser.add_argument('-fi', '--freq-inv', type=float, required=False,
help="Frequencies choices for inversions, space separated", nargs="+", default=[0.2, 0.5])
parser.add_argument("-l", "--read-len", help="Generate reads having a length of LEN", type=int, default=100)
parser.add_argument("-m", "--insert-len-mean", help="Generate inserts (fragments) having an average length of LEN",
type=int, default=300)
......@@ -528,8 +532,8 @@ def confirm(deletions: dict, inversions: dict, variants: dict, printer: Print, a
return True
def init(output_dir, force_outputdir, sv_list, nstretches, nb_inds, reference, proba_del, proba_inv, haploid,
force_polymorphism, coverage, read_len, insert_len_mean, insert_len_sd, threads, genotypes=None,
def init(output_dir, force_outputdir, sv_list, nstretches, nb_inds, reference, proba_del, proba_inv, freq_del, freq_inv,
haploid, force_polymorphism, coverage, read_len, insert_len_mean, insert_len_sd, threads, genotypes=None,
min_deletions=1, min_inversions=1, max_try=10, quiet=True, stdout=None, stderr=None):
printer = Print(stdout=stdout, stderr=stderr)
......@@ -576,7 +580,8 @@ def init(output_dir, force_outputdir, sv_list, nstretches, nb_inds, reference, p
nb_deletions = -1 # To allow 0 deletions
nb_inversions = -1 # To allow 0 inversions
nb_try = 0
sv_sim = VariantsSimulator(sv_list, nstretches, threads, stdout, stderr)
sv_sim = VariantsSimulator(sv_list=sv_list, nstretches=nstretches, threads=threads, stdout=stdout,
stderr=stderr, freq_del=freq_del, freq_inv=freq_inv)
if "DEL" not in sv_sim.variants:
proba_del = 0
if "INV" not in sv_sim.variants:
......
......@@ -23,7 +23,8 @@ class bcolors:
class VariantsSimulator:
def __init__(self, sv_list: str = None, nstretches: str = None, threads: int = -1, stdout=None, stderr=None):
def __init__(self, sv_list: str = None, freq_del: list=(0.2, 0.5), freq_inv: list=(0.2, 0.5), nstretches: str = None,
threads: int = -1, stdout=None, stderr=None):
self._epsilon = None
if sv_list is None:
sv_list = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "defaults.rules")
......@@ -34,6 +35,8 @@ class VariantsSimulator:
self.nstretches = self.__load_nstretches(nstretches)
self.deletions = {}
self.invertions = {}
self.freq_del = freq_del
self.freq_inv = freq_inv
self.threads = threads if threads > -1 else multiprocessing.cpu_count()
self.stdout = stdout
self.stderr = stderr
......@@ -303,7 +306,7 @@ class VariantsSimulator:
else:
self.print_ok("N-stretch filter: OK", print_message_header)
i = start
freq = 0.2 if random.uniform(0, 1) < 0.5 else 0.5
freq = random.choice(self.freq_del)
deletions[chrm].append({
"name": "DEL{0}_{1}".format(chrm, nb_dels_on_ch),
"start": start,
......@@ -345,7 +348,7 @@ class VariantsSimulator:
else:
self.print_ok("N-stretch filter: OK", print_message_header)
i = start
freq = 0.2 if random.uniform(0, 1) < 0.5 else 0.5
freq = random.choice(self.freq_inv)
inversions[chrm].append({
"name": "INV{0}_{1}".format(chrm, nb_inv_on_ch),
"start": start,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment