Sponsored Content
Full Discussion: Perl- matrix problem
Top Forums Shell Programming and Scripting Perl- matrix problem Post 302288347 by pludi on Tuesday 17th of February 2009 03:33:57 AM
Old 02-17-2009
Next time please use [code ][/code ] tags for pre-formatted text (output/code/...)
Code:
#!/usr/bin/perl -W

use strict;
use warnings;

my ( $FH, %data, @temp, $i, $line, @header );

$line = <DATA>;
chomp $line;
@header = split /\t/, $line;
while ( $line = <DATA> ) {
    chomp $line;
    @temp = split /\t/, $line;
    $data{ $temp[0] } = {};
    for ( $i = 1 ; $i <= $#temp ; $i++ ) {
        $data{ $temp[0] }{ $header[$i] } = $temp[$i];
    }
}

print $data{'A'}{'A'}, "\n";
print $data{'T'}{'G'}, "\n";

__DATA__
        A       C       G       T       -
A       5       -4      -4      -4      -5
C       -4      5       -4      -4      -5
G       -4      -4      5       -4      -5
T       -4      -4      -4      5       -5
-       -5      -5      -5      -5      0

I'm using an inline file here, so you'll have to adapt it if you want the file from the command line or where ever. First key of %data is the row, second is the column.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PERL: How do I get both sizes of a matrix?

Hi everybody, I have a matrix called @matrix dinamically built in PERL, so I don't know its exact sizes. It is a 2-dimensional matrix, so its elements are for example: $matrix $matrix $matrix $matrix $matrix etc... I know i can get the number of the rows of the matrix with the... (2 Replies)
Discussion started by: foo.bar
2 Replies

2. Shell Programming and Scripting

PERL: How do i print an associative matrix?

Hello guys, I have in PERL an associative 2-dimensional array, called matrix. The array (actually the matrix) is made up like this matrix = x; matrix = y; matrix = w; matrix = z; ... but the names a, b, c, d are set just at runtime. The question is: how can i get all the keys of... (2 Replies)
Discussion started by: foo.bar
2 Replies

3. Shell Programming and Scripting

awk matrix problem

hi there I'm very new in programing and i've started with awk. I'm processing 200 data files and I need to do some precessing on them. The files have 3 columns with N-lines for each line a have on the first and second value is the same for all the files and only the third is variable. like... (2 Replies)
Discussion started by: philstar
2 Replies

4. Shell Programming and Scripting

Invert Matrix of Data - Perl

I have columnar data in arrays perl, Example - @a = (1,2,3); @array1 = (A,B,C); @array2 = (D,E,F); @array3 = (I,R,T); I want the data to be formatted and printed as 1 A D I 2 B E F 3 C F T and so on... (8 Replies)
Discussion started by: dinjo_jo
8 Replies

5. 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

6. Programming

Matrix addition - Perl - PDL

Hi All, I have a question. I need to add 3 matrices of size 2000 x 2000. (i.e) 2000 rows and 2000 columns using Perl::PDL module. I used the following perl script #!/usr/bin/perl -w use strict; use warnings; use PDL; use PDL::Matrix; if ( @ARGV != 3 ) { die 'Two matrix files are... (1 Reply)
Discussion started by: Fredrick
1 Replies

7. 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

8. Shell Programming and Scripting

Randomization a matrix - perl / Shell

Hello all, I have a tricky question! (at least for me it is!). I'll try to explain it carefully here. Hope you can help me solving the whole or even parts of it! Here it is: I have a big input 0\1 table as a very simplified one is shown below: (The last row and column are the sum and... (0 Replies)
Discussion started by: @man
0 Replies

9. Shell Programming and Scripting

Make Separated files from a single matrix - Perl

Hey Masters, Here is my input: fragmentID chromosome start end HEL25E TRIP1 r5GATC2L00037 chr2L 5301 6026 0.03 0.036 r5GATC2L00038 chr2L 6023 6882 -0.025 -0.041 r5GATC2L00040 chr2R 6921 7695 -0.031 0.005 r5GATC2L00042 chr2R 7715 8554 -0.006 -0.024 r5GATC2L00043 chr3L 8551 8798 0.042 0... (4 Replies)
Discussion started by: @man
4 Replies
MAXDB_STMT_ERRNO(3)							 1						       MAXDB_STMT_ERRNO(3)

maxdb_stmt_errno - Returns the error code for the most recent statement call

       Procedural style

SYNOPSIS
int maxdb_stmt_errno (resource $stmt) DESCRIPTION
Object oriented style int$maxdb_stmt->errno () For the statement specified by stmt, maxdb_stmt_errno(3) returns the error code for the most recently invoked statement function that can succeed or fail. Note For possible error codes see documentation of SQLDBC: http://maxdb.sap.com/documentation/. RETURN VALUES
An error code value. Zero means no error occurred. EXAMPLES
Example #1 Object oriented style <?php /* Open a connection */ $maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } $maxdb->query("CREATE TABLE temp.mycity LIKE hotel.city"); $maxdb->query("INSERT INTO temp.mycity SELECT * FROM hotel.city"); $query = "SELECT name, zip FROM temp.mycity ORDER BY name"; if ($stmt = $maxdb->prepare($query)) { /* drop table */ $maxdb->query("DROP TABLE temp.mycity"); /* execute query */ $stmt->execute(); printf("Error: %d. ", $stmt->errno); /* close statement */ $stmt->close(); } /* close connection */ $maxdb->close(); ?> Example #2 Procedural style <?php /* Open a connection */ $link = maxdb_connect("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } maxdb_query($link, "CREATE TABLE temp.mycity LIKE hotel.city"); maxdb_query($link, "INSERT INTO temp.mycity SELECT * FROM hotel.city"); $query = "SELECT name, zip FROM temp.mycity ORDER BY name"; if ($stmt = maxdb_prepare($link, $query)) { /* drop table */ maxdb_query($link, "DROP TABLE temp.mycity"); /* execute query */ maxdb_stmt_execute($stmt); printf("Error: %d. ", maxdb_stmt_errno($stmt)); /* close statement */ maxdb_stmt_close($stmt); } /* close connection */ maxdb_close($link); ?> The above example will output something similar to: Warning: maxdb_stmt_execute(): -4004 POS(23) Unknown table name:MYCITY [42000] <...> Error: -4004. SEE ALSO
maxdb_stmt_error(3), maxdb_stmt_sqlstate(3). PHP Documentation Group MAXDB_STMT_ERRNO(3)
All times are GMT -4. The time now is 05:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy