Sponsored Content
Top Forums Shell Programming and Scripting Perl to change value based on set of rules Post 303001659 by durden_tyler on Tuesday 8th of August 2017 07:38:58 PM
Old 08-08-2017
Quote:
Originally Posted by cmccabe
...
...
The code below is a rule that is supposed to be applicable to lines 2-4 because this rule just looks at the digit in f[8].
...
...
That's wrong!
The regex looks for "a non-digit followed by one or more digits" ("\D\d+").
Line numbers 2 and 3 do not have that, so it will not match.
Line number 4 has that, so it will match.


Quote:
Originally Posted by cmccabe
...
...
So in line 2 f[8] is 27
and that value is greater than 10, so f[55] would be Likely Benign.
...
...
That's wrong again.
Line # 2 will never match "\D\d+" so 27 will never be extracted and hence never compared to anything.

Quote:
Originally Posted by cmccabe
...
...
Since the symbol before the digit could be either a > or + or - in the regex I use
\D to look for any non-digit before the number.
...
...
Wrong again.
There are cases where a symbol does not exist in the first place.
For example, lines 2 and 3 do not have the symbol at all.
You did not do anything for those cases hence those lines fail to match your regex.
Line 5 does have the symbol, so it matches your regex.


Quote:
Originally Posted by cmccabe
...
...
The else portion of the rule is supposed to be applicable to lines 1 and 5 as it uses the regex to parse out the digit after the - ot + or *in the string
that begins with NM_ in [ICODE] in f[8].
...
...
Yes, but before the control goes to the "else" portion, it will go to the "if" portion.
And the "if" portion will match your lines 1 and 5 because both of them have "a non-digit followed by one or more digit" ("\D\d+") in their f[8] values.

So the "else" portion will not even get a chance to execute for lines 1 and 5.

Here's some diagnostic output for your data file:
Code:
$ 
$ cat -n process_files.pl
     1    #!perl
     2    
     3    $file = $ARGV[0];
     4    open(FH, '<', $file) or die "Can't open $file: $!";
     5    while (<FH>) {
     6        next if $. == 1;
     7        chomp;
     8        @x = split /\s+/;
     9        $FuncrefGene = $x[6];
    10        $GeneDetailrefGene = $x[8];
    11        printf("Row no. = [%d]\n", $.);
    12        printf("FuncrefGene = [%s]\n", $FuncrefGene);
    13        printf("GeneDetailrefGene = [%s]\n", $GeneDetailrefGene);
    14        if ($FuncrefGene !~ /exonic/i && $GeneDetailrefGene=~/(\D\d+)/) {
    15            printf("In IF branch:\n");
    16            printf("==> \$1 = [%s]\n", $1);
    17            if ($1 > 11) {
    18                printf("==> Inside \$1 > 11\n");
    19                $1 //= 0;
    20                $classification = 'Likely Benign';
    21            }
    22            printf("==> Last line in IF branch: classification = [%s]\n", $classification);
    23        } else {
    24            printf("In ELSE branch:\n");
    25            if ($FuncrefGene !~ /exonic/i) {
    26                my ($transcript) = ($GeneDetailrefGene) =~ /(?:\.\d+[+*-])(\d+)/;
    27                printf("==> transcript = [%s]\n", $transcript);
    28                $transcript //= 0;
    29                $classification = 'Likely Benign' if $transcript > 11;
    30            }
    31            printf("==> Last line in ELSE branch: classification = [%s]\n", $classification);
    32        }
    33        printf("%s\n\n", "="x60);
    34    }
    35    close(FH) or die "Can't close $file: $!";
    36    
$ 
$ perl process_files.pl data.txt
Row no. = [2]
FuncrefGene = [splicing]
GeneDetailrefGene = [NM_018328:exon12:c.3055-9T>C]
In IF branch:
==> $1 = [_018328]
==> Last line in IF branch: classification = []
============================================================

Row no. = [3]
FuncrefGene = [upstream]
GeneDetailrefGene = [27]
In ELSE branch:
==> transcript = []
==> Last line in ELSE branch: classification = []
============================================================

Row no. = [4]
FuncrefGene = [upstream]
GeneDetailrefGene = [35]
In ELSE branch:
==> transcript = []
==> Last line in ELSE branch: classification = []
============================================================

Row no. = [5]
FuncrefGene = [splicing]
GeneDetailrefGene = [>50]
In IF branch:
==> $1 = [>50]
==> Last line in IF branch: classification = []
============================================================

Row no. = [6]
FuncrefGene = [UTR3]
GeneDetailrefGene = [NM_003042:c.*234C>A]
In IF branch:
==> $1 = [_003042]
==> Last line in IF branch: classification = []
============================================================

$ 
$

This User Gave Thanks to durden_tyler For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to change "set" values in perl, windows...

i am using perl in win2000advanced server... --------------------------- perl -version: --------------------------- This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2001, Larry Wall Binary build 638 provided by... (1 Reply)
Discussion started by: sekar sundaram
1 Replies

2. Shell Programming and Scripting

Need to change a set of lines between two given Pattrens

Hi All I have a Small Requiement I wanted to replace all the Follwing lines as follows Input:: file1 EVALUATE WS-TEMP-ATTR(15:1) WHEN 'D' MOVE DFHDARK TO WS-ATTR-COLOR WHEN OTHER MOVE DFHDFT ... (9 Replies)
Discussion started by: pbsrinivas
9 Replies

3. UNIX for Dummies Questions & Answers

Server wide password enforcement rules? 90 day force change.

Using Solaris 9 and 10. What we want to do is set up global rules for our password files to restrict all users, not only new ones set up with the rules but also the ones that have been sitting on the system for years. Is there a global way to force all users to change their password every 90... (1 Reply)
Discussion started by: LordJezo
1 Replies

4. Solaris

help me to change the character set

dears i am using solaris 10 i am facing a problem when i make setup for solaris i choose the country egypt and i select the language north america but i forget to do that the i found the date Jun written in arabic i want to change character set to written in english -rw-r--r-- 1 root ... (4 Replies)
Discussion started by: hosney00ux
4 Replies

5. Shell Programming and Scripting

Matching string on two files based on match rules.

Hi, How to check if a string on file2 exactly matches with a part or complete string on file1, and return a match indicator based on some match rules. 1) only records on file1 with category A should be matched. for other category, the output match indicator should default to 'N' 2) on file2... (13 Replies)
Discussion started by: effay
13 Replies

6. Shell Programming and Scripting

Help with allocated text content based on specific rules...

Input file format: /tag="ABL" /note="abl homolog 2 /tag="ABLIM1" /note="actin binding LIM 1 /tag="ABP1" /note="amiloride binding protein 1 (amine oxidase (copper- containing)) /tag="ABR" /note="active BCR-related /tag="AC003042.1" /note="SDR family member 11 precursor . . . (4 Replies)
Discussion started by: perl_beginner
4 Replies

7. Shell Programming and Scripting

Generating a passwordlist based on rules

Hy there! Some time ago I encrypted the harddrive of my notebook. Now, I can't remember it correctly. I want to create a list with all possible combinations of the words I used (I still remember all the words....). The password was created like this: ... (1 Reply)
Discussion started by: santiago10k
1 Replies

8. Shell Programming and Scripting

Delete lines based on Rules

Hi My requirement is very simple . I juts need to delte some lines from a file. here comes theactual scenario I have some data in file like say srinivasa prabhu kumar antony srinivas king prabhu antony srinivas prabhu king yar venkata venkata kingson srinivas... (6 Replies)
Discussion started by: ptappeta
6 Replies

9. Shell Programming and Scripting

Filtering duplicates based on lookup table and rules

please help solving the following. I have access to redhat linux cluster having 32gigs of ram. I have duplicate ids for variable names, in the file 1,2 are duplicates;3,4 and 5 are duplicates;6 and 7 are duplicates. My objective is to use only the first occurrence of these duplicates. Lookup... (4 Replies)
Discussion started by: ritakadm
4 Replies

10. Shell Programming and Scripting

Perl to update field based on a specific set of rules

In the perl below, which does execute, I am having trouble with the else in Rule 3. The digit in f{8} is extracted and used to update f accordinly along with the value in f. There can be either - * or + before the number that is extracted but the same logic applies, that is if the value is greater... (5 Replies)
Discussion started by: cmccabe
5 Replies
All times are GMT -4. The time now is 03:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy