Error removed from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error removed from file
# 1  
Old 03-20-2015
Error removed from file

Below is a flowchart of a program. Most everything works as expected, but there are a couple of issues that I need some expert help on. The check function was setup initially for a single user input. The input has been modified to allow for multiple inputs, so the code below does not work. My question is if two variants are inputted and an error is found in one of them, can that specific variant that caused an error be removed from the saved file here c:/Users/cmccabe/Desktop/Python27/${id}.txt ? Thank you Smilie.

I have attached a screenshot (there is a file saved in that same directory c:/Users/cmccabe/Desktop/Python27/${id}_name.txt of two variants and the file saved. In the example

Code:
 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/annovar/${id}_name.txt
	printf "Is the variant correct?  Y/N "; read match_choice
	
    case "$match_choice" in
        [yY]) id="${id}"; position ;; 
        [nN]) id=""; gjb2 ;;  
    esac
}

Code:
user choice 
|
v 
menu +> gjb2 -> -> -> -> gjb2name -> -> check -> -> -> -> position -> parse -> add2text -> additional? -> annovar ------+
  +  |     ^                 ^            ^                   +         ^          ^            ^           |         ^
  |  |     |                 |            |                   |         |          |            |           |         |
  |  - input id/variant     python      verify             python  (awk/perl       |           more         |       +--Y/N select---+
  |    add NM_                       +--Y/N select-----------+      conditional    |      +--Y/N select-----+         menu         exit
  |    merge input/save                     clear text                   parse)    |            |                     | 
  |    add2text                                                         |          |            |                     |
  |        |                                                            |          |            |                     |
  |        |                      	                                    |          |            |                     |
  |        |                                                            |          |            |                     |
  |	       |                                                            |          |            |                     |
  |        +<-----------------------------------------------------------+<<--------<+-----------<<+-------------------|                        
  |        |     
1. user menu - (4 choices: gjb2,mecp2,phox2b,exit)
2. gjb2 -(user inputs the id and variant, the unique NM_ is added, the input, variant, and NM_ are combined and saved for variant syntax check, id written to text file in seperate directory)
3. gjb2name - python script to verify variant syntax
4. check - Y/N select (If "Y" then goto [position] function, If "N": then clear variant text from file that error was found 
5. position - python - script to convert input to cordinates
6. parse - working on
7. add2text - create list of all ids
8. additional - Y/N select (If "Y" then goto [menu] function, if "N" then goto [annovar] function
9. annovar - perl script to annotate file
10. end - user prompt with Y/N select (If "Y" then goto [menu] function, if "N" {exit program}


Last edited by cmccabe; 03-20-2015 at 03:16 PM..
# 2  
Old 03-20-2015
When i open the screenshot.doc in AbiWord i see nothing but an empty page.

On the other hand, not sure if i understand you correct, if i do, this might help:
Code:
while read id;do check ;done<GJB2.txt

Or in multiline:
Code:
while read id
do  check
done<GJB2.txt

hth
# 3  
Old 03-20-2015
The screenshot is also saved as a text file ${id}_name in that same directory If there is an error in the variant $3 of that file will have (variantchecker): and in $1 in that file will match $1 of the ${id}.txt. That is the variant to remove. Is this possible? Thank you Smilie.

Code:
 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/${id}_name.txt
	printf "Is the variant correct?  Y/N "; read match_choice
	
    case "$match_choice" in
        [yY]) id="${id}"; position ;; 
        [nN]) id=""; while read id;do check "$id";done<GJB2.txt; gjb2 ;;  
    esac
}

# 4  
Old 03-20-2015
Does the variantchecker give an error exit code? Or: how about grep -v error on your id.txt.
# 5  
Old 03-21-2015
The text "variantchecker" will only be there in that file if a variant has an error in it. Thank you Smilie.

---------- Post updated at 03:39 PM ---------- Previous update was at 02:25 PM ----------

I added a warning to the menu:

If the user says "N" then it goes to the warning function and the variant is inputted again and the process continues as before. When the warning function is called I am trying to do post 3 (old variant removed and replaced with new variant). Thank you Smilie.

Code:
 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/${id}_name.txt
	printf "Is the variant correct?  Y/N "; read match_choice
	
    case "$match_choice" in
        [yY]) id="${id}"; position ;; 
        [nN]) awk 'FNR>1 FNR==NR {a[$i]; next}; !($1 in a)' ${id}_name.txt ${id}.txt; warning ;;  
    esac
}

warning() {
    printf "\n\n"
	printf "Please re-enter variant(s): "; IFS="," read -a variants
        
        [ -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<${#variants[@]}; i++))
                do printf "NM_004004.5:%s\n" ${variants[$i]} >> c:/Users/cmccabe/Desktop/Python27/$id.txt
		done
	gjb2name
}

---------- Post updated 03-21-15 at 09:55 AM ---------- Previous update was 03-20-15 at 03:39 PM ----------

I made an edit to the awk that is underlined but I dont think its correct. Thank you Smilie.

Last edited by cmccabe; 03-21-2015 at 11:54 AM..
# 6  
Old 03-22-2015
What do you want to achieve with that awk?
# 7  
Old 03-22-2015
FNR>1 FNR==NR is not a valid awk conditional expression. If you're trying to select all lines in the 1st input file except for the 1st line in that file, you want something like: FNR>1 && FNR==NR.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recover the original file once removed

Hi All, Is there is any machanisim, once delete the file can we restore it. Thanks (8 Replies)
Discussion started by: bmk123
8 Replies

2. UNIX for Beginners Questions & Answers

File Management: Removing of files from Server2 IF the same file is removed from Server1.

Hi Folks, I have a requirement of file management on different servers. Source Server is SERVER-A. Two servers will fetch files from SERVER-A: SERVER1 and SERVER2. 4th SERVER is SERVER-B, It will fetch files from SERVER1. If SERVER1 goes DOWN, SERVER-B will fetch pending files from... (2 Replies)
Discussion started by: Raza Ali
2 Replies

3. UNIX for Beginners Questions & Answers

File Containing Extra delimiter should be removed

The input file is this: a|b|c|d x|y|z|n||||||||| p|q|r|s||| g|h|i| w|e|r|| Now as per requirement , each row should have only 3 delimiter. Now the 2nd row & last row has an extra delimiter, How to remove that ? In some large file having 100K data , there can be 100 such rows having... (4 Replies)
Discussion started by: ikdKunal
4 Replies

4. Solaris

File system full - not removed: No space left on device

Does anyone have any advise on trying to clean up a full filesystem? I can't rm any files because of the follow: not removed: No space left on device Any help would be very much appreciated. (10 Replies)
Discussion started by: craigsky
10 Replies

5. Programming

The fwrite function is not returning error, if the file was removed.

The fwrite function call is not returning error, when the file it writes to is removed, please advise on how to find if the file already opened and being written by a program is removed manually or by some other process. please see the code below, #include<stdio.h> #include<stdlib.h> ... (3 Replies)
Discussion started by: Kesavan
3 Replies

6. Red Hat

How to update rpm database regarding removed file of a package?

For Suppose, I have installed a package having files file1, file2 and file3. After installation, I removed the file "file3". But "rpm -qf file3" is giving the package name, even file3 was not there. And also "rpm -ql package" is also displaying all 3 files. How can i update rpm database about... (6 Replies)
Discussion started by: snreddy_gopu
6 Replies

7. Linux

file removed

Hi Team, I have deleted a file accidentally by using rm command. I am not the root(admin) user. Can you please let me know how to get that .tex file? (2 Replies)
Discussion started by: darling
2 Replies

8. UNIX for Dummies Questions & Answers

how to removed chr(10) characters in a file

Hi, How do we remove an extra new line in a file. New line in ascii is called chr(10). Suppose we have a file as: 12345 98765 ------ ------ From the above i represented new line with dashed lines. Basically i have 2 new lines with white space at the end of the file. How do i removes... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

9. Shell Programming and Scripting

Please Help. Strings in file 1 need to be searched and removed from file 2

Please help. Here is my problem. I have 9000 lines in file a and 500,000 lines in file b. For each line in file a I need to search file b and remove that line. I am currently using the grep -v command and loading the output into a new file. However, because of the size of file b this takes an... (4 Replies)
Discussion started by: mjs3221
4 Replies

10. Solaris

after init all /tmp file has been removed

I'm new in Solaris server After the system support reboot the Solaris server, all the files in /tmp has been removed, is that normal under Solaris or under different init level will get different result? which init level will do that? (5 Replies)
Discussion started by: yesthomas
5 Replies
Login or Register to Ask a Question