# Sample2markers don't generate any pkl files, but instead generate json.bz2 files

**URL:** https://forum.biobakery.org/t/sample2markers-dont-generate-any-pkl-files-but-instead-generate-json-bz2-files/6864
**Category:** StrainPhlAn
**Created:** [March 29, 2024, 6:01am UTC](https://forum.biobakery.org/t/sample2markers-dont-generate-any-pkl-files-but-instead-generate-json-bz2-files/6864 "2024-03-29T06:01:15Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![zn\_Zhu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/zn_zhu/32/2801_2.png) [@zn\_Zhu](https://forum.biobakery.org/u/zn_Zhu)
#### Post date: [March 29, 2024, 6:01am UTC](https://forum.biobakery.org/t/sample2markers-dont-generate-any-pkl-files-but-instead-generate-json-bz2-files/6864/1 "2024-03-29T06:01:15Z")

</div>

I am going to strainphlan4 to abtain strain level data from mgs data, but when I use command sample2markers.py -i sams/\*.sam.bz2 -o consensus\_markers -n 8, I don’t get any pkl files, but json.bz2 files. I don’t know how to solve this problem, please help me, thanks  
.

---

<div class="post-metadata">

### Author: ![zn\_Zhu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/zn_zhu/32/2801_2.png) [@zn\_Zhu](https://forum.biobakery.org/u/zn_Zhu)
#### Post date: [April 1, 2024, 5:52am UTC](https://forum.biobakery.org/t/sample2markers-dont-generate-any-pkl-files-but-instead-generate-json-bz2-files/6864/2 "2024-04-01T05:52:37Z")

</div>

I have solved. In strainphlan4.1 version, the json files replace pkl files.

---

<div class="post-metadata">

### Author: ![L\_kyle](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/l_kyle/32/2839_2.png) [@L\_kyle](https://forum.biobakery.org/u/L_kyle)
#### Post date: [April 27, 2024, 4:04pm UTC](https://forum.biobakery.org/t/sample2markers-dont-generate-any-pkl-files-but-instead-generate-json-bz2-files/6864/3 "2024-04-27T16:04:22Z")

</div>

So how did you solved it? Do you use a older version of strainphlan or metaphlan?

---

<div class="post-metadata">

### Author: ![vitorheidrich](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/vitorheidrich/32/1891_2.png) [@vitorheidrich](https://forum.biobakery.org/u/vitorheidrich)
#### Post date: [April 29, 2024, 7:18am UTC](https://forum.biobakery.org/t/sample2markers-dont-generate-any-pkl-files-but-instead-generate-json-bz2-files/6864/4 "2024-04-29T07:18:49Z")

</div>

Hi, this is not an issue. Since StrainPhlAn 4.1, the output of sample2markers is in JSON format (not .pkl anymore), as described in the [changelog](https://github.com/biobakery/MetaPhlAn/blob/master/CHANGELOG.md) of MetaPhlAn 4.1. The only difference is that now you will provide JSON files during the strainphlan command execution instead of .pkl.

---

<div class="post-metadata">

### Author: ![BlueK77](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@BlueK77](https://forum.biobakery.org/u/BlueK77)
#### Post date: [April 29, 2024, 12:36pm UTC](https://forum.biobakery.org/t/sample2markers-dont-generate-any-pkl-files-but-instead-generate-json-bz2-files/6864/5 "2024-04-29T12:36:27Z")

</div>

Hi, I am facing the same situation but with biobakery\_workflow wmgx. The workflow expects a pkl file not a json.bz2. Do you know how I can modify the workflow in order to change the expected extension?  
Thanks

---

<div class="post-metadata">

### Author: ![BlueK77](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@BlueK77](https://forum.biobakery.org/u/BlueK77)
#### Post date: [April 30, 2024, 7:58am UTC](https://forum.biobakery.org/t/sample2markers-dont-generate-any-pkl-files-but-instead-generate-json-bz2-files/6864/6 "2024-04-30T07:58:08Z")

</div>

Hi there, I’ve managed to solve it by replacing:  
1 biobakery\_workflows/utilities.py  
2 biobakery\_workflows/tasks/shotgun.py

More details here: [Add strainphlan wildcard in one more location · biobakery/biobakery\_workflows@c9a6adb · GitHub](https://github.com/biobakery/biobakery_workflows/commit/c9a6adbc70584cdb49669e582477dae2e2947602)

Best regards

---

<div class="post-metadata">

### Author: ![Kborg000](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/kborg000/32/3070_2.png) [@Kborg000](https://forum.biobakery.org/u/Kborg000)
#### Post date: [February 14, 2025, 6:58pm UTC](https://forum.biobakery.org/t/sample2markers-dont-generate-any-pkl-files-but-instead-generate-json-bz2-files/6864/7 "2025-02-14T18:58:24Z")

</div>

Took me forever to find this post, but so glad I did, (thank you to the OP, all commenters, and especially BlueK77. That being said, I’m going to add more information in case anybody else needs to find this in the future, and like me, had to do more legwork and local code edits still after what was listed here to fix the issue.

1. Important to list for people trying to find this post: the specific error (non-fatal) that gets printed to the command line and in the anadama.log is:

```auto
2025-02-14 12:12:18,899	LoggerReporter	task_failed	ERROR: task 68, strainphlan_sample2markers ____ HD42R4_subsample : Failed! Error message : Failed to produce target `/Users/nyb/test/biobakery_wf_output/strainphlan/HD42R4_subsample_bowtie2/HD42R4_subsample_bowtie2.pkl'. Original exception: Traceback (most recent call last):
  File "/Users/nyb/miniforge3/envs/biobakery_workflows/lib/python3.11/site-packages/anadama2/runners.py", line 219, in _get_task_result
    targ_compares.append(list(target.compare()))
                         ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nyb/miniforge3/envs/biobakery_workflows/lib/python3.11/site-packages/anadama2/tracked.py", line 379, in compare
    stat = os.stat(self.name)
           ^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/Users/nyb/test/biobakery_wf_output/strainphlan/HD42R4_subsample_bowtie2/HD42R4_subsample_bowtie2.pkl'
1

```

It shows up when “strainphlan\_sample2markers\_\_\_\_[your sample name]” fails to complete the run.

1. In BlueK77 's comment, there’s a reference to a change made to utilities.py, I don’t see any evidence of a change made to that file on the GitHub link, and reading my local copy of the file, I don’t see any reference to MetaPhlAn versioning written there. As a result, I did not touch/edit that file. Not knocking the comment, just clarifying in case anybody else gets confused like I was.

2. BlueK77 only lists one link to a Github code edit they made, but technically there were two edits they made in separate commits which are both important (thank you), I’ve listed both links here so people know to check for both in their local files:

[First commit](https://github.com/biobakery/biobakery_workflows/commit/37fe30a035e59ba8391428a4cf3283fdc097f1f5)  
[Second commit](https://github.com/biobakery/biobakery_workflows/commit/c9a6adbc70584cdb49669e582477dae2e2947602)

1. There’s one problem with those edits: They don’t account for the fact that new versions of MetaPhlAn continue to be released, and the command checks the version against a static string. I have MetaPhlAn version 4.1.1, which means it doesn’t look for and detect the json.bz2 files that get created. The janky workaround for this is to edit your local files the same as shown in BlueK77’s git commits but just update what’s written to match the version you’re using (e.g. in my case “4.1.1.” instead of “4”). The proper way to fix this though would be for someone who knows Python to update the code to state that if your installed version of MetaPhlan is version 4 or greater, to use the json.bz2, else use the .pkl extension. I may circle back and make that commit to the GitHub myself when I’m done working on analyzing this data (TBD), but I’m just starting to learn Python, so I imagine someone else could do it cleaner/faster than me.

2. There’s another file that needs to be edited (at least on my system…) in order to get this all to work. I have two separate shotgun.py files in different areas, the file BlueK77 mentioned is here:

```auto
/Users/nyb/biobakery_workflows/biobakery_workflows/tasks

```

While the second file is here:

`/Users/nyb/miniforge3/envs/biobakery_workflows/lib/python3.11/site-packages/biobakery_workflows/tasks/shotgun.py`

They are different files content wise. In the second file, I needed to update line 798 so `extension="pkl"` instead read `extension="json.bz2"`. After that, the error went away, as shown below:

`strainphlan_markers_temp = utilities.name_files(sam_files, output_folder, subfolder="strainphlan", extension="json.bz2", create_folder=True)`

That’s not a great way of fixing it though, again, that should be rewritten to handle both options with a wild card (similar to how BlueK77 fixed the first shotgun.py file to change the extension based on the version of MetaPhlAn you’re using, but with the addition of the recommendation I made to to allow for continued releases of versions past MetaPhlAn 4). The edit I listed only makes sense if you are using \>= version 4 and the file output/extension type doesn’t change in future versions.

1. Finally, after getting past this error, the tasks labeled `strainphplan_print_clades` / `order_clade_list` / `strainphlan_clade_[insert number]` still fail when they go to run.

If you update line 823 in that last shotgun.py file to use “json.bz2” (instead of “pkl”) as shown below, it will fix the error. Again, this will only work if the version of MetaPhlAn you are using is \>=4 and the output file type/extension doesn’t change in future versions.

````auto
        "strainphlan --samples [args[0]]/*/*.json.bz2 --output_dir [args[0]] --print_clades_only > [targets[0]] "+options,
        depends=strainphlan_markers,
        targets=clade_list,
        args=os.path.abspath(os.path.join(os.path.dirname(strainphlan_markers[0]),"..")),
        name="strainphlan_print_clades")```
````
