|
1 | 1 | from collections import namedtuple |
2 | 2 | from contextlib import contextmanager |
| 3 | +import os |
3 | 4 |
|
4 | 5 | try: |
5 | 6 | from math import log2 |
@@ -1879,6 +1880,29 @@ def meta_entropy(self): |
1879 | 1880 | # Write Results |
1880 | 1881 | # ---------------------------------------- |
1881 | 1882 |
|
| 1883 | + def write(self, filename, *args, **kwargs): |
| 1884 | + """Write results to file. |
| 1885 | +
|
| 1886 | + Raises |
| 1887 | + ------ |
| 1888 | + NotImplementedError |
| 1889 | + If the file format is not supported. |
| 1890 | +
|
| 1891 | + Parameters |
| 1892 | + ---------- |
| 1893 | + filename : str |
| 1894 | + The filename. |
| 1895 | + """ |
| 1896 | + _, ext = os.path.splitext(filename) |
| 1897 | + |
| 1898 | + # remove the dot |
| 1899 | + writer = "write_{}".format(ext[1:]) |
| 1900 | + |
| 1901 | + if hasattr(self, writer): |
| 1902 | + return getattr(self, writer)(filename, *args, **kwargs) |
| 1903 | + |
| 1904 | + raise NotImplementedError("No method found for writing {} files".format(ext)) |
| 1905 | + |
1882 | 1906 | def write_clu(self, filename, states=False, depth_level=1): |
1883 | 1907 | """Write result to a clu file. |
1884 | 1908 |
|
@@ -1977,6 +2001,10 @@ def write_csv(self, filename, states=False): |
1977 | 2001 | """ |
1978 | 2002 | return self.writeCsvTree(filename, states) |
1979 | 2003 |
|
| 2004 | + # for the method "write" |
| 2005 | + write_ftree = write_flow_tree |
| 2006 | + write_nwk = write_newick |
| 2007 | + |
1980 | 2008 |
|
1981 | 2009 | def main(): |
1982 | 2010 | import sys |
|
0 commit comments