Code:
$
$ cat -n set_header.pl
1 #!/usr/bin/perl
2 use strict;
3
4 # Accept the input and output files as parameters
5 my $input_file = $ARGV[0];
6 my $output_file = $ARGV[1];
7
8 # Set the header columns to be added to the left
9 # and to the right of the header in the input file
10 my @left = (
11 "Index",
12 "Chromosome Position",
13 "Gene",
14 "Inheritance",
15 "RNA Accession",
16 "Chr",
17 "Coverage",
18 "Score",
19 "A(#F,#R)",
20 "C(#F,#R)",
21 "G(#F,#R)",
22 "T(#F,#R)",
23 "Ins(#F,#R)",
24 "Del(#F,#R)",
25 "SNP db_xref",
26 "Mutation Call",
27 "Mutant Allele Frequency",
28 "Amino Acid Change"
29 );
30 my @right = (
31 "HP",
32 "SPLICE",
33 "Pseudogene",
34 "Classification",
35 "HGMD",
36 "Disease",
37 "Sanger",
38 "References"
39 );
40
41 # Now open the input file, read the header line and sandwich it
42 # between @left and @right arrays
43 my $final_header;
44 open (FH, "<", $input_file) or die "Can't open $input_file: $!";
45 while (<FH>) {
46 chomp;
47 if ($. == 1) {
48 $final_header = sprintf("%s\t%s\t%s\n", join("\t", @left), $_, join("\t",@right));
49 last;
50 }
51 }
52 close (FH) or die "Can't close $input_file: $!";
53
54 # Once the final header is set, print it to the output file
55 open (FH, ">", $output_file) or die "Can't open $output_file: $!";
56 print FH $final_header;
57 close (FH) or die "Can't close $output_file: $!";
58
$
$ perl set_header.pl del.txt.hg19_multianno.txt my_output.txt
$
$ sed 's/\t/\n/g' my_output.txt
Index
Chromosome Position
Gene
Inheritance
RNA Accession
Chr
Coverage
Score
A(#F,#R)
C(#F,#R)
G(#F,#R)
T(#F,#R)
Ins(#F,#R)
Del(#F,#R)
SNP db_xref
Mutation Call
Mutant Allele Frequency
Amino Acid Change
Chr
Start
End
Ref
Alt
Func.refGene
Gene.refGene
GeneDetail.refGene
ExonicFunc.refGene
AAChange.refGene
PopFreqMax
1000G2012APR_ALL
1000G2012APR_AFR
1000G2012APR_AMR
1000G2012APR_ASN
1000G2012APR_EUR
ESP6500si_ALL
ESP6500si_AA
ESP6500si_EA
CG46
common
clinvar
clinvarsubmit
clinvarreference
Otherinfo
HP
SPLICE
Pseudogene
Classification
HGMD
Disease
Sanger
References
$
$