forked from roblanf/SRHtests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_bad_partitions.py
44 lines (38 loc) · 1.35 KB
/
write_bad_partitions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 5 10:16:43 2020
@author: Suha Naser-Khdour
"""
import codecs
import pandas as pd
import sys
def compare(All,table,Fail):
'''
input
All: is the file with all the partitions (PARTITION_FILE) in Nexus format
table: is the csv output file from IQ-TREE with the MaxSym test results
output
Fail: is the file that contains all the partitions that failed the MaxSym test
'''
df = pd.read_csv(table, comment='#')
bad_part = df.loc[df.SymPval < 0.05].Name.values
with open(All,'r') as inf, codecs.open(Fail,'w', "utf-8-sig") as outf:
outf.writelines('#NEXUS\n')
outf.writelines('begin sets;\n')
for line in inf:
if any(word in line for word in bad_part):
outf.write(line)
outf.writelines('#end;\n')
return
def FailedPart():
if len(sys.argv) == 1:
raise SystemExit('Error: No files were detected')
elif len(sys.argv) == 2:
raise SystemExit('Error: some files are missing')
elif len(sys.argv) == 3:
raise SystemExit('Error: some files are missing')
elif len(sys.argv) > 4:
raise SystemExit('Error: too many arguments')
compare(sys.argv[1], sys.argv[2], sys.argv[3])
if __name__ == '__main__':
FailedPart()