Sponsored Content
Top Forums Shell Programming and Scripting awk to match file1 and extract specific tag values Post 303028307 by MadeInGermany on Friday 4th of January 2019 04:42:44 AM
Old 01-04-2019
I think you want a lookup table from file1: $1 is the lookup key and $2 the returned value.
Code:
# in file 1 store the $2 values in s[$1] (s[] indexed by $1)
FNR==NR {
  s[$1]=$2
  next
}

Now you can test existence with (key in s) or get the value with s[key] or loop through the keys with for (key in s).

I think the following captures the wanted values in file2:
Code:
{
  match($8,/'normalizedPos':'([^']+)'/, pos)  # extract value after : into pos[]
  match((";" $8),/;(AF=[^;]+).*;(FDP=[^;]+)/, info) # extract values after AF= and FDP= into info[]
  match($8,/'gene':'([^']+)'/,gene) # extract the value after gene into gene[]
  print "pos[1]="pos[1], "info[1]="info[1], "info[2]="info[2], "gene[1]="gene[1]
}

Note1: the target array as 3rd argument is an extension in GNU-awk. (Maybe you want to consider perl? Then it works on all platforms that have perl.)
Note2: for a most exact string match use a "border character". I have even prepended a ";" to the input string for match() in order to ensure it exists even at the beginning.
This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

to extract specific values twice in a file

Hi Friends, I have a file with the following values.. xyz.txt,12345.xml abc.txt,04567.xml cde.txt,12134.xml I would like to extract all the 2nd column values twice as shown in the example like 12345,12345.xml 04567,04567.xml 12134,12134.xml Please advice!! In the formus one of... (7 Replies)
Discussion started by: techmoris
7 Replies

2. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

3. Shell Programming and Scripting

Extract all content that match exactly only specific word

Input: 21 templeta parent 35718 36554 . - . ID=parent_cluster_50.21.11; Name=Partial%20parent%20for%20training%20set; 21 templeta kids 35718 36554 . - . ID=_52; Parent=parent_cluster_5085.21.11; 21 templeta ... (7 Replies)
Discussion started by: patrick87
7 Replies

4. Shell Programming and Scripting

Get values from different columns from file2 when match values of file1

Hi everyone, I have file1 and file2 comma separated both. file1 is: Header1,Header2,Header3,Header4,Header5,Header6,Header7,Header8,Header9,Header10 Code7,,,,,,,,, Code5,,,,,,,,, Code3,,,,,,,,, Code9,,,,,,,,, Code2,,,,,,,,,file2... (17 Replies)
Discussion started by: cgkmal
17 Replies

5. Shell Programming and Scripting

Extract values from a specific column to the end

Hello friends, I have a text file with many columns (no. columns vary from row to row) separated by space. I need to collect all the values from 18th column to the end from each line and group them as pairs and then numbering like below.. 1. 18th-col-value 19th-col-value 2. 20th-col-value ... (5 Replies)
Discussion started by: prvnrk
5 Replies

6. Shell Programming and Scripting

awk to print string if tag is specific value

In the below awk I am trying to print expName only if another tag planExecuted is true. In addition to the expName I am also printing planShortID. For some reason the word experiment gets printed so I remove it with sed. I have attached the complete index.html as well as included a sample of it... (1 Reply)
Discussion started by: cmccabe
1 Replies

7. Shell Programming and Scripting

Return path of specific tag using awk

The below awk is used with the attached index.html and matches the specific user id in the sub portion with path of /rundb/api/v1/plugin/49/. The command does run but the output is blank. Something changed in the file structure as it used to work. So using the first line in the output: ... (2 Replies)
Discussion started by: cmccabe
2 Replies

8. Shell Programming and Scripting

awk to update specific value in file with match and add +1 to specific digit

I am trying to use awk to match the NM_ in file with $1 of id which is tab-delimited. The NM_ will always be in the line of file that starts with > and be after the second _. When there is a match between each NM_ and id, then the value of $2 in id is substituted or used to update the NM_. Each NM_... (3 Replies)
Discussion started by: cmccabe
3 Replies

9. Shell Programming and Scripting

awk to search field2 in file2 using range of fields file1 and using match to another field in file1

I am trying to use awk to find all the $2 values in file2 which is ~30MB and tab-delimited, that are between $2 and $3 in file1 which is ~2GB and tab-delimited. I have just found out that I need to use $1 and $2 and $3 from file1 and $1 and $2of file2 must match $1 of file1 and be in the range... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. Shell Programming and Scripting

awk to extract tag and add to each line

In the awk below which executes as is, I am trying to add a condition that will extract the text or value after the FR= for the lines in each line of file1 compared to file2. As is the lines between the two files are either a match, Missing in file 1, or Missing in file2, but I can not add the... (1 Reply)
Discussion started by: cmccabe
1 Replies
Bio::Tools::Run::Ensembl(3pm)				User Contributed Perl Documentation			     Bio::Tools::Run::Ensembl(3pm)

NAME
Bio::Tools::Run::Ensembl - A simplified front-end for setting up the registry for, and then using an Ensembl database with the Ensembl Perl API. SYNOPSIS
use Bio::Tools::Run::Ensembl; # get a Bio::EnsEMBL::Gene for agene of interest my $gene = Bio::Tools::Run::Ensembl->get_gene_by_name(-species => 'human', -name => 'BRCA2'); DESCRIPTION
This is a simple way of accessing the Ensembl database to retrieve gene information. Rather than learn the whole Ensembl Perl API, you only need to install it (that is, check it out from CVS: http://www.ensembl.org/info/docs/api/api_installation.html - ignore the information about BioPerl version) and then you can get information about a gene using get_gene_by_name(). For gene retrieval it is especially useful compared to direct Ensembl Perl API usage since it can use information from alternate data sources (orthologues, Swissprot, Entrez) to get your gene. FEEDBACK
Mailing Lists User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated. bioperl-l@bioperl.org - General discussion http://bioperl.org/wiki/Mailing_lists - About the mailing lists Support Please direct usage questions or support issues to the mailing list: bioperl-l@bioperl.org rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. Reporting Bugs Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web: http://redmine.open-bio.org/projects/bioperl/ AUTHOR - Sendu Bala Email bix@sendu.me.uk APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ registry_setup Title : registry_setup Usage : Bio::Tools::Run::Ensembl->registry_setup(-host => $host, -user => $user); if (Bio::Tools::Run::Ensembl->registry_setup) {...} Function: Configure the ensembl registy to use a certain database. The database must be an Ensembl database compatible with the Ensembl Perl API, and you must have that API installed for this method to return true. Defaults to anonymous access to ensembldb.ensembl.org Or just ask if the registry is setup and the database ready to use. Returns : boolean (true if Registry loaded and ready to use) Args : -host => host name (defaults to 'ensembldb.ensembl.org') -user => username (defaults to 'anonymous') -pass => password (no default) -port => port (defaults to 3306) -db_version => version of ensembl database to use, if different from your installed Ensembl modules -verbose => boolean (1 to print messages during database connection) -no_database => boolean (1 to disable database access, causing this method to always return false) get_adaptor Title : get_adaptor Usage : my $adaptor = Bio::Tools::Run::Ensembl->get_adaptor($species, $type); Function: Get a species-specific 'core' database adaptor, optionally of a certain type. Returns : Bio::EnsEMBL::DBSQL::DBAdaptor, OR if a certain type requested, a Bio::EnsEMBL::DBSQL::${type}Adaptor Args : Bio::Species or string (species name) (REQUIRED), AND optionally string (the type of adaptor, eg. 'Gene' or 'Slice'). get_gene_by_name Title : get_gene_by_name Usage : my $gene = Bio::Tools::Run::Ensembl->get_gene_by_name(); Function: Get a gene given species and a gene name. If multiple genes match this combination, tries to pick the 'best' match. Returns : Bio::EnsEMBL::Gene Args : -species => Bio::Species or string (species name), REQUIRED -name => string: gene name, REQUIRED If searching for the supplied gene name in the supplied species results in no genes, or more than one, you can choose what else is attempted in order to find just one gene: -use_orthologues => Bio::Species or string (species name), or array ref of such things: see if any of these supplied species have (unambiguously) a gene with the supplied gene name and if a (one-to-one) orthologue of that gene in that species is present in the main desired species supplied to -species, returns that orthologous gene. (default: none, do not use orthologues) -use_swiss_lookup => boolean: queries swissprot at expasy and if a suitable match is found, queries ensembl with the swissprot id. (default: 0, do not use swiss) -use_entrez_lookup => boolean: queries entrez at the NCBI server if (only) a single gene could not be found by any other method, then query ensembl with the entrez gene id. (default: 0, do not use NCBI) (Attempts proceed in this order and return as soon as one method is successful.) -strict => boolean: return undef with no warnings if more than one, or zero genes were found. (default: 0, warnings are issued and if many genes were found, one of them is returned) perl v5.12.3 2011-06-18 Bio::Tools::Run::Ensembl(3pm)
All times are GMT -4. The time now is 01:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy