Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Phybema
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kurtz, Prof. Dr. Stefan
Phybema
Commits
70a85c65
Commit
70a85c65
authored
Sep 12, 2019
by
Birgitta Paeuker
Browse files
Options
Downloads
Patches
Plain Diff
removing the old format converter
parent
a83516fa
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/PHYLIP_format_converter.py
+0
-116
0 additions, 116 deletions
src/PHYLIP_format_converter.py
src/phybema.py
+0
-1
0 additions, 1 deletion
src/phybema.py
with
0 additions
and
117 deletions
src/PHYLIP_format_converter.py
deleted
100755 → 0
+
0
−
116
View file @
a83516fa
#!/usr/bin/env python3
'''
Script to convert the PHYLIP format into the
for neighborjoining needed format.
The input has to be a lower left triangular or full matrix.
Names will be cut after 10 characters and are not allowed
to contain blanks or other seperators.
author: Birgitta Päuker
'''
import
sys
,
re
,
argparse
import
numpy
as
np
import
openFile
'''
Function to convert the PHYLIP Format into the for neighborjoining needed format.
'''
def
convert_format
(
progname
,
progoutfilepath
,
convoutfilepath
):
# Read in the lines
infile
=
openFile
.
open_file
(
progoutfilepath
)
lines
=
infile
.
readlines
()
infile
.
close
()
# Open the outputfile
outfile
=
openFile
.
open_file
(
convoutfilepath
,
'
w
'
)
# Writing the headline
num_genomesre
=
re
.
search
(
r
'
\w+
'
,
lines
[
0
])
num_genomes
=
num_genomesre
[
0
]
# Check if first line is a digit
if
not
(
num_genomes
.
isdigit
()):
sys
.
stderr
.
write
(
"
{}: The first line of the distmatrix from {} needs to
"
"
be the number of sequences
"
.
format
(
sys
.
argv
[
0
],
progname
))
exit
(
1
)
outfile
.
write
(
"
# pairwise dist values for {} sequences
\n
"
.
format
(
num_genomes
))
distmatrix
=
np
.
zeros
((
int
(
num_genomes
),
int
(
num_genomes
)))
linegenomeidx
=
0
testfullmatrix
=
False
# Convert distances into needed format
for
line
in
lines
[
1
:]:
'''
for normal PHYLIP Format the used seperator is
\t
.
But some are using
"
"
as seperator
Replacing sep
\t
with
"
"
'''
line
=
line
.
replace
(
"
\t
"
,
"
"
)
values
=
line
.
strip
().
split
(
'
'
)
# Remove all empty string elements
values
=
list
(
filter
(
None
,
values
))
# Replace a nan in the distancematrix with distance 1.0
for
value
in
values
[
1
:]:
if
(
value
.
isalpha
()):
if
value
==
"
nan
"
:
values
[
values
.
index
(
value
)]
=
1.0
sys
.
stdout
.
write
(
"
# Replaced the value nan in {} with distance 1.0
\n
"
.
format
(
progoutfilepath
))
else
:
sys
.
stderr
.
write
(
"
There are characters in the distancematrix in file
"
"
{}
\n
"
.
format
(
progoutfilepath
))
exit
(
1
)
# Testing if there are enough distances per sequence in a line
if
(
len
(
values
)
<
linegenomeidx
+
1
):
sys
.
stderr
.
write
(
"
{}: In the distmatrix of {} are not enough distances
"
"
per sequence.
\n
"
.
format
(
sys
.
argv
[
0
],
progname
))
exit
(
1
)
# Writing the name of the genom (10 characters) with its index
name
=
values
[
0
]
outfile
.
write
(
"
{}
\t
{}
\n
"
.
format
(
linegenomeidx
,
name
[:
10
]))
# Filling the distmatrix:
if
not
(
linegenomeidx
==
0
):
# working with the lower left triangular matrix
# for each processed rowgenom read in the dist to the current linegenome
for
row
in
range
(
linegenomeidx
):
distmatrix
[
linegenomeidx
][
row
]
=
values
[
row
+
1
]
# if full matrix, fill full distmatrix for later test
if
(
len
(
values
)
>
linegenomeidx
+
2
):
testfullmatrix
=
True
for
row
in
range
(
linegenomeidx
+
1
,
len
(
values
)
-
1
):
distmatrix
[
linegenomeidx
][
row
]
=
values
[
row
+
1
]
linegenomeidx
=
linegenomeidx
+
1
# Testing for a full matrix if it is semetric, to find cases like fswm and
# kmacs where there are no seperators between the name and the first distance.
if
(
testfullmatrix
):
for
i
in
range
(
distmatrix
.
shape
[
0
]):
for
j
in
range
(
i
+
1
,
distmatrix
.
shape
[
1
]):
if
(
distmatrix
[
i
][
j
]
!=
distmatrix
[
j
][
i
]):
sys
.
stderr
.
write
(
"
{}: The distancmatrix of {} can not be converted
"
"
into needed format.
\n
Please search for the cause in
"
"
file {}.
\n
A possible reason might be a missing
"
"
blank between genomename and first distance.
\n
"
.
format
(
sys
.
argv
[
0
],
progname
,
progoutfilepath
))
exit
(
1
)
# Print into outputfile:
for
lineidx
in
range
(
linegenomeidx
):
for
rowidx
in
range
(
lineidx
+
1
,
linegenomeidx
):
# write dist from linegenome to rowgenome
dist
=
distmatrix
[
rowidx
][
lineidx
]
outfile
.
write
(
"
dist {} {} {:.10f}
\n
"
.
format
(
lineidx
,
rowidx
,
dist
))
outfile
.
close
()
This diff is collapsed.
Click to expand it.
src/phybema.py
+
0
−
1
View file @
70a85c65
...
...
@@ -6,7 +6,6 @@ author: Birgitta Päuker
'''
import
sys
,
os
,
shutil
import
PHYLIP_format_converter
as
fc
import
ete
import
callTreeCmp
as
treecmp
import
callProg
...
...
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