Attributes and usage of artifact objects in python

Hi everyone!
First of all I would like to thank you all for the help you give here, you’re so valueable!! I’ve found a lot of posts that really helped me, but unluckly this doesn’t seem to be enough for the newbie like me!

So here I am with my problem:

  • I have some fastq files that I would like to import in qiime, in order to try the moving pitcure tutorial that I’ve only studied from the web so far.
  • The tool I’m using is a jupiter notebook, and for this reason I started using the Artifact module.
  • I’ve taken inspiration from - among the others - this thread and I got (I think!!) an artifact that gives me this:
    <artifact: SampleData[SequencesWithQuality] uuid: e770a98c-68a8-4e42-80ac-3bb6b821fbed>

I’m a bit confused now about how to proceed. Everything I try to do on this artifact object seems to be inappropriate. For example I tried:

feature_table.visualizers.summarize(artifact_data.per_sample_sequences)

that turned out with the error

AttributeError: 'Artifact' object has no attribute 'per_sample_sequences'

What are the attributes available for this object? How can I access to it?
How can I get, for example, the feature table?
As I said, I would like to replicate the moving picture tutorial, or do something close to it.

Thanks in advance for the help

I.

1 Like

Hi @IreneSA,

Welcome to the :qiime2: forum!

I think you have a few issues here. Im going to start simple and then work my way down.

Okay, so the first issue is running QIIME in Jupyter and having to use the Artifact API vs CLI-API.
Im personally, write a lot of QIIME2-CLI in a Jupyter notebook. (I also write a lot of qiime2-API in notebooks, but that’s a special case, typically). Unless, like, you’re a hard-core python person, I actually like the CLI interface better because it’s cleaner, and IMO, easier to navigate.

There are two solutions for Jupyter. One option, if you just want pure command line QIIME 2 code, is to get a bash kernel. It’s pip-installable, and if you can install QIIME natively, you can install this kernel. I’ve got one in most of my QIIME versions, and you just run the bash in your cell:

ls 

qiime demux summarize \
 --i-data demux-seqs.qza \
 --o-visualization demux-seqs.qzv

The second option is to use a standard python notebook, with then you prefix your bash commands with an exclamation point (!), for example, try

var = 'cat'
!ls
!echo $cat

in a notebook. You’ll get the bash result. Alternatively, if your sequences are in the current directory in demux-seqs.qza, you can just run the command in the python notebook inline:

!qiime demux summarize \
 --i-data demux-seqs.qza \
 --o-visualization demux-seqs.qzv

With this approach, you can mix and match your python and bash. For example, you could write your manifest with pandas and save it, then run the command line. …Its also good if you’re bad at bash loops (:raising_hand_woman:).


But, then, answering your real question: with the Artifact API, you pass the full Artifact. Which would look like,

from qiime2 import Artifact, Metadata
from qiime2.plugins import feature_table

seq_artifact = Artifact.load(some_per_sample_data)

feature_table.visualizers.summarize(seq_artifact)

… But, if you run this code, you’ll get an error! The summarize visualizer int he feature-table plugin won’t take a SampleData[SequencesWithQuality] semantic type. You want to use the summarize method in the demux plug in instead, so

from qiime2 import Artifact, Metadata
from qiime2.plugins import demux as q2_demux # incase you use python packages with the same name

seq_artifact = Artifact.load(some_per_sample_data)

q2_demux.visualizers.summarize(seq_artifact)

Best,
Justine

4 Likes

Hi Justine,
thank you sooo much. It worked like a charm.
And yes, you’re probablyr right, I should try to use command line code inside the notebook and I promise I will :slight_smile:, in order to compare pros and cons of both the approaches at least.

Thank you again,

Bests

Irene

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.