Reading Header info from x1D

AFNI version info (20.2.16):

Hi AFNI team,

I want to know if there is any AFNI function to read the header information from a X1D file.

Specifically, I want to read the “ColumnLabels” in the attached x1D ( x1D ), so that I can find extract label names and their corresponding Betas and T statistic for trial wise data using Stim_Times_IM.

Regards,
Sahithyan

Hi, Sahithyan-

I think 1d_tool.py is what you want.

Note that as a naming convention, we normally use .1D as the file extension, but the program will still read something called .x1D.

You can extract columns using the header labels:

# extract two columns using labels
1d_tool.py \
    -infile PCR501_M_TR_MNI_3mm_SI_censor_CueCSPLINTaskMR.x1D'[Run#1Pol#0,Run#1Pol#1]' \
    -write testA.1D 

# extract a slice/interval of columns with '..'
1d_tool.py \
    -infile PCR501_M_TR_MNI_3mm_SI_censor_CueCSPLINTaskMR.x1D'[Run#1Pol#0..Run#1Pol#4]' \
    -write testB.1D

Sidenote: I think we need to update the second case in Ex. 1 of the help file to use .., not ,, for the slice interval specification, as I have used above.

--pt

Thanks. This exactly what I wanted.

Hi @ptaylor !

One additional question.

How do I extract the column label names along with the data. ( asking for this because the number of column labels change with participant, especially when I use stim_times_IM based on accuracy )

For example:

Run#1Pol#0         Run#1Pol#1
1                       0.5
1                       0.5

Regards,
Sahithyan

Hi, Sahithyan-

I have a Linux-y command line way of getting a list of column headers, but @rickr might have a more official one.

In this example, I'm using X.stim.xmat.1D from the AFNI Bootcamp example. To see what the text file row in question looks like, we can use grep to extract it:

$ \grep ColumnLabels X.stim.xmat.1D
#  ColumnLabels = "vis#0 ; aud#0"

Note that I put a \ before the grep command up above, to avoid having colors in the text string as we process.

So, now we see we want to make the list by: 1) taking everythign to the right of the =, then removing the " (which could mean replacing it with a null character), then splitting at ; to make a list (which means replacing ';' with a newline character). This is accomplished by successively piping like this:

$ \grep ColumnLabels X.stim.xmat.1D \
    | cut -d '=' -f 2 \
    | tr '"' ''  \
    | tr ';' '\n'

The result could be saved to a variable (here, in tcsh syntax) with:

set my_variable = `\grep ColumnLabels X.stim.xmat.1D \
                       | cut -d '=' -f 2 \
                       | tr '"' ''  \
                       | tr ';' '\n'`

--pt

Hi Sahithyan,

And a perhaps less interesting way to go would be to add "-write_with_header yes" :

# extract a slice/interval of columns with '..'
1d_tool.py \
    -infile PCR501_M_TR_MNI_3mm_SI_censor_CueCSPLINTaskMR.x1D'[Run#1Pol#0..Run#1Pol#4]' \
    -write_with_header yes \
    -write testB.1D

It is not done automatically because we often use use extracted 1D text files more directly, and might not want the header.

  • rick

Thanks !! @ptaylor @rickr