GraphAligner icon indicating copy to clipboard operation
GraphAligner copied to clipboard

Convert alignments to GFA Path lines

Open Adamtaranto opened this issue 1 year ago • 2 comments

Hi Mikko,

Do you have a method to convert the graph alignment for a single read into a GFA Path line? I want to visualise individual read alignments in Bandage.

Adamtaranto avatar Jan 23 '24 01:01 Adamtaranto

Hi, I think this should work if you have just one alignment per read:

cut -f 1,6 < alignments.gaf | awk '{print "P\t" $1 "\t" $2 "\t" "*";}' | sed 's/>\([^<>\t ]\+\)/>\1+,/g' | sed 's/<\([^<>\t ]\+\)/<\1-,/g' | tr -d '<>' | sed 's/,\t/\t/g' > alignment-paths.gfa

Or this if you have multiple alignments per read, this will append the location of the aligned part into the read name:

cut -f 1,3,4,6 < alignments.gaf | awk '{print "P\t" $1 "_" $2 "_" $3 "\t" $4 "\t" "*";}' | sed 's/>\([^<>\t ]\+\)/>\1+,/g' | sed 's/<\([^<>\t ]\+\)/<\1-,/g' | tr -d '<>' | sed 's/,\t/\t/g' > alignment-paths.gfa

maickrau avatar Jan 24 '24 08:01 maickrau

Thanks for that, not sure why but that command wasn't working on my GAF files.

I've written a a little tool to do the job gaf2path. It should work so long as the path field only ever has >/< followed by the contig name.

Adamtaranto avatar Jan 26 '24 13:01 Adamtaranto