Sponsored Content
Full Discussion: column to matrix
Top Forums Shell Programming and Scripting column to matrix Post 302702429 by Fredrick on Tuesday 18th of September 2012 10:06:37 AM
Old 09-18-2012
Hi Rudi,

Thanks for your reply. I just tried with only two columns (for testing). here is the input:

Code:
 
    1  2
     2  3
     3  3
     4  3
     5  3
     6  3
     7  2
     8  3
     9  3
    10  3
    11  2
    12  2
    13  3
    14  2
    15  2
    16  2
    17  2
    18  2
    19  2
    20  2
    21  2
    22  2
    23  7
    24  2
    25  3
    26  3
    27  2
    28  2
    29  2
    30  2
    31  2
    32  2
    33  3
    34  2

and I got the following output

Code:
        4       5       6       7       8       9       0       1       2       3
780     0       0       0       0       0       1       0       0       0       0
781     0       0       0       0       0       0       0       1       0       0
740     0       0       0       0       0       0       0       1       0       0
782     0       0       0       0       0       0       0       1       0       0
741     0       0       0       0       0       0       0       0       0       1
700     0       0       0       0       0       0       0       1       0       0
80      0       0       0       0       0       0       0       0       1       0
783     0       0       0       0       0       1       0       0       0       0
742     0       0       0       0       0       0       0       0       0       1
701     0       0       0       0       0       1       0       0       0       0
81      0       0       0       0       0       0       0       0       1       0
40      0       0       0       0       0       0       0       0       0       1
784     0       0       0       0       0       0       0       1       0       0
743     0       0       0       0       0       0       0       1       0       0
702     0       0       0       0       0       0       0       0       0       1
82      0       0       0       0       0       0       0       0       1       0
41      0       0       0       0       0       0       0       0       0       1
785     0       0       0       0       0       1       0       0       0       0

In the output, row numbers are not in an order, as well as column numbers.

Warm regards
Fredrick.

Warm regards
Fredrick.

Last edited by Franklin52; 09-18-2012 at 11:18 AM.. Reason: fixed code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

processing matrix column wise

I have a m X n matrix written out to file, say like this: 1,2,3,4,5,6 2,6,3,10,34,67 1,45,6,7,8,8 I want to calculate the column averages in the MINIMUM amount of code or processing possible. I would have liked to use my favorite tool, "AWK" but since it processes rowwise, getting the... (5 Replies)
Discussion started by: Abhishek Ghose
5 Replies

2. Shell Programming and Scripting

diagonal matrix to square matrix

Hello, all! I am struggling with a short script to read a diagonal matrix for later retrieval. 1.000 0.234 0.435 0.123 0.012 0.102 0.325 0.412 0.087 0.098 1.000 0.111 0.412 0.115 0.058 0.091 0.190 0.045 0.058 1.000 0.205 0.542 0.335 0.054 0.117 0.203 0.125 1.000 0.587 0.159 0.357... (11 Replies)
Discussion started by: yifangt
11 Replies

3. Shell Programming and Scripting

two-column data to matrix in AWK

Howdy, I need to convert an association data matrix, currently in a two-column format, into a matrix with numbers indicating the number of associations. I've been looking around for AWK code in the list, but could not find anything. Here's an example of what I want to perform: original... (10 Replies)
Discussion started by: sramirez
10 Replies

4. Shell Programming and Scripting

Extracting columns from a matrix and storing each column in a separate file

Hi All, I have a huge matrix file consisting some some millions rows and 6000 columns. The contents are just floating point numbers in the matrix. I want to extract each column (i.e. 6000 of them) and store each column in a separate file. For example, 1.dat will consist of elements from column... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

5. Ubuntu

How to convert full data matrix to linearised left data matrix?

Hi all, Is there a way to convert full data matrix to linearised left data matrix? e.g full data matrix Bh1 Bh2 Bh3 Bh4 Bh5 Bh6 Bh7 Bh1 0 0.241058 0.236129 0.244397 0.237479 0.240767 0.245245 Bh2 0.241058 0 0.240594 0.241931 0.241975 ... (8 Replies)
Discussion started by: evoll
8 Replies

6. Shell Programming and Scripting

3 column .csv --> correlation matrix; awk, perl?

Greetings, salutations. I have a 3 column csv file with ~13 million rows and I would like to generate a correlation matrix. Interestingly, you all previously provided a solution to the inverse of this problem. Thread title: "awk? adjacency matrix to adjacency list / correlation matrix to list"... (6 Replies)
Discussion started by: R3353
6 Replies

7. Shell Programming and Scripting

Adding or substracting from a Matrix column

Hello! I'm new to linux programming. It would be great if you could help me out. I have a matrix of kind: 10 30.0 20 190.5 40 180. 50 320.5 I would like to substract 180 from column 2 If the value is >180 to add 180 for column 2 If the value is <180 nothing if it is equal to... (3 Replies)
Discussion started by: lovelinux
3 Replies

8. Shell Programming and Scripting

Perl- creating a matrix from a 3 column file

Dear all, I'm new in perl scripting and I'm trying to creating a matrix from a 3 column file sorting data in a particular manner. In the final matrix I need to have the first column "IDs" on the header of the columns and the second column values on the header of each row. And the value fo the... (2 Replies)
Discussion started by: gabrysfe
2 Replies

9. Shell Programming and Scripting

Convert a 3 column tab delimited file to a matrix

Hi all, I have a 3 columns input file like this: CPLX9PC-4943 CPLX9PC-4943 1 CPLX9PC-4943 CpxID123 0 CPLX9PC-4943 CpxID126 0 CPLX9PC-4943 CPLX9PC-5763 0.5 CPLX9PC-4943 CpxID13 0 CPLX9PC-4943 CPLX9PC-6163 0 CPLX9PC-4943 CPLX9PC-6164 0.04... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

10. Shell Programming and Scripting

Transpose matrix based on second column using awk

Hi, Is it possible to transpose the matrix like this using awk ? Many thanks in advance Input abc Name_1 0 abc Name_2 1 abc Name_3 2 abc Name_4 0.4 def Name_1 0 def Name_2 9 def Name_3 78 def Name_4 1 Output abc def Name_1 0 ... (4 Replies)
Discussion started by: quincyjones
4 Replies
Bio::Matrix::Generic(3pm)				User Contributed Perl Documentation				 Bio::Matrix::Generic(3pm)

NAME
Bio::Matrix::Generic - A generic matrix implementation SYNOPSIS
# A matrix has columns and rows my $matrix = Bio::Matrix::Generic->new; $matrix->add_column(1,$column1); $matrix->add_column(2,$column2); my $element = $matrix->entry_by_num(1,2); $matrix->entry_by_num(1,2,$newval); my $entry = $matrix->entry('human', 'mouse'); $matrix->entry('human','mouse', $newval); DESCRIPTION
This is a general purpose matrix object for dealing with row+column data which is typical when enumerating all the pairwise combinations and desiring to get slices of the data. Data can be accessed by column and row names or indexes. Matrix indexes start at 0. 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: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Jason Stajich Email jason-at-bioperl-dot-org APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ new Title : new Usage : my $obj = Bio::Matrix::Generic->new(); Function: Builds a new Bio::Matrix::Generic object Returns : an instance of Bio::Matrix::Generic Args : -values => arrayref of arrayrefs of data initialization -rownames => arrayref of row names -colnames => arrayref of col names -matrix_id => id of the matrix -matrix_name=> name of the matrix -matrix_init_value => default value to initialize empty cells matrix_id Title : matrix_id Usage : my $id = $matrix->matrix_id Function: Get/Set the matrix ID Returns : scalar value Args : [optional] new id value to store matrix_name Title : matrix_name Usage : my $name = $matrix->matrix_name(); Function: Get/Set the matrix name Returns : scalar value Args : [optional] new matrix name value entry Title : entry Usage : my $entry = $matrix->entry($row,$col) Function: Get the value for a specific cell as specified by the row and column names Returns : scalar value or undef if row or col does not exist Args : $rowname - name of the row $colname - column name get_entry Title : get_entry Usage : my $entry = $matrix->get_entry($rowname,$columname) Function: Get the entry for a given row,column pair Returns : scalar Args : $row name $column name entry_by_num Title : entry_by_num Usage : my $entry = $matrix->entry_by_num($rownum,$colnum) Function: Get an entry by row and column numbers instead of by name (rows and columns start at 0) Returns : scalar value or undef if row or column name does not exist Args : $row - row number $col - column number [optional] $newvalue to store at this cell column Title : column Usage : my @col = $matrix->column('ALPHA'); OR $matrix->column('ALPHA', @col); Function: Get/Set a particular column Returns : Array (in array context) or arrayref (in scalar context) of values. For setting will warn if the new column is of a different length from the rest of the columns. Args : name of the column [optional] new column to store here get_column Title : get_column Usage : my @row = $matrix->get_column('ALPHA'); Function: Get a particular column Returns : Array (in array context) or arrayref (in scalar context) of values Args : name of the column column_by_num Title : column_by_num Usage : my @col = $matrix->column_by_num(1); OR $matrix->column_by_num(1,@newcol); Function: Get/Set a column by its number instead of name (cols/rows start at 0) Returns : Array (in array context) or arrayref (in scalar context) of values Args : name of the column [optional] new value to store for a particular column row Title : row Usage : my @row = $matrix->row($rowname); OR $matrix->row($rowname,@rowvalues); Function: Get/Set the row of the matrix Returns : Array (in array context) or arrayref (in scalar context) Args : rowname [optional] new value of row to store get_row Title : get_row Usage : my @row = $matrix->get_row('ALPHA'); Function: Get a particular row Returns : Array (in array context) or arrayref (in scalar context) of values Args : name of the row row_by_num Title : row_by_num Usage : my @row = $matrix->row_by_num($rownum); OR $matrix->row($rownum,@rowvalues); Function: Get/Set the row of the matrix Returns : Array (in array context) or arrayref (in scalar context) Args : rowname [optional] new value of row to store diagonal Title : diagonal Usage : my @diagonal = $matrix->get_diagonal() Function: Get the diagonal of a matrix Returns : Array (in array context) or arrayref (in scalar context) of values which lie along the diagonal Args : none add_row Title : add_row Usage : $matrix->add_row($index,@newrow); Function: Adds a row at particular location in the matrix. If $index < the rowcount will shift all the rows down by the number of new rows. To add a single empty row, simply call $matrix->add_row($index,undef); Returns : the updated number of total rows in the matrix Args : index to store name of the row (header) newrow to add, if this is undef will add a single row with all values set to undef remove_row Title : remove_row Usage : $matrix->remove_row($colnum) Function: remove a row from the matrix shifting all the rows up by one Returns : Updated number of rows in the matrix Args : row index add_column Title : add_column Usage : $matrix->add_column($index,$colname,@newcol); Function: Adds a column at particular location in the matrix. If $index < the colcount will shift all the columns right by the number of new columns. To add a single empty column, simply call $matrix->add_column($index,undef); Returns : the updated number of total columns in the matrix Args : index to store name of the column (header) newcolumn to add, if this is undef will add a single column with all values set to undef remove_column Title : remove_column Usage : $matrix->remove_column($colnum) Function: remove a column from the matrix shifting all the columns to the left by one Returns : Updated number of columns in the matrix Args : column index column_num_for_name Title : column_num_for_name Usage : my $num = $matrix->column_num_for_name($name) Function: Gets the column number for a particular column name Returns : integer Args : string row_num_for_name Title : row_num_for_name Usage : my $num = $matrix->row_num_for_name Function: Gets the row number for a particular row name Returns : integer Args : string column_header Title : column_header Usage : my $name = $matrix->column_header(0) Function: Gets the column header for a particular column number Returns : string Args : integer row_header Title : row_header Usage : my $name = $matrix->row_header(0) Function: Gets the row header for a particular row number Returns : string Args : integer num_rows Title : num_rows Usage : my $rowcount = $matrix->num_rows; Function: Get the number of rows Returns : integer Args : none num_columns Title : num_columns Usage : my $colcount = $matrix->num_columns Function: Get the number of columns Returns : integer Args : none row_names Title : row_names Usage : my @rows = $matrix->row_names Function: The names of all the rows Returns : array in array context, arrayref in scalar context Args : none column_names Title : column_names Usage : my @columns = $matrix->column_names Function: The names of all the columns Returns : array in array context, arrayref in scalar context Args : none private methods Private methods for a Generic Matrix _values Title : _values Usage : $matrix->_values(); Function: get/set for array ref of the matrix containing distance values Returns : an array reference Args : an array reference perl v5.14.2 2012-03-02 Bio::Matrix::Generic(3pm)
All times are GMT -4. The time now is 11:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy