Sponsored Content
Top Forums Shell Programming and Scripting awk to split one field and print the last two fields within the split part. Post 302624773 by yifangt on Monday 16th of April 2012 09:41:57 PM
Old 04-16-2012
awk to split one field and print the last two fields within the split part.

Hello;
I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is the input file like (>100k rows!!!):
Code:
B_1019927    ES904790    Unknown    Unknown protein
B_1065532    JCVI_27855   JCVI_27855|gb|DW997385|gb|CD815403|gb|EV204160|gb|CD813268|gb|EX038736|UniProt|Q8RWM2    Putative uncharacterized protein At4g36940
B_1065533    JCVI_27856   JCVI_27856|gb|CD826551|gb|DY030639|gb|CX272767|gb|EV056662|gb|EX022554|gb|EX038271|UniProt|Q3E9T4    Protein At4g31430
B_1065534    JCVI_27857   JCVI_27857|gb|DY023794|gb|EE530065|gb|CX280035|UniProt|Q84WF5    Probable VAMP-like protein At1g33475
B_1065535    JCVI_27858   JCVI_27858|gb|ES941909|gb|ES940913|gb|EE514812|UniProt|Q8LBM4    Iron-sulfur assembly protein IscA-like 1, mitochondrial precursor

I want the output file with the truncated field-3, which is like following:
Code:
B_1019927    ES904790    Unknown    Unknown protein
B_1065532    JCVI_27855    UniProt    Q8RWM2     Putative uncharacterized protein At4g36940
B_1065533    JCVI_27856    UniProt    Q3E9T4     Protein At4g31430
B_1065534    JCVI_27857    UniProt    Q84WF5     Probable VAMP-like protein At1g33475
B_1065535    JCVI_27858    Uniprot    Q8LBM4     Iron-sulfur assembly protein IscA-like 1, mitochondrial precursor

What I did is by matching the "UniProt" string in the third field, split this field and only print the last two columns of the split fields, the original 3 fields ($1, $2, $4) need to be printed untouched.

Here is my code:
Code:
awk 'FS="\t" {for(i=1;i<=NF;i++) if(match($i,"UniProt")) split($i, a, "|"); {print $1, "\t", $2, "\t", $a[-2],"\t", $a[-1],"\t",$NF}}' infile.csv

Have struggled for a while, but did not work out. Appreciate your expertise to help me out. Thanks a lot! Yifang
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split a field in awk script

Hi all, I have a field in the line, let's say argument $6, which is in the format 00.00 If i want to split the field to get rid of the "." in between of the amount, how can i do that i awk script? I have it like this split($6,a,".") but it will get rid of the last 2 digits after the... (4 Replies)
Discussion started by: CamTu
4 Replies

2. Shell Programming and Scripting

can Awk split my field on the .

I am trying to pull data out of a file to execute a series of repetitive commands. One of the fields is a {hex number}.{hex number} pattern. I need the first part of that structure to pass into the command. The file structure is like this: A 2007/10/20 09:50:00 li text ef6da.1 name ... (6 Replies)
Discussion started by: oly_r
6 Replies

3. Shell Programming and Scripting

How to split a field into two fields?

Hi, I have a comma delimited text file where character fields (as opposed to numeric and date fields) are always enclosed with double quotes. Records are separated by the newline character. In a shell script I would like to split a particular field into two separate fields (enclosed with double... (4 Replies)
Discussion started by: vbrown
4 Replies

4. Shell Programming and Scripting

Split field with awk

Hi there I have a text file with several fields separated by ";" as follow : 5466-43;5466;JOAN;LIGA;LIGA ESPANOLA;43;DEP LA CORUNA - OSASUNA;10/01/10 17:00 5466-44;5466;CARLES;LIGA;LIGA ESPANOLA;44;MALAGA - ATHL BILBAO;10/01/10 17:00 5466-45;5466;FAB;LIGA;LIGA ESPANOLA;45;REAL MADRID -... (4 Replies)
Discussion started by: capnino
4 Replies

5. Shell Programming and Scripting

AWK:Split fields separated by semicolon

Hi all, I have a .vcf file which contains 8 coulmns and the data under each column as shown below, CHROM POS ID REF ALT QUAL FILTER INFO 1 3000012 . A G 126 ... (6 Replies)
Discussion started by: mehar
6 Replies

6. Shell Programming and Scripting

awk split lines without knowing the number of fields a-priori

I want to use awk to split fields and put them into a file but I don't know the number of fields for example, in the following line Ports: 22/filtered/tcp//ssh///, 53/open/tcp//tcpwrapped///, 111/filtered/tcp//rpcbind///, 543/filtered/tcp//klogin///, 544/filtered/tcp//kshell///,... (3 Replies)
Discussion started by: esolvepolito
3 Replies

7. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

8. Shell Programming and Scripting

awk split after second underscore in field

I am trying to split a tab-delimeted file using awk after the second _ in bold. The awk below is close but splits on the first _, and I am not sure how to use the second _. Thank you :). file chr1 92145889 92149424 NM_001195684_exon_0_10_chr1_92145900_r 0 - chr1 92161218 ... (4 Replies)
Discussion started by: cmccabe
4 Replies

9. Shell Programming and Scripting

awk to add plus or minus to fields and split another field

In the tab-delimited input below I am trying to use awk to -10 from $2 and +10 to $3. Something like awk -F'\t' -v OFS='\t' -v s=10 '{split($4,a,":"); print $1,$2-s,$3+s,a,$5,$6} | awk {split(a,b,"-"); print $1,$2-s,$3+s,b-s,b+s,$5,$6}' input should do that. I also need to -10 from $4... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. UNIX for Beginners Questions & Answers

awk to split field twice using two deliminators

In the awk I am splitting on the : into array a, then splitting on the - into element b. I can not seem to duplicate b if there is no - after it. Lines 1,2,4 are examples. If there is a - after the number in b then the value to the right of it is $3 in the ouput. Thank you :). awk... (2 Replies)
Discussion started by: cmccabe
2 Replies
Bio::SeqIO::swiss(3pm)					User Contributed Perl Documentation				    Bio::SeqIO::swiss(3pm)

NAME
Bio::SeqIO::swiss - Swissprot sequence input/output stream SYNOPSIS
It is probably best not to use this object directly, but rather go through the SeqIO handler system: use Bio::SeqIO; $stream = Bio::SeqIO->new(-file => $filename, -format => 'swiss'); while ( my $seq = $stream->next_seq() ) { # do something with $seq } DESCRIPTION
This object can transform Bio::Seq objects to and from Swiss-Pprot flat file databases. There is a lot of flexibility here about how to dump things which needs to be documented. GN (Gene name) line management details A Uniprot/Swiss-Prot entry holds information on one protein sequence. If that sequence is identical across genes and species, they are all merged into one entry. This creates complex needs for several annotation fields in swiss-prot format. The latest syntax for GN line is described in the user manual: http://www.expasy.ch/sprot/userman.html#GN_line Each of the possibly multiple genes in an entry can have Name, Synonyms (only if there is a name), OrderedLocusNames (names from genomic sequences) and ORFNames (temporary or cosmid names). "Name" here really means "symbol". This complexity is now dealt with the following way: A new Bio::AnnotationI class was created in order to store the data in tag-value pairs. This class (Bio::Annotation::TagTree) is stored in the Bio::Annotation::Collection object and is accessed like all other annotations. The tag name is 'gene_name'. There is a single Bio::Annotation::TagTree per sequence record, which corresponds to the original class that stored this data (Bio::Annotation::StructuredValue). Depending on how we progress this may change to represent each group of gene names. For now, to access the gene name tree annotation, one uses the below method: my ($gene) = $seq->annotation->get_Annotations('gene_name'); If you are only interested in displaying the values, value() returns a string with similar formatting. There are several ways to get directly at the information you want if you know the element (tag) for the data. For gene names all data is stored with the element-tag pairs: "element1=tag1, tag2, tag3; element2=tag4, tag5;" This normally means the element will be 'Name', 'Synonyms', etc. and the gene names the values. Using findval(), you can do the following: # grab a flattened list of all gene names my @names = $ann->findval('Name'); # or iterated through the nodes and grab the name for each group for my $node ($ann->findnode('gene_name')) { my @names = $node->findval('Name'); } The current method for parsing gene name data (and reconstructing gene name output) is very generic. This is somewhat preemptive if, for instance, UniProt decides to update and add another element name to the current ones using the same formatting layout. Under those circumstances, one can iterate through the tag tree in a safe way and retrieve all node data like so. # retrieve the gene name nodes (groups like names, synonyms, etc). for my $ann ($seq->annotation->get_Annotations('gene_name')) { # each gene name group for my $node ($ann->findnode('gene_name')) { print "Gene name: "; # each gene name node (tag => value pair) for my $n ($node->children) { print " ".$n->element.": ".$n->children." "; } } } For more uses see Bio::Annotation::TagTree. Since Uniprot/Swiss-Prot format have been around for quite some time, the parser is also able to read in the older GN line syntax where genes are separated by AND and various symbols by OR. The first symbol is taken to be the 'Name' and the remaining ones are stored as 'Synonyms'. Also, for UniProt output we support using other Bio::AnnotationI, but in this case we only use the stringified version of the annotation. This is to allow for backwards compatibility with code that previously used Bio::Annotation::SimpleValue or other Bio::AnnotationI classes. Optional functions _show_dna() (output only) shows the dna or not _post_sort() (output only) provides a sorting func which is applied to the FTHelpers before printing _id_generation_func() This is function which is called as print "ID ", $func($seq), " "; To generate the ID line. If it is not there, it generates a sensible ID line using a number of tools. If you want to output annotations in Swissprot format they need to be stored in a Bio::Annotation::Collection object which is accessible through the Bio::SeqI interface method annotation(). The following are the names of the keys which are polled from a Bio::Annotation::Collection object. reference - Should contain Bio::Annotation::Reference objects comment - Should contain Bio::Annotation::Comment objects dblink - Should contain Bio::Annotation::DBLink objects gene_name - Should contain Bio::Annotation::SimpleValue object 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 one of the Bioperl mailing lists. 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 the bugs and their resolution. Bug reports can be submitted via the web: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Elia Stupka Email elia@tll.org.sg APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ next_seq Title : next_seq Usage : $seq = $stream->next_seq() Function: returns the next sequence in the stream Returns : Bio::Seq object Args : write_seq Title : write_seq Usage : $stream->write_seq($seq) Function: writes the $seq object (must be seq) to the stream Returns : 1 for success and 0 for error Args : array of 1 to n Bio::SeqI objects _generateCRCTable Title : _generateCRCTable Usage : Function: Example : Returns : Args : _crc32 Title : _crc32 Usage : Function: Example : Returns : Args : _crc64 Title : _crc64 Usage : Function: Example : Returns : Args : _print_swissprot_FTHelper Title : _print_swissprot_FTHelper Usage : Function: Example : Returns : Args : _read_swissprot_References Title : _read_swissprot_References Usage : Function: Reads references from swissprot format. Internal function really Example : Returns : Args : _read_swissprot_Species Title : _read_swissprot_Species Usage : Function: Reads the swissprot Organism species and classification lines. Able to deal with unconventional species names. Example : OS Unknown prokaryotic organism $genus = undef ; $species = Unknown prokaryotic organism Returns : A Bio::Species object Args : _filehandle Title : _filehandle Usage : $obj->_filehandle($newval) Function: Example : Returns : value of _filehandle Args : newvalue (optional) _read_FTHelper_swissprot Title : _read_FTHelper_swissprot Usage : _read_FTHelper_swissprot($buffer) Function: reads the next FT key line Example : Returns : Bio::SeqIO::FTHelper object Args : _write_line_swissprot Title : _write_line_swissprot Usage : Function: internal function Example : Returns : Args : _write_line_swissprot_regex Title : _write_line_swissprot_regex Usage : Function: internal function for writing lines of specified length, with different first and the next line left hand headers and split at specific points in the text Example : Returns : nothing Args : file handle, first header, second header, text-line, regex for line breaks, total line length _post_sort Title : _post_sort Usage : $obj->_post_sort($newval) Function: Returns : value of _post_sort Args : newvalue (optional) _show_dna Title : _show_dna Usage : $obj->_show_dna($newval) Function: Returns : value of _show_dna Args : newvalue (optional) _id_generation_func Title : _id_generation_func Usage : $obj->_id_generation_func($newval) Function: Returns : value of _id_generation_func Args : newvalue (optional) _ac_generation_func Title : _ac_generation_func Usage : $obj->_ac_generation_func($newval) Function: Returns : value of _ac_generation_func Args : newvalue (optional) _sv_generation_func Title : _sv_generation_func Usage : $obj->_sv_generation_func($newval) Function: Returns : value of _sv_generation_func Args : newvalue (optional) _kw_generation_func Title : _kw_generation_func Usage : $obj->_kw_generation_func($newval) Function: Returns : value of _kw_generation_func Args : newvalue (optional) perl v5.14.2 2012-03-02 Bio::SeqIO::swiss(3pm)
All times are GMT -4. The time now is 09:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy