Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get user history #5

Merged
merged 11 commits into from
Oct 8, 2018
Merged

Conversation

ValentinChCloud
Copy link
Contributor

Hello Björn,
I take this opportunity (#4) to propose a function
Actually I use this to get the user history ( not a specific dataset). I think it could be useful in case where you want to get the list of all datasets and their names ( and choose only csv,txt etc..) , to display it to the user, and (this is the point) to display it on client side to have a dropdown button for example .
image

There is the R function to get the dataset and parse for only csv file_type.

gx_get_user_history <- function( history_id="None"){
    library('rPython')
    python.load("/usr/local/bin/get_user_history.py")
    x <- python.call("user_history",history_id)
    v<-list()
    l=length(x)
    for (y in 1:l) {
        if(is.null(x[[y]])) { 
            print("nothing to see")
        }else{
            if(x[[y]]$'extension' == 'csv'){
                name<-paste(x[[y]]$'hid',x[[y]]$'name')
                id<-unname(x[[y]]$'hid')
                v[[name]]<-id
            }
        }
     }

 return v
}

It's an shiny use case example :

Once you get v as a named list, you can easely display it as show above. When the user click on the name of his dataset, in fact this is the hid wil be used to get the dataset.

Copy link
Owner

@bgruening bgruening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool enhancement, I added a few comments and I think you also need to adjust the setup.py file to install the new binary.

hc = HistoryClient(gi)
history = hc.show_history(history_id, visible=True, contents=True)
# I add a None element, to be sure the list has at least 2 elements
# It's neccessary, in the case case where the list give to R, it will
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/case//

# I add a None element, to be sure the list has at least 2 elements
# It's neccessary, in the case case where the list give to R, it will
# be interpreted as a list of list, and not only a list.
history.append(None)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we hack around this on the R side? The None will be confusing I guess for other users of this function.


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Connect to Galaxy through the API')
parser.add_argument('--action', help='Action to execute', choices=['get', 'put'])
parser.add_argument('--action', help='Action to execute', choices=['get', 'put','get_history_user'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_user_history?

@ValentinChCloud
Copy link
Contributor Author

Yes, we can do this on the R side, but the function python.call of rPython library, will return :

  • a list in the case where there is only one dataset
  • a list of list in multiple datasets case

On the R side it could look like

library('rPython')
python.load("/usr/local/bin/get_user_history.py")
x <- python.call("user_history",history_id)
v<-list()

# If the first element is not a list, it's mean only one dataset

if(is.list(x[[1]]) == FALSE) {
    if(x$'extension' == 'csv'){
                name<-paste(x$'hid',x$'name')
                id<-unname(x$'hid')
                v[[name]]<-id
    }
}else{
    l=length(x)
    for (y in 1:l){
        if(x[[y]]$'extension' == 'csv'){
                name<-paste(x[[y]]$'hid',x[[y]]$'name')
                id<-unname(x[[y]]$'hid')
                v[[name]]<-id
            }
     }
}

This is a bit heavy, but it's imposed by the fact R doesn't handle dictionnary objet as Python (mentioned there

I guess you right, I shouldn't have modified the python function to suit R problems, the function has to be the most flexible possible.

@ValentinChCloud
Copy link
Contributor Author

Hello @bgruening, I have noticed this PR is still open , may be it can be merged if it's ok for you?

@bgruening
Copy link
Owner

Sorry, forgot about that :(

@bgruening bgruening merged commit ffd00b1 into bgruening:master Oct 8, 2018
@bgruening
Copy link
Owner

Thanks! @erasche is working on a new awesome concept of mounting in entire histories during container start, so this will also make your life easier we hope!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants