How to add header name to all annotation lines
2
0
Entering edit mode
5.1 years ago
Sam ▴ 20

Hi there,

how to append the header line (chromosome or scaffold) to the end of each annotation.


Input:

@Chr1

54584 54773 100 1.9 98

55019 55105 22 3.9 22


@Chr2

2226 2261 18 1.9 19

4211 4259 26 1.9 25

4426 4468 22 2 22


@utg7294

919 1455 36 15 36

919 1455 71 7.5 72

4872 4913 22 1.9 22


Expected output

54584 54773 100 1.9 98 @Chr1

55019 55105 22 3.9 22 @Chr1


2226 2261 18 1.9 19 @Chr2

4211 4259 26 1.9 25 @Chr2

4426 4468 22 2 22 @Chr2


919 1455 36 15 36 @utg7294

919 1455 71 7.5 72 @utg7294

4872 4913 22 1.9 22 @utg7294

It must be simple as search line has '@', if so append that header to end until it finds another '@'. But I couldn't find an exact script.

Thanks for your help. Sam

sequencing fasta • 764 views
ADD COMMENT
2
Entering edit mode
5.1 years ago
ATpoint 81k
DELIMITER="\t"
awk NF your.file | \
  while read p; do
  if [[ $p == @* ]]; then 
    APPEND=$p
    continue
      fi
  if [[ $p != @* ]]; then 
    echo -e ${p}${DELIMITER}${APPEND}
    fi
  done < /dev/stdin

Change DELIMITER in line 1 according to the delimiter present in your file. Here is is tab.


Also, for the future, please use the code option (101010) in the formatting bar to indicate code and example data.

ADD COMMENT
2
Entering edit mode
5.1 years ago
JC 13k

Perl:

#!/usr/bin/perl

use strict;
use warnings;

my $head = '';
while (<>) {
    chomp;
    if (/^(@.+)/) { $head = $1; }
    else { print "$_\t$head\n"; }
}

Run as perl addheader.pl < INPUT > OUPUT

ADD COMMENT

Login before adding your answer.

Traffic: 2057 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6