Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Repositioning based on column values Post 302940148 by A-V on Wednesday 1st of April 2015 03:38:13 PM
Old 04-01-2015
Error Repositioning based on column values

Dear all ...
I have a file which I want to change the structure based on the values in some columns and I would be grateful if you can help...
one of my files looks like ... they all have ten rows
Code:
1,0,0
10,0,0
2,0,0
3,0,0
4,1,1
4,1,1
4,1,1
5,0,0
6,0,0
7,0,0
8,0.5,2
9,0.33,3
9,0.33,3

what I was to get is
Code:
1,0
10,0
2,0
3,0
4,3
5,0
6,0
7,1.63 #(0.33*2)+0.5
8,1.63 #(0.33*2)+0.5
9,0.66 #(0.33*2)

So what is happening is if value is not 0 the value in $2 is being published in rows that are between [$1-$3+1, $1] which means for "9,0.33,3", 0.33 is published 3 times in rows 7,8 and 9... else the value stays 0

I have managed to combine the values to combine the multiple row of the same values
Code:
awk -F, '{a[$1]+=$2;} END {for(i in a )  print i","a[i]","}'

so my data now looks like

Code:
1,0,
10,0,
2,0,
3,0,
4,3,
5,0,
6,0,
7,0,
8,0.5,
9,0.666666,

so not sure how to implement get the final row and distribute the values correctly

Can you help

Last edited by A-V; 04-01-2015 at 04:57 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

2. Shell Programming and Scripting

How to averaging column based on first column values

Hello I have file that consist of 2 columns of millions of entries timestamp and throughput I want to find the average (throughput ) for each equal timestamp before change it to proper format e.g : i want to average 2 coloumnd fot all 1308154800 values in column 1 and then print... (4 Replies)
Discussion started by: aadel
4 Replies

3. Shell Programming and Scripting

join rows based on the column values

Hi, Please help me to convert the input file to a new one. input file: -------- 1231231231 3 A 4561223343 0 D 1231231231 1 A 1231231231 2 A 1231231231 4 D 7654343444 2 A 4561223343 1 D 4561223343 2 D the output should be: -------------------- 1231231231 3#1#2 A 4561223343 0 D... (3 Replies)
Discussion started by: vsachan
3 Replies

4. UNIX for Dummies Questions & Answers

Cut from tables based on column values

Hello, I have a tab-delimited table that may contain 11,12 or 13 columns. Depending on the number of columns, I want to cut and get a sub table as shown below. However, the awk commands in the code seem to be an issue. What should I be doing differently? #cut columns 1-2,4-5,11 when 12 &... (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

5. Shell Programming and Scripting

Adding values of a column based on another column

Hello, I have a data such as this: ENSGALG00000000189 329 G A 4 2 0 ENSGALG00000000189 518 T C 5 1 0 ENSGALG00000000189 1104 G A 5 1 0 ENSGALG00000000187 3687 G T 5 1 0 ENSGALG00000000187 4533 A T 4 2 0 ENSGALG00000000233 5811 T C 4 2 0 ENSGALG00000000233 5998 C A 5 1 0 I want to... (3 Replies)
Discussion started by: Homa
3 Replies

6. Shell Programming and Scripting

Choosing rows based on column values

I have a .csv file: A,B,0.6 C,D,-0.7 D,E,0.1 A,E,0.45 D,G, -0.4 I want to select rows based on the values of the 3rd columns such that it is >=0.5 or <= -0.5 Thanks. A,B,0.6 D,G, -0.7 (1 Reply)
Discussion started by: Sanchari
1 Replies

7. Shell Programming and Scripting

Sum column values based in common identifier in 1st column.

Hi, I have a table to be imported for R as matrix or data.frame but I first need to edit it because I've got several lines with the same identifier (1st column), so I want to sum the each column (2nd -nth) of each identifier (1st column) The input is for example, after sorted: K00001 1 1 4 3... (8 Replies)
Discussion started by: sargotrons
8 Replies

8. Shell Programming and Scripting

Fetch parent value based on column values

Hi All, I am trying to achieve the below logic, could you please help me in this. In second row 2nd column I've Value JC2 and the same JC2 is 4th row 1st column.So I need to replace JC2 value in 4th row with JC2 2nd row's 1st column. Input: Job1,JC1 Job1,JC2 Job1,JC3 JC2,JA1... (6 Replies)
Discussion started by: unme
6 Replies

9. Shell Programming and Scripting

Concatenate values in the first column based on the second column.

I have a file (myfile.txt) with contents like this: 1.txt apple is 3.txt apple is 5.txt apple is 2.txt apple is a 7.txt apple is a 8.txt apple is a fruit 4.txt orange not a fruit 6.txt zero isThe above file is already sorted using this command: sort -k2 myfile.txtMy objective is to get... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

10. UNIX for Beginners Questions & Answers

Filtering based on column values

Hi there, I am trying to filter a big file with several columns using values on a column with values like (AC=5;AN=10;SF=341,377,517,643,662;VRT=1). I wont to filter the data based on SF= values that are (bigger than 400) ... (25 Replies)
Discussion started by: daashti
25 Replies
Bio::SeqIO::table(3pm)					User Contributed Perl Documentation				    Bio::SeqIO::table(3pm)

NAME
Bio::SeqIO::table - sequence input/output stream from a delimited table SYNOPSIS
#It is probably best not to use this object directly, but #rather go through the SeqIO handler system. Go: $stream = Bio::SeqIO->new(-file => $filename, -format => 'table'); while ( my $seq = $stream->next_seq() ) { # do something with $seq } DESCRIPTION
This class transforms records in a table-formatted text file into Bio::Seq objects. A table-formatted text file of sequence records for the purposes of this module is defined as a text file with each row corresponding to a sequence, and the attributes of the sequence being in different columns. Columns are delimited by a common delimiter, for instance tab or comma. The module permits specifying which columns hold which type of annotation. The semantics of certain attributes, if present, are pre- defined, e.g., accession number and sequence. Additional attributes may be added to the annotation bundle. 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 email or the web: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Hilmar Lapp Email hlapp at gmx.net APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ new Title : new Usage : $stream = Bio::SeqIO->new(-file => $filename, -format => 'table') Function: Returns a new seqstream Returns : A Bio::SeqIO stream for a table format Args : Named parameters: -file name of file to read -fh filehandle to attach to -comment leading character(s) introducing a comment line -header the number of header lines to skip; the first non-comment header line will be used to obtain column names; column names will be used as the default tags for attaching annotation. -delim the delimiter for columns as a regular expression; consecutive occurrences of the delimiter will not be collapsed. -display_id the one-based index of the column containing the display ID of the sequence -accession_number the one-based index of the column containing the accession number of the sequence -seq the one-based index of the column containing the sequence string of the sequence -species the one-based index of the column containing the species for the sequence record; if not a number, will be used as the static species common to all records -annotation if provided and a scalar (but see below), a flag whether or not all additional columns are to be preserved as annotation, the tags used will either be 'colX' if there is no column header and where X is the one-based column index, and otherwise the column headers will be used as tags; if a reference to an array, or a square bracket-enclosed string of comma-delimited values, only those columns (one-based index) will be preserved as annotation, tags as before; if a reference to a hash, or a curly braces-enclosed string of comma-delimited key and value pairs in alternating order, the keys are one-based column indexes to be preserved, and the values are the tags under which the annotation is to be attached; if not provided or supplied as undef, no additional annotation will be preserved. -colnames a reference to an array of column labels, or a string of comma-delimited labels, denoting the columns to be converted into annotation; this is an alternative to -annotation and will be ignored if -annotation is also supplied with a valid value. -trim flag determining whether or not all values should be trimmed of leading and trailing white space and double quotes Additional arguments may be used to e.g. set factories and builders involved in the sequence object creation (see the POD of Bio::SeqIO). next_seq Title : next_seq Usage : $seq = $stream->next_seq() Function: returns the next sequence in the stream Returns : Bio::Seq::RichSeq object Args : comment_char Title : comment_char Usage : $obj->comment_char($newval) Function: Get/set the leading character(s) designating a line as a comment-line. Example : Returns : value of comment_char (a scalar) Args : on set, new value (a scalar or undef, optional) header Title : header Usage : $obj->header($newval) Function: Get/set the number of header lines to skip before the rows containing actual sequence records. If set to zero or undef, means that there is no header and therefore also no column headers. Example : Returns : value of header (a scalar) Args : on set, new value (a scalar or undef, optional) delimiter Title : delimiter Usage : $obj->delimiter($newval) Function: Get/set the column delimiter. This will in fact be treated as a regular expression. Consecutive occurrences will not be collapsed to a single one. Example : Returns : value of delimiter (a scalar) Args : on set, new value (a scalar or undef, optional) attribute_map Title : attribute_map Usage : $obj->attribute_map($newval) Function: Get/set the map of sequence object initialization attributes (keys) to one-based column index. Attributes will usually need to be prefixed by a dash, just as if they were passed to the new() method of the sequence class. Example : Returns : value of attribute_map (a reference to a hash) Args : on set, new value (a reference to a hash or undef, optional) annotation_map Title : annotation_map Usage : $obj->annotation_map($newval) Function: Get/set the mapping between one-based column indexes (keys) and annotation tags (values). Note that the map returned by this method may change after the first next_seq() call if the file contains a column header and no annotation keys have been predefined in the map, because upon reading the column header line the tag names will be set automatically. Note also that the map may reference columns that are used as well in the sequence attribute map. Example : Returns : value of annotation_map (a reference to a hash) Args : on set, new value (a reference to a hash or undef, optional) keep_annotation Title : keep_annotation Usage : $obj->keep_annotation($newval) Function: Get/set flag whether or not to keep values from additional columns as annotation. Additional columns are all those columns in the input file that aren't referenced in the attribute map. Example : Returns : value of keep_annotation (a scalar) Args : on set, new value (a scalar or undef, optional) annotation_columns Title : annotation_columns Usage : $obj->annotation_columns($newval) Function: Get/set the names (labels) of the columns to be used for annotation. This is an alternative to using annotation_map. In order to have any effect, it must be set before the first call of next_seq(), and obviously there must be a header line (or row) too giving the column labels. Example : Returns : value of annotation_columns (a reference to an array) Args : on set, new value (a reference to an array of undef, optional) trim_values Title : trim_values Usage : $obj->trim_values($newval) Function: Get/set whether or not to trim leading and trailing whitespace off all column values. Example : Returns : value of trim_values (a scalar) Args : on set, new value (a scalar or undef, optional) Internal methods All methods with a leading underscore are not meant to be part of the 'official' API. They are for use by this module only, consider them private unless you are a developer trying to modify this module. _attribute_map Title : _attribute_map Usage : $obj->_attribute_map($newval) Function: Get only. Same as attribute_map, but zero-based indexes. Note that any changes made to the returned map will change the map used by this instance. You should know what you are doing if you modify the returned value (or if you call this method in the first place). Example : Returns : value of _attribute_map (a reference to a hash) Args : none _annotation_map Title : _annotation_map Usage : $obj->_annotation_map($newval) Function: Get only. Same as annotation_map, but with zero-based indexes. Note that any changes made to the returned map will change the map used by this instance. You should know what you are doing if you modify the returned value (or if you call this method in the first place). Example : Returns : value of _annotation_map (a reference to a hash) Args : none _header_skipped Title : _header_skipped Usage : $obj->_header_skipped($newval) Function: Get/set the flag whether the header was already read (and skipped) or not. Example : Returns : value of _header_skipped (a scalar) Args : on set, new value (a scalar or undef, optional) _next_record Title : _next_record Usage : Function: Navigates the underlying file to the next record. For row-based records in delimited text files, this will skip all empty lines and lines with a leading comment character. This method is here is to serve as a hook for other formats that conceptually also represent tables but aren't formatted as row-based text files. Example : Returns : TRUE if the navigation was successful and FALSE otherwise. Unsuccessful navigation will usually be treated as an end-of-file condition. Args : _parse_header Title : _parse_header Usage : Function: Parse the table header and navigate past it. This method is called if the number of header rows has been specified equal to or greater than one, and positioned at the first header line (row). By default the first header line (row) is used for setting column names, but additional lines (rows) may be skipped too. Empty lines and comment lines do not count as header lines (rows). This method will call _next_record() to navigate to the next header line (row), if there is more than one header line (row). Upon return, the file is presumed to be positioned at the first record after the header. This method is here is to serve as a hook for other formats that conceptually also represent tables but aren't formatted as row-based text files. Note however that the only methods used to access file content or navigate the position are _get_row_values() and _next_record(), so it should usually suffice to override those. Example : Returns : TRUE if navigation past the header was successful and FALSE otherwise. Unsuccessful navigation will usually be treated as an end-of-file condition. Args : _get_row_values Title : _get_row_values Usage : Function: Get the values for the current line (or row) as an array in the order of columns. This method is here is to serve as a hook for other formats that conceptually also represent tables but aren't formatted as row-based text files. Example : Returns : An array of column values for the current row. Args : perl v5.14.2 2012-03-02 Bio::SeqIO::table(3pm)
All times are GMT -4. The time now is 01:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy