Save the output from perlblastparser into a file, which I will call test_data in the following.
The contents of test_data should look somewhat like this (note the empty line at the end of the file):
SW:X2:
>SW:X2 A0KFJ6 Homoserine O-succinyltransferase GN=a PE=3 SV=1
Length = 317
e-118 201 0 299 Plus 1 299 1 299
SW:X3:
>SW:X3 A0KFJ6 Homoserine O-succinyltransferase GN=b PE=3 SV=1
Length = 317
e-118 201 0 299 Plus
SW:X1:
>SW:X1 A0KFJ6 Homoserine O-succinyltransferase GN=c PE=3 SV=1
Length = 317
e-118 201 0 299 Plus 1 299 1 299
Then create a Ruby script sortBy.rb like this:
lines = IO.readlines("test_data")
sortBy='GN='
entries = {}
n = 0
while n + 4 < lines.size do
key = lines[n + 1].match(sortBy + '[^ ]+')[0].sub(sortBy, '')
entries[key] = lines[n] + lines[n + 1] + lines[n + 2] + lines[n + 3] + lines[n + 4]
n += 5
end
entries.keys.sort.each { |key|
puts entries[key]
}
You can then sort your output by running: ruby sortBy.rb. Simply change the variable sortBy if you want to sort on something else than the GN field.
Do you have the gene name in the fasta headers or a mapping between the identifiers in fasta to gene name ?
No I don't have the gene nemae in the fasta headers. I don't think anyway.
I use the blastall -p blastx command to run reads against a protein-sequence-database I made with formatdb. So the BLAST output file I get gives me all the hits for each protein which lists the protein name in the header along with gene name as, for example, GN=mecA.
So the perl script I am incapable of writing myself, within this year anyway, sorts the hits like this
tr|H6LSH4|H6LSH4_STAAU:
but it would be better to have them sorted according to GN=mecA or similar.
I just wondered if anyone knew if there was a script that did that.
:)
You should write a test case. Write an example of input file, and an example of the output that you want to get, and then post it here.
I agree with Giovanni's comment, because then it is easy to figure out what you need