Awesome job!
I don't know if this is possible, but can plugins like this be accessed through the artifact API?
I got a small workaround going for making Krona plots using the python API. It's not using this plugin, but I might as well share it here, in case anybody else is trying to do this. It's a bit hacky, since it requires saving every sample as a .txt in a format that's acceptable for KronaTools, and then passing all of them to KronaTools with a subprocess.
You need to have KronaTools installed! Releases · marbl/Krona · GitHub
DF = taxa.methods.collapse( qiime2.Artifact.load(Dir + 'FeatTable.qza'), qiime2.Artifact.load(Dir + 'FeatTax.qza'), level=7 ).collapsed_table.view(pd.DataFrame) Params = ["ktImportText", '-o', Dir + 'Krona.html'] # String list to pass to subprocess later os.mkdir(Dir+'Temp') # Folder to store .txt files for each sample for i in range(len(DF)): Row = DF.iloc[i:i + 1] # get row for the Nth sample Row = Row.loc[:, (Row != 0).any(axis=0)] # remove columns that are 0 NewDF = [i.split(';') for i in Row.columns] # Get a list of the column names with Row.columns, and split it into a list of lists using ; as the delimiter. NewDF = pd.DataFrame(NewDF) # When turning a list of lists into a df, each sublist becomes a column. This way we get 7 columns, corresponding to each level of taxonomy NewDF.index = Row.iloc[0].tolist() # Turn the row of values into the index of the new DF NewDF.to_csv(Dir+'Temp/' + Row.index[0] + '.txt', sep='\t', header=False, index=True) # Save. Row.index[0] is the sample name. Params.append(Dir + 'Temp/' + Row.index[0] + '.txt') # Add the location of the .txt to the parameters subprocess.run([*Params]) shutil.rmtree('Qiime/Temp')
Hi @MaxEdge, welcome to the QIIME 2 Forum!
It shouldn't be a problem at all to access q2-krona through the artifact API if you have the plugin installed in your QIIME 2 environment. You would just access this in the same way you would other plugins. There's generally no difference between the plugins that are distributed along with QIIME 2 and community plugins, aside from how they're distributed. Have you run into issues? If so, share some details and we'll be happy to try to help.
Hey, thanks for responding!
Unless I'm doing something wrong, I believe the command should be
qiime2.plugins.krona.methods.plot(
qiime2.Artifact.load(Dir+'Qiime/FeatTable.qza')
).visualization.save('KRONA.qzv')
But I'm getting
AttributeError: module 'qiime2.plugins.krona.methods' has no attribute 'plot'
I don't have q2-krona installed right now so I can't test this myself, but could you try calling the following:
qiime2.plugins.krona.actions.plot
I swapped methods
for actions
there.
In QIIME 2, there are three types of Actions
: Methods
, Visualizers
, and Pipelines
. plot
sounds like a Visualizer
to me (but it could also be a Pipeline
), so it won't be accessible under qiime2.plugins.krona.methods
, but should be under qiime2.plugins.krona.visualizers
, or under qiime2.plugins.krona.actions
, where you can find all three action types. I tend to call actions via qiime2.plugins.krona.actions
in the ArtifactAPI because all actions are accessible there, so I don't necessarily have to know what type of action I'm calling when I call it.
Oh, I see. I didn't realize there were different actions, and assumed they all used 'methods'. Indeed, it is a visualizer, and must be called as such:
qiime2.plugins.krona.visualizers.plot(
qiime2.Artifact.load(Dir+'Qiime/FeatTable.qza')
).visualization.save('KRONA.qzv')
And now it works.
Thanks a lot!
Fantastic! Thanks for letting me know!
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.