Example #1
0
    def test_bad_object(self):
        # Iterable includes elements that are not ggplot objects
        fn = next(filename_gen)
        plots = list(p()) + ['foo']
        with pytest.raises(TypeError):
            save_as_pdf_pages(plots, fn)

        assert_exist_and_clean(fn, "bad ggplot object")
Example #2
0
    def test_plot_exception(self):
        # Force an error in drawing
        fn = next(filename_gen)
        plots = list(p())
        plots[0] += aes(color='unknown')
        with pytest.raises(PlotnineError):
            save_as_pdf_pages(plots, fn)

        assert_exist_and_clean(fn, "Plot exception")
def generate_pdf(pcoa_qza, metadata, file_name, output_dir, point_size=6):
    """
    Generates a single pdf file with multiple PCoA plots

    Input:
        - pcoa_qza: PCoA QIIME2 Artifact
        - metadata: path to metadata file
        - file_name: name of the output file
        - output_dir: directory to save output file in
        - point_size: ggplot point size. Default=6
    """
    pcoa = convert_qiime2_2_skbio(pcoa_qza)

    #generate_pcoa_plot(pcoa, metadata_df, args.target_primary)
    output_name = "PCoA_plots_all.pdf"
    save_as_pdf_pages(run_multiple(pcoa, metadata, point_size),
                      filename=file_name,
                      path=output_dir)
Example #4
0
    def test_save_method(self):
        fn = next(filename_gen)
        with pytest.warns(UserWarning) as record:
            save_as_pdf_pages(p(), fn)

        assert_exist_and_clean(fn, "save method")

        res = ('filename' in str(item.message).lower() for item in record)
        assert any(res)

        # verbose
        fn = next(filename_gen)
        with pytest.warns(None) as record:
            save_as_pdf_pages(p(), fn, verbose=False)
        assert_exist_and_clean(fn, "save method")

        res = ('filename' in str(item.message).lower() for item in record)
        assert not any(res)
    data = {}

    for column in cols:
        filename = column + "." + image_format
        data[column] = filename

    with open(output_path, 'w') as fh:
        json.dump(data, fh)


if __name__ == "__main__":
    parser = args_parse()

    # Print help messages if no arguments are supplied
    if (len(sys.argv) < 2):
        parser.print_help()
        sys.exit(0)

    args = parser.parse_args()

    pcoa = convert_qiime2_2_skbio(args.pcoa_qza)

    # Load metadata into pandas dataframe
    metadata_df = load_metadata(args.metadata)

    #generate_pcoa_plot(pcoa, metadata_df, args.target_primary)
    output_name = "PCoA_plots_all.pdf"
    save_as_pdf_pages(run_multiple(pcoa, args.metadata, args.point_size),
                      filename=args.file_name,
                      path=args.output_dir)
Example #6
0
 def test_height_width(self):
     plots = []
     for i, plot in enumerate(p()):
         plots.append(plot + theme(figure_size=(8+i, 6+i)))
     fn = next(filename_gen)
     save_as_pdf_pages(plots, fn)
Example #7
0
 def test_filename_plot_path(self):
     fn = next(filename_gen)
     save_as_pdf_pages(p(), fn, path='.')
     assert_exist_and_clean(fn, "fn, plot and path")
Example #8
0
 def test_default_filename(self):
     plots = list(p())
     save_as_pdf_pages(plots)
     fn = plots[0]._save_filename('pdf')
     assert_exist_and_clean(fn, "default filename")
Example #9
0
def test_save_as_pdf_pages_closes_plots():
    assert plt.get_fignums() == [], "There are unsaved test plots"
    fn = next(filename_gen)
    save_as_pdf_pages(p(), fn)
    assert_exist_and_clean(fn, "exist")
    assert plt.get_fignums() == [], "ggplot.save did not close the plot"
Example #10
0
 def test_plot_exception(self):
     # Force an error in drawing
     plots = list(p())
     plots[0] += aes(color='unknown')
     with pytest.raises(PlotnineError):
         save_as_pdf_pages(plots)
Example #11
0
 def test_bad_object(self):
     # Iterable includes elements that are not ggplot objects
     plots = list(p()) + ['foo']
     with pytest.raises(TypeError):
         save_as_pdf_pages(plots)