7

I'm printing data in Perl6 with Data::Printer which is a spectacular package, but I am trying to alter parameters and I am not able to.

For example, I want:

HG00112 {
    gained_site                    {
        9:10162   0,
        9:10272   var{HG00112}{gained_site}{9:10162},
        9:10326   var{HG00112}{gained_site}{9:10162},
        ...
}(tied to Perl6::Hash)

to look like

HG00112 {
    gained_site                    {
        9:10162   0,
        9:10272   0,
        9:10326   0,
        ...
}(tied to Perl6::Hash)

for easier readability (I don't care about tied to Perl6::Hash specifically)

this hash element can be seen with JSON:

"HG00112": {
    "discordant_multiallelic_loss": 0,
    "concordant_hom_alt": 4,
    "discordant_het_to_alt": 0,
    "discordant_hom_alt_to_ref": 0,
    "discordant_hom_ref_to_alt": 0,
    "lost_site": 0,
    "concordant_het": 3,
    "discordant_multiallelic_gain": 0,
    "discordant_hom_alt_to_het": 0,
    "discordant_call_to_no_call": 0,
    "discordant_het_to_ref": 0,
    "concordant_hom_ref": 5,
    "concordant_site": 18,
    "discordant_no_call_to_call": 0,
    "concordant_no_call": 6,
    "concordant_multiallelic": 0,
    "gained_site": 0,
    "discordant_hom_ref_to_het": 0
}

I normally load the package using use Data::Printer:from<Perl5>, and using suggestions from

Terminal ANSI colors does not work with Inline::Perl5 (Data::Printer)

I have tried using that with advice from https://metacpan.org/pod/Data::Printer , namely

use Data::Printer:from<Perl5> {show_tied => 0}

& use Data::Printer:from<Perl5> show_tied => 0

but both show the error

Error while importing from 'Data::Printer': no such tag 'show_tied'

How can I get the output from Data::Printer to look like the second code selection, without the ugly var{...?

---edit---

a slight improvement, the script recognizes the option show_tied but still doesn't use it:

my test script:

use JSON::Fast;
use Data::Printer:from<Perl5> 'show_tied', 0;

my %conc = from-json '{"HG00112": {
    "discordant_multiallelic_loss": 0,
    "concordant_hom_alt": 4,
    "discordant_het_to_alt": 0,
    "discordant_hom_alt_to_ref": 0,
    "discordant_hom_ref_to_alt": 0,
    "lost_site": 0,
    "concordant_het": 3,
    "discordant_multiallelic_gain": 0,
    "discordant_hom_alt_to_het": 0,
    "discordant_call_to_no_call": 0,
    "discordant_het_to_ref": 0,
    "concordant_hom_ref": 5,
    "concordant_site": 18,
    "discordant_no_call_to_call": 0,
    "concordant_no_call": 6,
    "concordant_multiallelic": 0,
    "gained_site": 0,
    "discordant_hom_ref_to_het": 0
}}';

p %conc;

shows nearly useless output:

{
    HG00112   {
        concordant_het                 3,
        concordant_hom_alt             var{HG00112}{concordant_het},
        concordant_hom_ref             var{HG00112}{concordant_het},
        concordant_multiallelic        var{HG00112}{concordant_het},
        concordant_no_call             var{HG00112}{concordant_het},
        concordant_site                var{HG00112}{concordant_het},
        discordant_call_to_no_call     var{HG00112}{concordant_het},
        discordant_het_to_alt          var{HG00112}{concordant_het},
        discordant_het_to_ref          var{HG00112}{concordant_het},
        discordant_hom_alt_to_het      var{HG00112}{concordant_het},
        discordant_hom_alt_to_ref      var{HG00112}{concordant_het},
        discordant_hom_ref_to_alt      var{HG00112}{concordant_het},
        discordant_hom_ref_to_het      var{HG00112}{concordant_het},
        discordant_multiallelic_gain   var{HG00112}{concordant_het},
        discordant_multiallelic_loss   var{HG00112}{concordant_het},
        discordant_no_call_to_call     var{HG00112}{concordant_het},
        gained_site                    var{HG00112}{concordant_het},
        lost_site                      var{HG00112}{concordant_het}
    } (tied to Perl6::Hash)
} (tied to Perl6::Hash)
con
  • 5,767
  • 8
  • 33
  • 62
  • 1
    Please show how you create `%HG00112`, so we can try to reproduce – Håkon Hægland Apr 22 '19 at 20:19
  • According to the [source](https://github.com/garu/Data-Printer/blob/master/lib/Data/Printer.pm#L485) `var { }` is used to label circular references (not tied hashes). – Håkon Hægland Apr 22 '19 at 20:35
  • @HåkonHægland I've attached the JSON so that the hash element is reproducible. It's strange, because the various `var` are all different when I print – con Apr 22 '19 at 20:44
  • 1
    I cannot reproduce: https://pastebin.com/jVhsZNuG – Håkon Hægland Apr 22 '19 at 21:02
  • 1
    I only have a few seconds; here's a somewhat wild guess. Please try `{;show_tied => 0}`, `{'show_tied' => 0}`, `{;{show_tied => 0}}`, and `{;{'show_tied' => 0}}`. – raiph Apr 23 '19 at 12:14
  • @raiph I make a hash before calling Data::Printer: `my %parameters = ('show_tied' => 0); use Data::Printer:from %parameters;` this doesn't print an error, but I can't change anything either. However, this still doesn't get rid of all of those nasty vars, `show_tied` doesn't fix it :( the key is to show the values of `cyclic` references – con Apr 23 '19 at 14:07
  • @raiph unfortunately all failed :( – con Apr 26 '19 at 17:00
  • 1
    https://github.com/niner/Inline-Perl5/issues/135 – raiph Apr 26 '19 at 21:28
  • I've tested today with your latest test script (as of Jan 2nd, 2020). It works fine. There are no `var` variables. It will only take a few seconds to review [my test and its results](https://gist.github.com/raiph/cd53ef62373464aee1d4e7b8eac535d4). They confirm the result Håkon linked to in a comment above. There must be *something* that's different on your system. – raiph Jan 02 '20 at 20:20
  • 1
    I'm running Raku/Perl6 2018.03 built on MoarVM, Data::Printer 0.40, Perl 5.30.1 through perlbrew, and Inline::Perl5 version 0.38. perhaps one of these is the cause? `zef` is having issues upgrading `Inline::Perl5` – con Jan 02 '20 at 20:58
  • Hi @con. (You didn't @ mention me so I only just noticed the above comment.) Great info. We can eliminate DP as a difference for now. (Mine also reports as 0.40.) My Perl is 5.22.1. But let's presume Perl isn't the issue for now. My Raku JSON::Fast is 0.10. Yours will be older. It would be good to eliminate that as a cause. While your IP5 is a little old, given you're having problems with upgrading that let's also put that to one side for now. Which brings us to Rakudo. How do you feel about upgrading your Rakudo? Did you install it as part of a Rakudo Star bundle? Thanks for pursuing this. – raiph Jan 02 '20 at 22:13
  • @raiph I installed Rakudo from the standard Ubuntu `sudo apt-get install perl6` I tried upgrading Perl6/Raku a while ago, but was discouraged from upgrading, so I should try rakudobrew to update perl6? – con Jan 02 '20 at 22:26
  • @con (I just tried `sudo apt-get --dry-run install perl6` on my system to see what it said. It appeared to offer something from 2015. That would more than discourage me.) I recommend the latest Rakudo Star. It's always the best tested and supported version of Rakudo. It's the one I used to run your script. I removed my old Rakudo then downloaded Rakudo Star from [here](https://rakudo.org/files). I followed the installation instructions (click the orange button beneath the blue button) but had to fiddle. You may too. I will help if that happens. But I won't be able to tonight or tomorrow. – raiph Jan 02 '20 at 22:44
  • 1
    @raiph thanks, I'm now running Rakudo Star 2019.03.1 built on MoarVM version 2019.03, but it's still not printing correctly. I've tried to update all packages with zef, but that fails too. I think that the key is to turn cyclic references off, but the CPAN page doesn't seem to offer that option. – con Jan 03 '20 at 16:47
  • @con That eliminates Rakudo. Next suspect is JSON::Fast. I don't think you've said which version you have. The oldest version I could downgrade mine to was 0.7 from 21 Dec 2016. It worked fine. Is your JSON::Fast older than 0.7? Last obvious suspect is IP5. On the presumption that JSON::Fast isn't the problem, my next step will be to try an IP5 0.38. – raiph Jan 04 '20 at 00:28
  • @con It would be great if we could just turn off the offending cyclic references, but neither of us see an option that controls that. I thought `use Data::Printer:from kv { name => '' }` *might* have worked but am presuming you tried that and it failed to even remove the three letter `var` prefix from the circular references. You could perhaps figure out how to modify the DP source code to drop the circular references but that would be a pretty crazy thing to do and I'm presuming you've zero interest in that sort of hack. Maybe filtering the output to remove the offending bits is sane? – raiph Jan 04 '20 at 00:34
  • @con I took a quick go at downgrading to IP5 0.38 on my system but failed. I want to now focus on moving your system forward. So, if you're game, when you have time, please copy from a console starting with a `zef upgrade` command and including all the messages that then get displayed. Then go to [GH's gist page](https://gist.github.com), click the `+` at the top right, paste the console content in the big box, click `Create secret gist`, and paste the resulting URL into a comment here. (If you don't have a github.com account then please use some other paste service.) Thanks for your patience. – raiph Jan 05 '20 at 23:18
  • Hi @con. I promised to offer a 500 point bounty on this question if it wasn't sorted soon. And it's still not sorted. I'm more than happy to offer the bonus. But I'm pretty sure it would be a waste to spend it on this SO as it stands. The core issue is really unrelated to this SO and is rather about getting your system upgraded. Perhaps you could post a separate SO that's purely about getting `zef` to work on your system with the definition of "work" being getting your IP5 upgraded to 0.43. Then we can stick a bonus on *that* SO if it looks like it's needed to move things along. Thoughts? – raiph Jan 10 '20 at 22:20

1 Answers1

2

As explained in the Q+A I introduce and link below, you should be able to control DP's name option as follows:

use Data::Printer kv { name => '' }

This will hopefully eliminate at least the var from "the ugly var{..." bit.

And if so, that in turn will at least demonstrate that you are now able to control DP's options.

At best, setting name to '' will switch off the whole circular reference display. (And if not, maybe setting it to 0?)

At worst, you'll still see the three letter "name" var at the start of the circular references and I think we'd then have to figure out why.

If you can comment on how things worked out with kv { name => '' } we'll be making progress.

How do I turn the Perl 5 module Data::Printer's show_tied option off when using it in Raku?

A key part of your question that you explicitly "don't care about ... specifically" (the (tied to Perl6::Hash) bit, which is controlled by DP's show_tied option) is nevertheless very much worth clearly resolving. If nothing else, it involves what will inevitably be a FAQ when trying to set, in a Raku use statement, almost any named option of almost any Perl module.

So I've written a Q+A pair resolving that bit: How do I turn the Perl 5 module Data::Printer's show_tied option off when using it in Raku?.

"the ugly var{..."

The first and most important point I can make right now is that, just like @HåkonHægland++ in one of their comments on your question, I cannot reproduce your problem.

That is to say, when I run your last listed test code, it displays (with some lines elided at ...):

{
    HG00112   {
        concordant_het                 3,
        concordant_hom_alt             4,
        concordant_hom_ref             5,
        concordant_multiallelic        0,
        concordant_no_call             6,
        concordant_site                18,
        discordant_call_to_no_call     0,
        ...
        discordant_no_call_to_call     0,
        gained_site                    0,
        lost_site                      0
    }
}

As you can see, there's none of the "ugly" circular references.

This is with show_tied set to off, as per the above linked Q+A. But even with show_tied left on, per the default, I still get the above, just with a couple (tied to Perl6::Hash) annotations.

So, as @HåkonHægland++ explained in another of their comments on your question, the var{... parts are presumably nothing to do with show_tied but rather due to circular references in your JSON data that you are not sharing with us.

In short, your problem is something about your data and/or about use of DP's name option, not its show_tied option.

I think it's unlikely any of us Raku folk can help with your data (which was presumably not generated by Raku) but we should be able to help make progress and perhaps even resolve your question to the degree it's about appropriately using some DP option.

raiph
  • 31,607
  • 3
  • 62
  • 111
  • even with `show_tied` set as you say, it still outputs the same useless `var` variables :( I've edited to show the test script. – con Dec 23 '19 at 21:04
  • 1
    Thank you for the follow up and editing your question. Sorry it didn't solve the problem. :( But happy holidays anyway. :) If you or I or someone else hasn't figured this out by early January I'll offer a 500 point bounty to try get this sorted. – raiph Dec 24 '19 at 00:13