This is not really a bioinformatics question, but a simple perl text processing question. someone might help you if you provide a little more information on the formats, the conversion is in fact very easy using perl and awk. What is the software requiring and yielding such formats? Also, it is impossible to see exactly what the formatting is from your example, because of the invisible delimiters in the output (tab,space, how many). If you provide this information, the question might be of some value for others searching for the same format conversion, otherwise it is not relevant and should be closed.
It is not entirely clear to me what you want to do with the file you have. But assuming you want to reshape the data in the file you specified on top and you want to reshape it in the way you specified than use R:
d <- read.table("yourFile.txt",sep="\t",header=T)
library(reshape) # if you don't have installed it use install.packages("reshape") first
use strict;
use warnings;
my @header = split ' ', <>;
while (<>) {
my @line = /(\S+)/g;
print "$line[0]\n";
print "$header[$_]\t$line[$_]\n" for 1 .. @line - 1;
}
Usage: perl script.pl inFile [>outFile]
The last, optional parameter directs the output to a file.
The header line is first split into @header. Then the subsequent file's lines are processed into array @lines, where $lines[0] contains the sequence that's printed as a header under which elements $header[1 .. n] are correspondingly printed with elements $line[1 .. n].
This can be done using a perl 'Hash of Hash' and for a tab delimited data file
use strict;
use warnings;
my %hoh=();
my $datafile="data.txt";
open FH,$datafile||die($!);
while(<FH>){
chomp $_;
my @fields=split(/\t/,$_);
$hoh{$fields[0]}{wsb1}=$fields[1];
$hoh{$fields[0]}{wsb2}=$fields[2];
$hoh{$fields[0]}{sm1}=$fields[3];
$hoh{$fields[0]}{sm2}=$fields[4];
$hoh{$fields[0]}{ph1}=$fields[5];
$hoh{$fields[0]}{ph2}=$fields[6];
$hoh{$fields[0]}{my1}=$fields[7];
$hoh{$fields[0]}{my2}=$fields[8];
}
close FH||die($!);
my @g_array=qw/wsb1 wsb2 sm1 sm2 ph1 ph2 my1 my2/;
for my $rna ( sort keys %hoh ) {
print $rna,"\n";
map{print $_,"\t",$hoh{$rna}{$_},"\n";}@g_array;
}
This is not really a bioinformatics question, but a simple perl text processing question. someone might help you if you provide a little more information on the formats, the conversion is in fact very easy using perl and awk. What is the software requiring and yielding such formats? Also, it is impossible to see exactly what the formatting is from your example, because of the invisible delimiters in the output (tab,space, how many). If you provide this information, the question might be of some value for others searching for the same format conversion, otherwise it is not relevant and should be closed.
yes , the format is not clear,I have edit it ,and I have get the answer by myself,use awk,it's very easy.thank you all the same,and how to close it ?
Perhaps you would like to post your solution, so others may learn from it?
I found your formatting and implicit specs clear and understandable. I see no good reason to close your question.