1

I have this input;

scaffold10x_1   AUGUSTUS    gene    72040   72306   0.67    -   .   g4
scaffold10x_1   AUGUSTUS    transcript  72040   72306   0.67    -   .   g4.t1
scaffold10x_1   AUGUSTUS    stop_codon  72040   72042   .   -   0   transcript_id "g4.t1"; gene_id "g4";
scaffold10x_1   AUGUSTUS    CDS 72040   72306   0.67    -   0   transcript_id "g4.t1"; gene_id "g4";
scaffold10x_1   AUGUSTUS    exon    72040   72306   .   -   .   transcript_id "g4.t1"; gene_id "g4";
scaffold10x_1   AUGUSTUS    start_codon 72304   72306   .   -   0   transcript_id "g4.t1"; gene_id "g4";
scaffold10x_1   AUGUSTUS    gene    72500   72970   0.99    -   .   g5
scaffold10x_1   AUGUSTUS    transcript  72500   72970   0.99    -   .   g5.t1
scaffold10x_1   AUGUSTUS    stop_codon  72500   72502   .   -   0   transcript_id "g5.t1"; gene_id "g5";
scaffold10x_1   AUGUSTUS    CDS 72500   72970   0.99    -   0   transcript_id "g5.t1"; gene_id "g5";
scaffold10x_1   AUGUSTUS    exon    72500   72970   .   -   .   transcript_id "g5.t1"; gene_id "g5";
scaffold10x_1   AUGUSTUS    start_codon 72968   72970   .   -   0   transcript_id "g5.t1"; gene_id "g5";

I would love to have this output;

scaffold10x_1   AUGUSTUS    gene    72040   72306   0.67    -   .   transcript_id "g4.t1"; gene_id "g4";
scaffold10x_1   AUGUSTUS    transcript  72040   72306   0.67    -   .   transcript_id "g4.t1"; gene_id "g4";
scaffold10x_1   AUGUSTUS    stop_codon  72040   72042   .   -   0   transcript_id "g4.t1"; gene_id "g4";
scaffold10x_1   AUGUSTUS    CDS 72040   72306   0.67    -   0   transcript_id "g4.t1"; gene_id "g4";
scaffold10x_1   AUGUSTUS    exon    72040   72306   .   -   .   transcript_id "g4.t1"; gene_id "g4";
scaffold10x_1   AUGUSTUS    start_codon 72304   72306   .   -   0   transcript_id "g4.t1"; gene_id "g4";
scaffold10x_1   AUGUSTUS    gene    72500   72970   0.99    -   .   transcript_id "g5.t1"; gene_id "g5";
scaffold10x_1   AUGUSTUS    transcript  72500   72970   0.99    -   .   transcript_id "g5.t1"; gene_id "g5";
scaffold10x_1   AUGUSTUS    stop_codon  72500   72502   .   -   0   transcript_id "g5.t1"; gene_id "g5";
scaffold10x_1   AUGUSTUS    CDS 72500   72970   0.99    -   0   transcript_id "g5.t1"; gene_id "g5";
scaffold10x_1   AUGUSTUS    exon    72500   72970   .   -   .   transcript_id "g5.t1"; gene_id "g5";
scaffold10x_1   AUGUSTUS    start_codon 72968   72970   .   -   0   transcript_id "g5.t1"; gene_id "g5";

how can I use sed command on linux to get the desired output? Thanks Kay

  • @Theophrastus Beware of the .t1trap! And why are you escaping the quotes inside the double quotes? – Philippos Jan 2 '18 at 13:03
  • so basically, the first file is the current output file have from Augustus software, but then I need to use the file as input for another software, and it seems my file does conform to what new software requires. – Kay NewEdge Daramola Jan 3 '18 at 8:43
1

It's usually a good idea to explain the replacement logic and some border conditions, so there is no need to guess. You didn't, so I have to make some assumptions:

  • You want to make replacements if the last column of the line is either g followed by any (maybe multi-digit) number and an optional .t1 (always 1)
  • No matter whether the line had a .t1 or not, the transcript_id should be sufficed .t1, the gene_id should not
  • The column delimiters are whitespaces

In this case, the following script should work. Otherwise, you need to adapt it:

sed -E 's/ (g[0-9]*)(\.t1)?$/ transscript_id "\1.t1"; gene_id "\1";/' yourfile

  • I am trying to change some contents in the last column. for every gene and transcript in a group for example, their current attribute is g4 and g4.t1 respectively. I want all the attributes in the group to have similar attribute, as transcript_id "g4.t1"; gene_id "g4"; – Kay NewEdge Daramola Jan 3 '18 at 8:58
  • thanks, Philippos, but it doesn't seem to work – Kay NewEdge Daramola Jan 3 '18 at 9:49
  • What do you mean by "doesn't seem to work"? I tested it to produce the output you desired, so under which condition does it fail? What does your mechanic answer if you say nothing but "my car doesn't work"? – Philippos Jan 3 '18 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.