Bash function to suppress warning message for specific text and display prompt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash function to suppress warning message for specific text and display prompt
# 1  
Old 03-07-2017
Bash function to suppress warning message for specific text and display prompt

In the below bash function multiple variants are input and stored in a variable $variant, and each is written to an out file at c:/Users/cmccabe/Desktop/Python27/out.txt stored on a separate line.

Code:
# enter variant
phox2b() {
    printf "\n\n"
    printf "What is the id of the patient getting Phox2B analysis  : "; read id
    printf "Please enter the coding variant the following is an example"
    echo " c.274G>T or c.274-10G>T"
    
    printf "variant(s), use a comma between multiple: "; IFS="," read -a variant
        
        [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
        [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return

        for ((i=0; i<${#variant[@]}; i++))
              do printf "NM_003924.3:%s\n" ${variant[$i]} >> c:/Users/cmccabe/Desktop/Python27/out.txt
        done
    add2text ${id}.txt
    additional

contents of out.txt
Code:
NM_003924.3:c.242-1G>A
NM_003924.3:c.*18_*19delGCinsAA
NM_003924.3:c.013G>T
NM_003924.3:c.013C>T

Each individual variant then goes through functions nomenclature, check, and convert.
The bash below runs as is, but I need to modify it to account for if a line in variant has a +/- in it (like line 1 does, NM_003924.3:c.242-1G>A).
The +/- always occurs in the same location (that is right before the last number in the c. and first letter before the > in the line but can vary in the amount of digits.

Code:
# run python NameChecker
nomenclature() {
    printf "\n\n"
    cd 'C:'
    C:/Users/cmccabe/Desktop/Python27/python.exe C:/Users/cmccabe/Desktop/Python27/run_batch_job.py C:/Users/cmccabe/Desktop/Python27/out.txt C:/Users/cmccabe/Desktop/Python27/out_name.txt NameChecker
      check
}

# verify
check() {
    printf "\n\n"
    awk 'NR>1 { if ($2 ~ /^\(/ ) {$1=""; print "Found error: ", $0} else { sub(/.*:/, "", $1); sub(/.*:/, "", $7); print "No error: " $1 "," $7}}' C:/Users/cmccabe/Desktop/Python27/out_name.txt
    printf "Is the variant correct?  Y/N "; read match_choice
    
    case "$match_choice" in
        [yY]) id="${id}"; convert ;; 
        [nN]) cd 'C:' C:/Users/cmccabe/Desktop/Python27/; awk '/variantchecker/ {r[$1]} FNR==NR {next} !($1 in r)' c:/Users/cmccabe/Desktop/Python27/out_name.txt c:/Users/cmccabe/Desktop/Python27/out.txt > c:/Users/cmccabe/Desktop/Python27/out.txt; rm c:/Users/cmccabe/Desktop/Python27/out_name.txt; menu ;;
    esac
}

# run python PositionConverter
convert() {                 
    printf "\n\n"
    cd 'C:'
    C:/Users/cmccabe/Desktop/Python27/python.exe C:/Users/cmccabe/Desktop/Python27/run_batch_job.py C:/Users/cmccabe/Desktop/Python27/out.txt C:/Users/cmccabe/Desktop/annovar/out_position.txt PositionConverter
    parse
}

After the nomenclature function runs a out_name.txt is created at C:/Users/cmccabe/Desktop/Python27/out_name.txt and looks like the below:

Code:
Input    Errors and warnings    AccNo    Genesymbol    Variant    Reference Sequence Start Descr.    Coding DNA Descr.    Protein Descr.    GeneSymbol Coding DNA Descr.    GeneSymbol Protein Descr.    Genomic Reference    Coding Reference    Protein Reference    Affected Transcripts    Affected Proteins    Restriction Sites Created    Restriction Sites Deleted
NM_003924.3:c.242-1G>A    (variantchecker): Intronic position given for a non-genomic reference sequence.    
NM_003924.3:c.*18_*19delGCinsAA        NM_003924.3    PHOX2B_v001    c.*18_*19delGCinsAA    n.1323_1324delinsAA    c.*18_*19delinsAA    p.(=)    PHOX2B_v001:c.*18_*19delinsAA    PHOX2B_v001:p.(=)        NM_003924.3    NP_003915.2    NM_003924.3(PHOX2B_v001):c.*18_*19delinsAA    NM_003924.3(PHOX2B_i001):p.(=)    HpyAV        
NM_003924.3:c.013G>T        NM_003924.3    PHOX2B_v001    c.013G>T    n.373G>T    c.13G>T    p.(Glu5*)    PHOX2B_v001:c.13G>T    PHOX2B_v001:p.(Glu5*)        NM_003924.3    NP_003915.2    NM_003924.3(PHOX2B_v001):c.13G>T    NM_003924.3(PHOX2B_i001):p.(Glu5*)            
NM_003924.3:c.013C>T    (variantchecker): C not found at position 373, found G instead.

I am trying to add a condition that will suppress the warning message $2 for the line in bold.
In addition, that line "is an intronic variant" is displayed. My attempt to incorporate these changes is below in bold, I hope it is a start. I apologize for the long post, just trying to include enough detail. Thank you Smilie.

Code:
# enter variant
phox2b() {
    printf "\n\n"
    printf "What is the id of the patient getting Phox2B analysis  : "; read id
    printf "Please enter the coding variant the following is an example"
    echo " c.274G>T or c.274-10G>T"
    
    printf "variant(s), use a comma between multiple: "; IFS="," read -a variant
        
        [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
        [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return

        for ((i=0; i<${#variant[@]}; i++))
              do printf "NM_003924.3:%s\n" ${variant[$i]} >> c:/Users/cmccabe/Desktop/Python27/out.txt
        done
    add2text ${id}.txt
    additional

# run python NameChecker
nomenclature() {
    printf "\n\n"
    cd 'C:'
    C:/Users/cmccabe/Desktop/Python27/python.exe C:/Users/cmccabe/Desktop/Python27/run_batch_job.py C:/Users/cmccabe/Desktop/Python27/out.txt C:/Users/cmccabe/Desktop/Python27/out_name.txt NameChecker
       # read each variant that matches patterern into LINE
       while read LINE; do
           grep -oP '[ "$variant" == "${variant#*[+-]}" ]\K.*'
       done < c:/Users/cmccabe/Desktop/Python27/out.txt

       # supress warning message and display message
       grep -q '(variantchecker): Intronic position given for a non-genomic reference sequence.' 'C:/Users/cmccabe/Desktop/Python27/out_name.txt' || echo "$LINE is an intronic variant";
   check
}

# verify
check() {
    printf "\n\n"
    awk 'NR>1 { if ($2 ~ /^\(/ ) {$1=""; print "Found error: ", $0} else { sub(/.*:/, "", $1); sub(/.*:/, "", $7); print "No error: " $1 "," $7}}' C:/Users/cmccabe/Desktop/Python27/out_name.txt
    printf "Is the variant correct?  Y/N "; read match_choice
    
    case "$match_choice" in
        [yY]) id="${id}"; convert ;; 
        [nN]) cd 'C:' C:/Users/cmccabe/Desktop/Python27/; awk '/variantchecker/ {r[$1]} FNR==NR {next} !($1 in r)' c:/Users/cmccabe/Desktop/Python27/out_name.txt c:/Users/cmccabe/Desktop/Python27/out.txt > c:/Users/cmccabe/Desktop/Python27/out.txt; rm c:/Users/cmccabe/Desktop/Python27/out_name.txt; menu ;;
    esac
}

# run python PositionConverter
convert() {                 
    printf "\n\n"
    cd 'C:'
    C:/Users/cmccabe/Desktop/Python27/python.exe C:/Users/cmccabe/Desktop/Python27/run_batch_job.py C:/Users/cmccabe/Desktop/Python27/out.txt C:/Users/cmccabe/Desktop/annovar/out_position.txt PositionConverter
    parse
}

moderator please close as i am going to repost a cleaner thread. Thank you.

Last edited by cmccabe; 03-09-2017 at 12:53 PM.. Reason: added moderator comment
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remote Desktop Session Prints Warning Message Everytime I Hit One Specific Key

Hello All, My question has to do with a Remote Desktop Session going from my Linux HOST to a Windows GUEST. Linux OS: OpenSuSE 11.4 i586 Windows OS: Windows Server 2003 For some reason after I have run rdekstop to connect to the Windows Guest, whenever I click on the Shift key I get the... (0 Replies)
Discussion started by: mrm5102
0 Replies

2. Shell Programming and Scripting

Suppress Error Message

How can I suppress a error message being given by awk command in bash shell? (2 Replies)
Discussion started by: Prachi Gupta
2 Replies

3. Shell Programming and Scripting

Bash function accepting list of strings and error message

I have a variable strLst containing a list of strings. I want to create a function that takes the list and an error message. If the number of strings is 0 or greater than 1, I print the error message. (1 Reply)
Discussion started by: kristinu
1 Replies

4. UNIX for Dummies Questions & Answers

pine email tool suppress prompt to save read messages

Could somebody please advise about how to configure pine/alpine so that on exit it doesn't prompt me to save read messages? Thanks (3 Replies)
Discussion started by: LeoKSimon
3 Replies

5. Shell Programming and Scripting

Suppress a background message in Bash

I'm having trouble with part of this bash script in Linux where I respawn a new instance of script and kill the old one to prevent forking (Yes, I know 'exec' will not fork but this needs to be interactive) When the old instance is kill it pops up "Terminated!" in the middle of the new instance... (7 Replies)
Discussion started by: Azrael
7 Replies

6. Shell Programming and Scripting

How do display a warning message?

Hello, I am teaching myself shell scripting and I was wondering if there was a way to rename a file and display a warning or prompt message? And if you had a file like /home/me/blah/ for example, what are the ways to use the CD to get to /me? Would it be ../home/me? Are there other ways to... (4 Replies)
Discussion started by: kris2010
4 Replies

7. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

8. Shell Programming and Scripting

Print a message at specific line on prompt

Hi Friends, I am using HP-UNIX(ksh). I want to print a message at specific line on the prompt screen. For Example: for num in 1 10 3 145 do echo $num // need to print this on the same line for each number sleep 2 done Actual Output: ========== 1 10 3 145 Expected Output:... (5 Replies)
Discussion started by: Niroj
5 Replies

9. Shell Programming and Scripting

Suppress error message in unzip

I'm creating a bsh shell to unzip a file from one directory into another. The directory that holds the zip files has zip files constantly being added to it, so I am testing it before it does the unzip and more. Right now my code looks like this: unzip -tq $ZIP_PATH/$ZIP_NAME >/dev/null if ... (5 Replies)
Discussion started by: skwyer
5 Replies

10. Shell Programming and Scripting

suppress bash's "Done" message

Hi, I'm running a background job in my bash script. But when the job quit, bash echos a message like "+ Done xterm". This is annoying. How can I suppress it? (5 Replies)
Discussion started by: momiji
5 Replies
Login or Register to Ask a Question