Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,037 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,065 people online right now. Registration is fast and FREE... Join Now!




Comparing two tab delimited text files

 
Reply to this topicStart new topic

Comparing two tab delimited text files

utrivedi
post 7 Aug, 2008 - 04:23 AM
Post #1


New D.I.C Head

*
Joined: 7 Aug, 2008
Posts: 1

Hi all,

I am quite new to perl. I have two text files each of which looks something like:

Dmel_mitochondrion 1 A 17 17 0 0 0
Dmel_mitochondrion 2 A 22 22 0 0 0
Dmel_mitochondrion 3 T 29 0 21 0 0
Dmel_mitochondrion 4 G 46 0 0 39 0
Dmel_mitochondrion 5 A 54 53 0 0 0
Dmel_mitochondrion 6 A 63 61 0 0 0
Dmel_mitochondrion 7 T 64 0 47 0 0
Dmel_mitochondrion 8 T 72 0 54 0 0
Dmel_mitochondrion 9 G 82 0 0 73 0
Dmel_mitochondrion 10 C 106 0 0 0 77
Dmel_mitochondrion 11 C 118 0 0 0 93

Now, I want to compare each of it and print columns 1,2, 3 and 4. Further, of the last four columns whichever is showing the highest value needs to be printed out with columns 1,2,3,4 Hence output should look something like:

Dmel_mitochondrion 1 A 17 A 17
Dmel_mitochondrion 2 A 22 T 22
Dmel_mitochondrion 3 T 21 A 23
Dmel_mitochondrion 4 G 39 G 39
Dmel_mitochondrion 5 A 53 C 53

where last two columns come from second file.

This script can make my analysis quite fast. Please help.

Thanks.

Urmi
User is offlineProfile CardPM

Go to the top of the page

Nova Dragoon
post 7 Aug, 2008 - 06:15 AM
Post #2


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 6,128



Thanked 4 times

Dream Kudos: 515

Expert In: Python, Linux

My Contributions


Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: code.gif

Thanks.
User is online!Profile CardPM

Go to the top of the page

KevinADC
post 7 Aug, 2008 - 09:59 AM
Post #3


D.I.C Head

Group Icon
Joined: 23 Jan, 2007
Posts: 212



Thanked 3 times

Dream Kudos: 50
My Contributions


Even if it is no school work, you have to ask a question that other people can understand in order to be able to help you. Your question/requirements are incomprehensible.
User is offlineProfile CardPM

Go to the top of the page

perfectly.insane
post 8 Aug, 2008 - 02:19 AM
Post #4


D.I.C Addict

Group Icon
Joined: 22 Mar, 2008
Posts: 557



Thanked 46 times

Dream Kudos: 25

Expert In: C/C++

My Contributions


Some hints...

The split function will be able to split your lines by any string (or regexp) of your choosing. This should be appropriate for your task.

You could read both of those files and compare them line-by-line, provided that the sequences are always complete (meaning, 1, 2, 3, 4..., not 1, 2, 4, 5, ...). Otherwise, a perl hash might be appropriate.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 05:57AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month