Sponsored Content
Full Discussion: Add static text in perl
Top Forums Shell Programming and Scripting Add static text in perl Post 302965995 by Aia on Friday 5th of February 2016 08:59:30 PM
Old 02-05-2016
Quote:
Originally Posted by cmccabe
I can not seem to figure out why VUS doesn't populate in $out[45] as that is the only part that doesn't seem to work.
Earlier, in post #6, I mentioned the following:
Quote:
Originally Posted by Aia
$out[45] = "VUS"; pretty much assigns it and there is not way you have "NULL" after that unless it gets changed or your understanding of what you are looking at is not correct.
I still believe that what you expect to see is misleading you of what it really is.

Code:
$out[45] = "VUS";

At this point, "VUS" is still, the 46th element of array out.

Code:
print OF join("\t",@out),"\n";

At that point, array out has been flatten out as an string separated with tabs.
You have lost your ability to know what element it would be in a string that now contains new tab separated elements.
In fact, since $out[45] is the last part, it would, actually, become $out[64] if you were to split again by tab.
You have introduced new parts that have tabs as well.


You want to test it?
Here's your original code, with some prints to show some details. Run it with just the two lines of input you posted.
Code:
#!/bin/perl

use strict;

my %nms=("NM_004004.5"=>"AR","NM_004992.3"=>"XLD","NM_003924.3"=>"AD");
my $input_file = $ARGV[0];
my $output_file = $ARGV[1];

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"
);

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));

open (OF, ">", $output_file) or die "Can't open $output_file: $!";
print OF "$final_header";

my @colsleft = map "Null",(1..$#left);
print "\@colsleft = ", scalar @colsleft, ": @colsleft\n";

my @colsright = map "Null",(0..$#right);
print "\@colsright = ", scalar @colsright, ": @colsright\n";

while(<FH>)  {
chomp;
my @vals = split/\t/;
my @mutations=split/,/,$vals[9];
my ($gene,$transcript,$exon,$coding,$aa);
for (@mutations)
{
    $_ or next;
    ($gene,$transcript,$exon,$coding,$aa) = split/\:/; # this takes col AB and splits it at colons

    grep {$transcript eq $_} keys %nms or next;
}
my @out=($.,@colsleft,$_,@colsright);
print "\n";
print 'After this evaluation: my @out=($.,@colsleft,$_,@colsright);', "\n";
print "\@out = ", scalar @out, ": @out\n\n";

$out[2]=$gene;
$out[3]=$nms{$transcript};
$out[4]=$transcript;
$out[15]=$coding;
$out[17]=$aa;
$out[45] = "VUS";

print 'After this evaluation:  $out[45] = "VUS";', "\n";
print "\@out = ", scalar @out, ": @out\n\n";

print OF join("\t",@out),"\n";

my @after = split( "\t", join("\t", @out) );
print "\@after = ", scalar @after, ": @after\n";
}

Run as:
Code:
perl debug.pl input.file /dev/null


Output:

Code:
@colsleft = 17: Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null
@colsright = 8: Null Null Null Null Null Null Null Null

After this evaluation: my @out=($.,@colsleft,$_,@colsright);
@out = 27: 2 Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null 4     41748130        41748130        G       C       exonic  PHOX2B      synonymous SNV   PHOX2B:NM_003924.3:exon3:c.C639G:p.G213G        0.0007  .       .       .       .       .       0.0005  0.0002  0.0007  . Null Null Null Null Null Null Null Null

After this evaluation:  $out[45] = "VUS";
@out = 46: 2 Null PHOX2B AD NM_003924.3 Null Null Null Null Null Null Null Null Null Null c.C639G Null p.G213G 4        41748130        41748130        G       C       exonic       PHOX2B          synonymous SNV  PHOX2B:NM_003924.3:exon3:c.C639G:p.G213G        0.0007  .       .       .       .       .       0.0005  0.0002  0.0007  . Null Null Null Null Null Null Null Null                   VUS

@after = 65: 2 Null PHOX2B AD NM_003924.3 Null Null Null Null Null Null Null Null Null Null c.C639G Null p.G213G 4 41748130 41748130 G C exonic PHOX2B  synonymous SNV PHOX2B:NM_003924.3:exon3:c.C639G:p.G213G 0.0007 . . . . . 0.0005 0.0002 0.0007 . Null Null Null Null Null Null Null Null                   VUS

Please, scroll all the way to the right to see VUS highlighted.

Again, knowing what the code does... it is not a problem; knowing what you expect is the hard part.
If you were to post an example of how those 2 lines are supposed to look after the process, that might help.

Last edited by Aia; 02-05-2016 at 10:17 PM.. Reason: Run only with the first two lines of input
 

10 More Discussions You Might Find Interesting

1. Solaris

Add Static Routes to new physical address

Hi, I need help to add new route: 10.252.0.138, GW 10.252.0.129 to e1000g1 and 10.252.0.10, GW 10.252.0.1 to e1000g2 tnx (4 Replies)
Discussion started by: mehrdad68
4 Replies

2. Red Hat

permanently add static route

I have a machine with an interface that has two different addresses on CentOS 5 eth0: 10.20.21.77 eth0:1 141.218.1.221 If I issue this command I get the result I'm looking for. /sbin/route add -net 141.218.1.0 netmask 255.255.255.0 gw 10.20.21.77 ip route show dev eth0 141.218.1.0/24... (1 Reply)
Discussion started by: beaker457
1 Replies

3. Shell Programming and Scripting

How to add static lines to short file?

I've got a simple log file that looks something like this: And I need to append it to look like this: So I just want to add a timestamp and a static (non-variable) word to each line in the file. Is there an easy scripted way to cat the file and append that data to each line....?? (4 Replies)
Discussion started by: kevinmccallum
4 Replies

4. IP Networking

I need HELP to Set up Coyote Linux router with 1 static IP & 64 internal static IP

hello, i need help on setting my coyote linux, i've working on this for last 5 days, can't get it to work. I've been posting this message to coyote forum, and other linux forum, but haven't get any answer yet. Hope someone here can help me...... please see my attached picture first. ... (0 Replies)
Discussion started by: dlwoaud
0 Replies

5. Shell Programming and Scripting

Removing text between two static strings

Hi everyone, I need to replace the text between two strings (html tags) and I'm having trouble figuring out how to do so. I can display the text with sed but I'm not having any luck deleting the text between the two strings. My file looks like this: <oths>test</oths><div class="text">1928... (2 Replies)
Discussion started by: cg2
2 Replies

6. UNIX for Advanced & Expert Users

Static code analysis for Perl

As an addition to our ongoing investigation into static code analysis tools for a Perl programming we are maintaining, can anyone recommend a certain tool that he/she is experienced with? We are already actively using perl::critic (Perl::Critic) and rats... (2 Replies)
Discussion started by: figaro
2 Replies

7. Programming

Even the Static cURL Library Isn't Static

I'm writing a program which uses curl to be run on Linux PCs which will be used by a number of different users. I cannot make the users all install curl on their individual machines, so I have tried to link curl in statically, rather than using libcurl.so. I downloaded the source and created a... (8 Replies)
Discussion started by: BrandonShw
8 Replies

8. Programming

Perl find text and add line

Hi All I need to add a line to a file but after a certain block of text is found The block of text looks like this <RDF:Description RDF:about="urn:mimetype:video/quicktime" NC:value="video/quicktime" and i need to add this in the next line down ( note there is... (4 Replies)
Discussion started by: ab52
4 Replies

9. Shell Programming and Scripting

awk to skip lines find text and add text based on number

I am trying to use awk skip each line with a ## or # and check each line after for STB= and if that value in greater than or = to 0.8, then at the end of line the text "STRAND BIAS" is written in else "GOOD". So in the file of 4 entries attached. awk tried: awk NR > "##"' "#" -F"STB="... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. Shell Programming and Scripting

How to add line breaks to perl command with large text in single quotes?

Below code extracts multiple field values from XML into array and prints all in one line. perl -nle '@r=/(?: jndiName| authDataAlias| value| minConnections| maxConnections| connectionTimeout| name)="(+)/g and print join ",",$ENV{tIPnSCOPE},$ENV{pr ovider},$ENV{impClassName},@r' server.xml ... (4 Replies)
Discussion started by: kchinnam
4 Replies
All times are GMT -4. The time now is 08:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy