Update perl code with parser


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Update perl code with parser
# 1  
Old 11-02-2015
Update perl code with parser

The below perl code imports the data in the attached document. However, I can not seem to update the perl code to include a parser like in the desired tab of that document. Thank you Smilie.


Most of the data for the parse is included in the document except for the gene and RNA which can is hard-coded based on the text in bold:

1. column AB (AAChange.refGene)has the Mutation (column p), and AminoAcid (column R) information in it
2. the clinvar column (AN) has the information for classification (column AT) in it (first letter needs to be capital)


Code:
        column                D                E
If GJB2 then RNA = NM_004004.5 and Inheritance = AR

If MECP2 then RNA = NM_004992.3 and Inheritance = XLD

If PHOX2B then RNA = NM_003924.3 and Inheritance = AD

perl:
Code:
#!/bin/perl
   use strict;
     
       # Accept the input and output files as parameters
       my $input_file = $ARGV[0];
       my $output_file = $ARGV[1];
     
       # Set the header columns to be added to the left
       # and to the right of the header in the input file
      my @left =  (
                       "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"
                  );
      my @right = (
                      "HP",
                      "SPLICE",
                      "Pseudogene",
                      "Classification",
                      "HGMD",
                      "Disease",
                      "Sanger",
                      "References"
                  );
    
      # open the input file, read the header line and sandwich it
      # between @left and @right arrays
      my $final_header;
      open (FH, "<", $input_file) or die "Can't open $input_file: $!";
	  chomp(my $hdr=<FH>);

      $final_header = sprintf("%s\t%s\t%s\n", join("\t", @left), $hdr, join("\t",@right));

      # final header is set, print it to the output file
      open (OF, ">", $output_file) or die "Can't open $output_file: $!";
      print OF "$final_header";
     # close (FH) or die "Can't close $output_file: $!";
	  
	   my @colsleft = map "Null",(1..$#left);	  
	   my @colsright = map "Null",(0..$#right);	 
	  	  
	  while(<FH>)  {  # puts row of input file into $_ 
	  chomp;
		print OF join("\t",$.,@colsleft,$_,@colsright),"\n";   # row data is set, print it to the output file		 
   	 }


Last edited by cmccabe; 11-03-2015 at 12:46 PM.. Reason: fixed format
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to run different parser based on digit

The perl parser below works as expected assuming the last digit in the NC_ before the . is a single digit. perl -ne 'next if $. == 1; if(/.*del(+)ins(+).*NC_0{4}(+).*g\.(+)_(+)/) # indel { print join("\t", $3, $4, $5, $1, $2), "\n"; } ' out_position.txt > out1.txt ... (8 Replies)
Discussion started by: cmccabe
8 Replies

2. Shell Programming and Scripting

Help required in Building an XML using SAX Parser in perl

I want to use sax parser for my application as i have 5 Lakhs of data. I have the xml file like this <Nodes> <Node> <NodeName>Company</NodeName> <File>employee_details.csv</File> <data>employee_data.txt</data> <Node> <NodeName>dummy</NodeName> ... (8 Replies)
Discussion started by: vanitham
8 Replies

3. Programming

Parser - multiple in Perl

Dear Perl Experts, Could some body help me to find the solution for my problem below: Input file: ----------- THE-0 tsjp THE-32 tsjp THE-64 tsjp Output desired: --------------- THE-0&&-31 tsjp THE-32&&-63 tsjp THE-64&&-95 tsjp Note: 31 = 0+31, (2 Replies)
Discussion started by: askari
2 Replies

4. Shell Programming and Scripting

Facing problem in XML::parser module in PERL

HI, I have XML file which is having values as Spanish character (UTF-8 encoding). I am using XML::parser module but my code is not able to read those characters. I did goggling but not able to find suitable solution. Anybody please help me out. XML file having characters like: ñ I am... (1 Reply)
Discussion started by: jatanig
1 Replies

5. Shell Programming and Scripting

perl config parser

Hello. Can anybody help me with some sub on perl that can parse config like this: %CFG ( 'databases' => { 'db1' => 'db_11', 'db_12', 'db_13', 'db2' => 'db_21', 'db_22', 'db_23' } 'datafiles' => { 'datadir1' => 'datadir_11', 'datadir_12', 'datadir2' =>... (4 Replies)
Discussion started by: drack
4 Replies

6. Shell Programming and Scripting

xml-parser with perl

Hello I want to write an xml- parser with perl an i use the libary XML::LibXML. I have a problem with the command getElementsByTagName. If there is an empty tag, the getElementsByTagName method returns a NodeList of length zero. how can i check if this is a nodelist of lenght zero?? i... (1 Reply)
Discussion started by: trek
1 Replies

7. Shell Programming and Scripting

Perl XML:Parser help

I am very new to XML. Really I have an excel file that I am trying to read w/ Perl on a Linux machine. I don't have a mod for reading excel files so I have to convert the excel file to xml to be able to read it. I can read the file and everything is ok except...the Number style is being dropped... (0 Replies)
Discussion started by: vincaStar
0 Replies

8. Shell Programming and Scripting

xml parser in perl

hi all i want to read xml file in perl i am using XML::Simple for this. i am not getting how to read following file removing xml file due to some reason (1 Reply)
Discussion started by: zedex
1 Replies
Login or Register to Ask a Question