Pybids: filtering for particular subjects/sessions

Hey! I’m writing a class that has this as the init.

def __init__(self, bdir, subjects=None, sessions=None):
    self.layout = bids.BIDSLayout(bdir)
    self.bdir = bdir
    self.df = self.layout.to_df(filters={"absolute_paths": True})
    self.df = self.df[self.df.suffix != "description"]  # no metadata file
    self.subjects = subjects
    self.sessions = sessions

‘subjects’ and ‘sessions’ can each either be None, or List.
If 'subjects is None, I’m just using every subject in the dataset.
Same for sessions if ‘sessions’ is None.

I’d like self.df to only include the subjects and sessions specified as arguments, but I can’t seem to figure out how to do this with filters.

Even if I try layout.to_df(filters={'subject': 'sub-002427'}) (one of the three subjects in my test dataset), I still get a dataframe with all three subjects. I’ve tried a lot of regex with filters={'session': ..., 'subject': ...,}, but nothing seems to actually filter stuff. Here’s what I mean: https://www.dropbox.com/s/sgjtt00s2g2sc9v/Screenshot%202019-11-06%2008.44.07.png?dl=0

This seems like it should be a pretty straightforward thing to do - can anyone who knows pybids better than me help?

bids.__version__ returns ‘0.9.4’.

Thanks! I can post the full class if that would be useful, but I figure just the init takes up less space for now.

(Sorry if I posted this in the wrong place - this is my first time posting on neurostars!)

EDIT: I actually just refactored my code to avoid using dataframes entirely – now all I need to finish it is a list of all possible (subject, session) tuples in layout. Can probably figure this out myself now, but if anyone has a quick way to grab that off the top of their head, let me know!

Alex Loftus

MANAGED BY INCF