0

The following file is tab-separated. I tried to remove from the first column NbLab330C00 64506568 the number after space in order to get NbLab330C00.

$ head LAB330_TE_annotation.gff3 
##gff-version 3      
##date Sun Feb 14 08:41:36 UTC 2021      
##Identity: Sequence identity (0-1) between the library sequence and the target region.      
##ltr_identity: Sequence identity (0-1) between the left and right LTR regions.      
##tsd: target site duplication.      
##seqid source sequence_ontology start end score strand phase attributes      
NbLab330C00 64506568    EDTA    Gypsy_LTR_retrotransposon   2   3364    20798   -   .   ID=TE_homo_0;Name=TE_00007365_INT;Classification=LTR/Gypsy;Sequence_ontology=SO:0002265;Identity=0.868;Method=homology      
NbLab330C00 64506568    EDTA    Gypsy_LTR_retrotransposon   3367    4198    3385    -   .   ID=TE_homo_1;Name=TE_00008087_LTR;Classification=LTR/Gypsy;Sequence_ontology=SO:0002265;Identity=0.865;Method=homology      
NbLab330C00 64506568    EDTA    hAT_TIR_transposon  4424    4715    1278    +   .   ID=TE_homo_2;Name=TE_00003964;Classification=DNA/DTA;Sequence_ontology=SO:0002279;Identity=0.834;Method=homology      
NbLab330C00 64506568    EDTA    hAT_TIR_transposon  5236    5453    835 +   .   ID=TE_homo_3;Name=TE_00001425;Classification=DNA/DTA;Sequence_ontology=SO:0002279;Identity=0.828;Method=homology 

I tried the following awk command but it shorten also the last column.

$ awk -v OFS='\t' '{print $1,$3,$4,$5,$7,$8,$9}' LAB330_TE_annotation.gff3 > LAB330_TE_annotation.fix.gff3
(base) ubuntu@ip-10-23-2-113:/efs/apollo/LAB330$ head LAB330_TE_annotation.fix.gff3 
##gff-version                       
##date  Feb 14  08:41:36    2021        
##Identity: identity    (0-1)   between library sequence    and
##ltr_identity: identity    (0-1)   between left    and right
##tsd:  site    duplication.                
##seqid sequence_ontology   start   end strand  phase   attributes
NbLab330C00 EDTA    Gypsy_LTR_retrotransposon   2   20798   -   .
NbLab330C00 EDTA    Gypsy_LTR_retrotransposon   3367    3385    -   .
NbLab330C00 EDTA    hAT_TIR_transposon  4424    1278    +   .
NbLab330C00 EDTA    hAT_TIR_transposon  5236    835 +   .
(base) ubuntu@ip-10-23-2-113:/efs/apollo/LAB330$ 

How to fix the above command,

Thank you in advance,

1
  • awk sees ten columns, you only print up to column 9. Add $10 and you will be fine. You may want to exclude comment lines; right now, their second column is also removed from the output. Commented Feb 18, 2021 at 3:12

2 Answers 2

1
awk 'BEGIN{ OFS=FS="\t" } 
  !/^#/{ sub(/ [0-9]+$/, "", $1) }
  1
' LAB330_TE_annotation.gff3 > LAB330_TE_annotation.fix.gff3

This leaves the header lines starting with # unmodified and replaces a space character followed by at least one digit at the end of the first field with an empty string.

1

You can use cut to remove the second column. The default delimiter is tab so you don't need to specify -d switch.

$ cut -f 1,3- LAB330_TE_annotation.gff3
##gff-version 3
##date Sun Feb 14 08:41:36 UTC 2021
##Identity: Sequence identity (0-1) between the library sequence and the target region.
##ltr_identity: Sequence identity (0-1) between the left and right LTR regions.
##tsd: target site duplication.
##seqid source sequence_ontology start end score strand phase attributes
NbLab330C00 EDTA    Gypsy_LTR_retrotransposon   2   3364    20798   -   .   ID=TE_homo_0;Name=TE_00007365_INT;Classification=LTR/Gypsy;Sequence_ontology=SO:0002265;Identity=0.868;Method=homology
NbLab330C00 EDTA    Gypsy_LTR_retrotransposon   3367    4198    3385    -   .   ID=TE_homo_1;Name=TE_00008087_LTR;Classification=LTR/Gypsy;Sequence_ontology=SO:0002265;Identity=0.865;Method=homology
NbLab330C00 EDTA    hAT_TIR_transposon  4424    4715    1278    +   .   ID=TE_homo_2;Name=TE_00003964;Classification=DNA/DTA;Sequence_ontology=SO:0002279;Identity=0.834;Method=homology
NbLab330C00 EDTA    hAT_TIR_transposon  5236    5453    835 +   .   ID=TE_homo_3;Name=TE_00001425;Classification=DNA/DTA;Sequence_ontology=SO:0002279;Identity=0.828;Method=homology

Alternative: $ cut -f 2 --complement LAB330_TE_annotation.gff3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .