This is a test version of Biostars. For the public version, visit https://www.biostars.org.
meta file table

Hi,

How can I generate a meta file table from a list of text files?

I have a text file with multiple file names, like so:

ID1_GENDER_TREATMENT.fastq
ID2_GENDER_TREATMENT.fastq
.
.
.
IDn_GENDER_TREATMENT.fastq

I would like to generate a table that looks like this:

ID                  GENDER                  TREATMENT

ID1                  gender                        treatment

ID2                    gender                      treatment
.

. .

I am new in bioinformatics and I am not sure how to do this.

Thanks!

rna-seq

1 answer

Assume you had files like this:

$ ls *.fastq
ID1_GENDER1_TREATMENT1.fastq ID2_GENDER2_TREATMENT2.fastq ID3_GENDER3_TREATMENT3.fastq

Then do:

$ ls *.fastq | awk -F "_" 'OFS="\t" {if(NR==1)print "ID", "GENDER", "TREATMENT"} {gsub(".fastq","");print $1, $2, $3}'
ID  GENDER  TREATMENT
ID1 GENDER1 TREATMENT1
ID2 GENDER2 TREATMENT2
ID3 GENDER3 TREATMENT3

OFS="\t" will make it a tab-delimited list. Change that if you want alternative delimiters.

Log in to answer this question.