In the bash below the unique headers of each vcf.gz are stored in a text file with the same name. That is if 16-0000-file.vcf.gz was used the header text file would be 16-0000-file_header.txt.
There can be multiple vcf.gz in a directory, usually 3, that I need to fix the header in each file before further processing it. My question is how can I match each text file with its vcf.gz and pass the stored variables of each to the reheader code ?
In the below I strip off the unique numerical prefix 16-0000 from both the vcf.gz and text file, but am not sure how to match the two files
vcf.gz in directory (file2)
matching text file in directory (file1)
So the contents of 16-0000.txt would be used to update 16-0000.vcf.gz using the code below.
reheader code
Last edited by cmccabe; 02-02-2017 at 01:40 PM..
Reason: fixed format, added details to bash
Current output syntax error: unexpected end of file, though the portion in bold creates the files that are need in the directory.
desired output
Currently no arguments are being passed to reheader (in italics in the command)
desired arguments passed to reheader
The loop would use each argument in the below to create a new file updated with the fixed header:
I hope this helps and thank you very much .
Please explain in English what the following code is intended to do:
Given that the variable out is never used after being defined by the above statement, are these two lines of code needed?
What happens if you insert the missing done in your script before or after the code discussed above (which should resolve the syntax error in your script)?
This User Gave Thanks to Don Cragun For This Post:
is intended to match and store file1_header.txt as $file1 and match and store file1_header.vcf.gz as $file2.
These two variables are then passed to the reheader command to be processed. After the command executes the variables are reset using the remaining two files.
I will rerun the code omitting the out and adding the done. Thank you .
---------- Post updated at 04:53 PM ---------- Previous update was at 02:25 PM ----------
The portion of code in bold in the previous post is unchanged, but I updated the match portion of the code to:
adding the missing done did allow the script to execute.
The output that I get in the terminal is:
desired output
Basically, on the first pass the $file1 variable is the .txt and $file2 variable is the matching vcf.gz. Those variable are passed to the reheader command it is executed. After it executes the variables are reset using the other files in the directory. Since the numerical prefix is always unique that is used to perform the match between files. There will also also be a match vcf.gz and .txt. Thank you .
Last edited by cmccabe; 02-02-2017 at 06:56 PM..
Reason: added details
is intended to match and store file1_header.txt as $file1 and match and store file1_header.vcf.gz as $file2.
These two variables are then passed to the reheader command to be processed. After the command executes the variables are reset using the remaining two files.
I will rerun the code omitting the out and adding the done. Thank you .
---------- Post updated at 04:53 PM ---------- Previous update was at 02:25 PM ----------
The portion of code in bold in the previous post is unchanged, but I updated the match portion of the code to:
adding the missing done did allow the script to execute.
The output that I get in the terminal is:
desired output
Basically, on the first pass the $file1 variable is the .txt and $file2 variable is the matching vcf.gz. Those variable are passed to the reheader command it is executed. After it executes the variables are reset using the other files in the directory. Since the numerical prefix is always unique that is used to perform the match between files. There will also also be a match vcf.gz and .txt. Thank you .
Given that there is nothing in your script that attempts to print the string $file1= nor the string $file2=, I have no idea how you would expect your script to produce that output???
Furthermore, since your ls output doesn't show any files with any of the filenames shown on the right hand side of those strings, I can't guess at how you would expect your script to create those names and find those names as existing files. (But of course I did ask for ls -l output from all three of your directories and you only showed output from one of those directories and didn't indicate which one of those three directories was the current working directory for the listing you provided, so maybe your names would make sense.)
The confusion between the the punctuation you use in the names of your files completely confuses any attempt to guess at what you want. Above we have .txt file filenames:
quoted from post #5 (with two showing underscores between the leading sequences of digits and two showing hyphens between the leading sequences of digits, while the names shown in post #1 were:
using a completely different filename format.
Is it really that hard to give us an accurate description of the files you're working with and what you're trying to do?
This User Gave Thanks to Don Cragun For This Post:
Some of the file names and locations were different because I was at the office then at home and that was a problem leading to typos. I apologize for that and am back in the office. The details below are the exact files in the directory.
There are always 3 vcf.gz files in the following format below in each directory:
Files in /home/cmccabe/Desktop/NGS/test
The numeric prefix of each is always 7 characters xx-xxxx and unique. The portion of code in the previous post uses each vcf.gz file to create a corresponding .txt file with only the unique numeric prefix followed by _header.
Files in /home/cmccabe/Desktop/NGS/test (if code works as expected)
I am trying to match the 16-0000.vcf.gz with the 16-0000.txt and read 16-0000.vcf.gz into $file1 and 16-0000.txt into $file2.
These two variables $file1 and $file2 would be passed to the reheader command, in bold,below which is part of a loop.
After the $file1 and $file2 are processed for 16-0000, the process is repeated for the remaining two files, 16-0002 and 16-0005.
reheader command
There is only one directory that contains the files and that is /home/cmccabe/Desktop/NGS/test. The numerical prefixes are not being stripped off and used to perform the match between files nor are the variables being passed to reheader. Thank you .
I am trying to use bash to loop through a directory /path/to/data using a prefix match from /path/to/file. That match is obtained and works using the code below (in green)... what I can not seem to do is populate or update the corresponding prefix_file.txt in /path/to/data with the values in each... (3 Replies)
In the awk below I am trying to use the file1 as a match to file2. In file2 the contents of $5,&6,and $7 (always tab-delimited) and are copied to the output under the header Quality metrics. The below executes but the output is empty. I have added comments to help and show my thinking. Thank you... (0 Replies)
In the file1 below if $9 and $12 are . (dot) then the value in $8 of file1 is used as a key (exact match) to lookup in each $2 of file2, when a match is found then the value of $4
in file1 is used to look for a range match within +/- 50 using the values in $4 and after in file2. The number of... (9 Replies)
In the below bash I am trying to rename eachof the 3 text files in /home/cmccabe/Desktop/percent by matching the numerical portion of each file to lines 3,4, or 5 in /home/cmccabe/Desktop/analysis.txt. There will always be a match between the files. When a match is found each text file in... (2 Replies)
I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output.
$1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
The bash below loops through a specific directory dir and finds and writes the oldest folder to a variable called $filename.
#!/bin/bash
# oldest folder stored as variable for analysis, version log created, and quality indicators matched to run
dir=/home/cmccabe/Desktop/NGS/test
find... (2 Replies)
Dear All,
assume i have a file with content:
<Start>6000</Start>
<Stop>7599</Stop>
the output is:
6000
7000
7100
7200
7300
7400
7599
how should we use any awk, sed, perl can do this task, means to extract the uniq prefixes from the start and stop prefix.
Thanks
Jimmy (3 Replies)
Hi,
I have a file of csv data, which looks like this:
file1:
1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628
2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Hi,
I am trying to write a script which parses a log file and will eventually put the values in an array so that I can perform some math on it. In this file I am only interested in the last 200 lines so here is the command I use to display the contents in a manageable manner.
tail -200... (3 Replies)
I have searched the internet (including these forums) and perhaps I'm not using the right wording.
What I'm looking for is a function (preferably C) that analyzes the similitude of two numerical or near-numerical values, and returns either a true/false (match/nomatch) or a return code that... (4 Replies)