473,378 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

map attributes between three columns and extract common

Hi,

I am running a perl script to retrieve common values in columns at mysql tables. I am mapping three columns for finding same $chr, $start, $end or values within $start and $end. I have attached the text files for two tables earlier. I would be glad to see your positive response.

Regards,
Rocky

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use DBI;
  4. my $user = 'root';
  5. my $password = '1004';
  6.  
  7. # connect to the database
  8. my $dbh = DBI->connect("dbi:mysql:mirvar", $user, $password) || die "Failed connect DB : $!\n";
  9.  
  10. my $sql;
  11. my $sql1;
  12. #my $sql2;
  13.  
  14. $sql = "select * from dbsnp129 limit 10";
  15. $sql1 = "select * from mirna limit 10";
  16.  
  17. # prepare the query
  18.  
  19. my $sth = $dbh->prepare($sql);
  20. my $sth1 = $dbh->prepare($sql1);
  21.  
  22.  
  23. # execute the query with parameter
  24. $sth->execute || die "Error! : $sql\n";
  25. $sth1->execute || die "Error! : $sql1\n";
  26.  
  27. while ( my $line1 = $sth->fetchrow_hashref() ) {
  28.         my $chr = $line1->{'chrom'};
  29.         my $start = $line1->{'chromStart'};
  30.         my $end = $line1->{'chromEnd'};
  31.         my $strand = $line1->{'strand'};
  32.         print "$chr\t$start\t$end\t$strand\n";
  33.         }
  34.         while ( my $line2 = $sth1->fetchrow_hashref() ) {
  35.                 my $chr = $line2->{'chrom'};
  36.                 my $start = $line2->{'chromStart'};
  37.                 my $end = $line2->{'chromEnd'};
  38.                 my $strand = $line2->{'strand'};
  39.                 print "$chr\t$start\t$end\t$strand\n";
  40.         }
  41.  
  42.                 if ( $line2->{'chrom'} == $line1->{'chrom'} && ($line2->{'chromStart'} <= $line1->{'chromStart'} && $line1->{'chromEnd'} <= $line2->{'chromEnd'} )) {
  43.  
  44.                         print "$chr\t$start\t$end\t$start\t$end\n";
  45.         }
  46.  
Aug 19 '11 #1
0 840

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: anon | last post by:
I am trting to simulate the case available in an excel worksheet where the first three columns are frozen and the rest scroll left and right against this. For example: I have a grid which lists...
1
by: Koen Hakvoort | last post by:
Hello, In order to create a message board like this one http://www.prikpagina.nl/read.php?f=18&i=168071&t=168071 I've build a custom treeview with three colums, derived from the asp.net 2.0 ...
16
by: Edward | last post by:
This is a three-column DIV page with a menu bar DIV under them. Easy enough with table layouting but with CSS I can't get it to work: http://tanguay.info/web/examples/threeColumnsColor.htm 1....
2
by: Kaushal Shah | last post by:
Why won't the following code do as expected? Like print Top Three on the top row and bottom three in the bottom row in that order. Thanks for any advice. Kaushal <!DOCTYPE html PUBLIC...
2
by: mil111 | last post by:
Hi, Can anybody help me? I have table1 with 5 columns(first name, last name etc) and table2 with one column. I need to put all of columns from table1 into table2. Into table2 I need to have all...
2
by: shapper | last post by:
Hello, I created a 2 column layout with header and footer: http://www.27lamps.com/public/layout.htm Am I doing this the right way? One problem I have is when giving padding to my col's...
6
by: Arial | last post by:
I have more classes with several common properties. e.g. class A { string Class_A_Prop1{get; set;} string Class_A_Prop2{get; set;} string CommonProp1{get; set;} // common to all classes
36
by: stateemk | last post by:
I have a db with a table that has many columns of info for various entities. In this table, there are three columns called, entity name, second entity name and third entity name. I need to combine...
1
by: kkshansid | last post by:
i want to make a column in mysql table which display sum of three columns.is it possible?how? eg a table with column price1 price2 price3 totalprice after inserting 3 prices total price...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.