Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
popsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
A compter du 1er avril, attention à vos pipelines :
Nouvelles limitations de Docker Hub
Show more breadcrumbs
SVdetection
popsim
Commits
6bf39874
Commit
6bf39874
authored
8 years ago
by
Floreal Cabanettes
Browse files
Options
Downloads
Patches
Plain Diff
Force polymorphism is now optional
parent
83928951
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README
+2
-0
2 additions, 0 deletions
README
build_pop.py
+36
-23
36 additions, 23 deletions
build_pop.py
with
38 additions
and
23 deletions
README
+
2
−
0
View file @
6bf39874
...
...
@@ -61,6 +61,8 @@ If increment is not specified, it defaults to 1.
1 line by SV type, like above.
IMPORTANT: only deletion is implemented yet.
We use SVsim to generate positions of SVs. https://github.com/GregoryFaust/SVsim
...
...
This diff is collapsed.
Click to expand it.
build_pop.py
+
36
−
23
View file @
6bf39874
...
...
@@ -14,6 +14,8 @@ parser.add_argument("--sv-list", help="File containing the SVs", required=True)
parser
.
add_argument
(
"
--coverage
"
,
help
=
"
Coverage of reads (default: 15)
"
,
default
=
15
,
type
=
int
)
parser
.
add_argument
(
"
--output-directory
"
,
help
=
"
Output directory (default: res)
"
,
default
=
"
res
"
)
parser
.
add_argument
(
"
--tmp-directory
"
,
help
=
"
Temporary directory (default: tmp)
"
,
default
=
"
tmp
"
)
parser
.
add_argument
(
"
--force-polymorphism
"
,
help
=
"
Force polymorphism for each SV
"
,
action
=
'
store_const
'
,
const
=
True
,
default
=
False
)
args
=
parser
.
parse_args
()
...
...
@@ -31,9 +33,33 @@ if not os.path.isfile(reference + ".fai"):
os
.
system
(
"
samtools faidx
"
+
reference
)
#############
# FUNCTIONS #
#############
def
allele
(
frequency
):
return
1
if
random
.
uniform
(
0
,
1
)
<
frequency
else
0
def
get_genotypes_for_inds
():
all_genotypes
=
[]
genotypes_row
=
[]
for
i
in
range
(
1
,
nb_inds
+
1
):
genotype
=
str
(
allele
(
freq
))
+
"
/
"
+
str
(
allele
(
freq
))
genotype_data
=
vcf
.
model
.
_Call
(
None
,
"
INDIV_
"
+
str
(
i
),
vcf
.
model
.
make_calldata_tuple
(
"
GT
"
)(
GT
=
genotype
))
genotypes_row
.
append
(
genotype_data
)
all_genotypes
.
append
(
genotype
)
return
all_genotypes
,
genotypes_row
def
svsort
(
sv
,
chr
):
"""
Function to sort regions
"""
return
int
(
genotypes_for_inds
[
chr
][
sv
][
"
start
"
])
prg_path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
not
os
.
path
.
isdir
(
tmp_dir
):
...
...
@@ -93,22 +119,16 @@ with open(os.path.join(tmp_dir, "reference-sv.bed"), "r") as bed:
if
parts
[
0
]
not
in
genotypes_for_inds
:
genotypes_for_inds
[
parts
[
0
]]
=
{}
genotypes_for_inds
[
parts
[
0
]][
parts
[
3
]]
=
{
"
start
"
:
int
(
parts
[
1
]),
"
end
"
:
int
(
parts
[
2
]),
"
genotypes
"
:
[]}
genotypes
=
[]
polymorph
=
False
while
not
polymorph
:
unique_genotypes
=
set
()
all_genotypes
=
[]
genotypes_tmp
=
[]
for
i
in
range
(
1
,
nb_inds
+
1
):
genotype
=
str
(
allele
(
freq
))
+
"
/
"
+
str
(
allele
(
freq
))
genotype_data
=
vcf
.
model
.
_Call
(
None
,
"
INDIV_
"
+
str
(
i
),
vcf
.
model
.
make_calldata_tuple
(
"
GT
"
)(
GT
=
genotype
))
genotypes_tmp
.
append
(
genotype_data
)
unique_genotypes
.
add
(
genotype
)
all_genotypes
.
append
(
genotype
)
polymorph
=
len
(
unique_genotypes
)
>
1
if
polymorph
:
genotypes
+=
genotypes_tmp
genotypes_for_inds
[
parts
[
0
]][
parts
[
3
]][
"
genotypes
"
]
=
[
x
.
split
(
"
/
"
)
for
x
in
all_genotypes
]
# Get genotypes:
if
args
.
force_polymorphism
:
polymorph
=
False
while
not
polymorph
:
all_genotypes
,
genotypes
=
get_genotypes_for_inds
()
polymorph
=
len
(
set
(
all_genotypes
))
>
1
else
:
all_genotypes
,
genotypes
=
get_genotypes_for_inds
()
genotypes_for_inds
[
parts
[
0
]][
parts
[
3
]][
"
genotypes
"
]
=
[
x
.
split
(
"
/
"
)
for
x
in
all_genotypes
]
info
=
{
"
END
"
:
int
(
parts
[
2
]),
"
AF
"
:
freq
}
vcf_record
=
vcf
.
model
.
_Record
(
parts
[
0
],
int
(
parts
[
1
]),
parts
[
3
],
"
N
"
,
[
vcf
.
model
.
_SV
(
"
DEL
"
)],
"
.
"
,
"
.
"
,
info
,
"
GT
"
,
[
0
],
genotypes
)
...
...
@@ -123,13 +143,6 @@ with open(os.path.join(tmp_dir, "reference-sv.bed"), "r") as bed:
print
(
"
BUILD FASTA GENOME FOR EACH INDIVIDUAL...
\n
"
)
def
svsort
(
sv
,
chr
):
"""
Function to sort regions
"""
return
int
(
genotypes_for_inds
[
chr
][
sv
][
"
start
"
])
fasta_orig
=
SeqIO
.
index
(
reference
,
"
fasta
"
)
for
chr
,
svs_infos
in
genotypes_for_inds
.
items
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment