2020from collections import Counter , defaultdict
2121import numpy as np
2222import matplotlib
23- import matplotlib .pyplot as plt
2423matplotlib .use ('Agg' )
24+ import matplotlib .pyplot as plt
2525
2626
2727def parse_usepopinfo (fhandle , end_string ):
2828 """
2929 Parses Structure results when using the USEPOPINFO flag.
3030 """
31- qvalues_dic = defaultdict (float )
3231 qvalues = np .array ([])
32+ poplist = []
3333 # Skip subheader
3434 next (fhandle )
3535 for line in fhandle :
3636 if line .strip () != "" :
3737 if line .strip ().lower ().startswith (end_string ):
38- print (qvalues )
3938 return qvalues , poplist
4039
40+ qvalues_dic = defaultdict (float )
4141 fields = line .strip ().split ("|" )[:- 1 ]
4242 # Assumed pop
4343 qvalues_dic [fields [0 ].split ()[3 ]] = float (fields [0 ].split ()[5 ])
@@ -46,13 +46,13 @@ def parse_usepopinfo(fhandle, end_string):
4646 prob = sum (map (float , pop .split ()[- 3 :]))
4747 qvalues_dic [pop .split ()[1 ][:- 1 ]] = prob
4848 clv = []
49- poplist = sorted (list (qvalues_dic .keys ()))
50- for percents in poplist :
51- clv .append (qvalues_dic [percents ])
49+ for percents in sorted (list (map (int , list (qvalues_dic .keys ())))):
50+ clv .append (qvalues_dic [str (percents )])
5251 try :
5352 qvalues = np .vstack ((qvalues , clv ))
5453 except ValueError :
5554 qvalues = np .array (clv )
55+ poplist .append (int (fields [0 ].split ()[3 ]))
5656
5757
5858def parse_nousepopinfo (fhandle , end_string ):
@@ -65,7 +65,6 @@ def parse_nousepopinfo(fhandle, end_string):
6565 for line in fhandle :
6666 if line .strip () != "" :
6767 if line .strip ().lower ().startswith (end_string ):
68- print (qvalues )
6968 return qvalues , poplist
7069
7170 fields = line .strip ().split ()
@@ -121,16 +120,19 @@ def dataminer(indfile_name, fmt, popfile=None):
121120 if next (file_handle ).lower ().startswith (popinfo_string ):
122121 qvalues , numlist = parse_usepopinfo (file_handle ,
123122 end_parsing_string )
123+ break
124124 else :
125125 qvalues , numlist = parse_nousepopinfo (file_handle ,
126126 end_parsing_string )
127- if not popfile :
128- poplist = numlist
127+ break
128+ #if not popfile:
129+ #poplist = numlist
129130
130131
131132 if not popfile :
132133 # Transform poplist in convenient format, in which each element
133134 # is the boundary of a population in the x-axis
135+ poplist = numlist
134136 poplist = Counter (poplist )
135137 poplist = [([x ]* y , None ) for x , y in poplist .items ()]
136138
@@ -248,7 +250,8 @@ def plotter(qvalues, poplist, outfile):
248250 plt .yticks ([])
249251 plt .xticks ([])
250252
251- plt .savefig ("{}.pdf" .format (outfile ), bbox_inches = "tight" )
253+
254+ plt .savefig ("{}.svg" .format (outfile ), bbox_inches = "tight" )
252255
253256
254257def main (result_files , fmt , outdir , popfile = None ):
0 commit comments