python - Swapping column positions in a file -
i have file looks this:
#name cdsstart cdsend exoncount exonstarts exonends nm_017436 431 586 3 420,440,513, 435,500,596, nm_001173466 720 950 4 700,752,821,823, 721,760,900,973,
i want swap numbers in column 2 , column 3 first number in column 5 , last number in column 6, respectively. desired output:
nm_017436 431 586 3 *431*,440,513, 435,500,*586*, nm_001173466 720 950 4 *720*,752,821,823, 721,760,900,*950*,
i asterisked changes in output file clarity. think of doing splitting file script:
with open('nonsensepositions.txt') inf: open('nonsensepositions_split.txt', 'w') outf: line in inf: outf.write('\t'.join(line.split(',')))
and try swap particular columns, think might prove challenging due differing amounts of columns after split. have figure out way make appear original file after carry out swapping. there easier way carry out type of swap or need split file based on ,
, proposed?
$ awk '{ sub(/^[0-9]+/,$2,$5); sub(/[0-9]+,$/,$3",",$6) } 1' file #name cdsstart cdsend exoncount exonstarts exonends nm_017436 431 586 3 431,440,513, 435,500,586, nm_001173466 720 950 4 720,752,821,823, 721,760,900,950,
Comments
Post a Comment