Hello, I am trying to convert CuffDiff-derived tabular files, to at tab delimited format. Does anybody know of a LINUX-based tool that does this? Other than the one included in Galaxy? Thanks Genaro
2 answers
Output files from CuffDiff are already in tab-delimited format (I just checked to confirm my memory). However, if they weren't and you wanted a LINUX-based tool to switch delimiters, you might reach for sed. For example, if the delimiter was a space, and you wanted it to be tab, the following one-liner would work:
sed -e 's/ /\t/g' inputfile > yournewfile
This tells sed to substitute space for tab globally from your input file, and puts the result into a new file. Tab is specified by '\t', but on some operating systems you have to specify it literally using control-v and then hitting the TAB key.
Since you mention Galaxy, perhaps you're simply looking to extract and re-arrange certain columns from your CuffDiff files, and put the result into tab delimited format. There are a variety of options for extracting columns from files in linux, and placing the results, delimited as you wish, into a new file. For instance if you wanted columns 2 and 4 into a new tab-delimited file you could use 'cut':
cut -f2,4 gene_exp.diff > yournewfile
Or you could use perl to grab the columns of interest:
perl -nale 'print "$F[1]\t$F[3]";' gene_exp.diff > yournewfile
Calling perl with -n creates a while loop to process the lines of your file, -a turns on auto-split which is tab by default and the results are placed into an array called @F. Since numbering perl array elements starts at 0, elements 1 and 3 correspond to file fields 2 and 4. The -l switch takes care of line endings for the print statment, and -e means evaluate the following line of code.
Or you could use awk:
awk 'BEGIN{OFS="\t";}{print $2,$4}' gene_exp.diff > yournewfile
Awk will auto-split your file on white space (which includes tabs) such that your column values are available as numbered variables (starting at 1). You can then specify which columns you'd like to print out. The BEGIN block gets executed before the lines of the file are processed, and there we set the Output Field Separator to tab, so the resulting values are tab-delimited when printed out. This is an easy way to manipulate columns of data in text files.
Since CuffDiff files are already tab-delimited, I'm not sure what you're really trying to do, but since you asked about LINUX based tools for performing a systematic file manipulation, you might find these handy. These kinds of manipulations can be very powerful when doing all kinds of bioinformatics analysis. Sometimes people reach for Galaxy because they simply don't know about things like sed or cut.
Thanks all for your help!
Log in to answer this question.
As I recall, they are already in tab-delimited format. I read them into R using tab as the delimiter. Are you sure your question is clear? What do you think is the delimiter, if not tab?
Can you provide examples of the source an target format, please, in case the output of CuffDiff is not sufficient already. Please use source code formatting and put only a few lines into your example.