Dear Monks,
I have the following problem:
1) I have N tables {minimum 2,maximum -unlimited).
2) Each table could have different numbers of columns and rows (minimum 2 columns).
3) Each table has a column, containing Unique IDs (in my case this is a gene names).

Task:
Merge all tables together, based on Unique ID column.
Here is an example:

Tab 1:
ID column | column 1
gene 1 | value 1.1
gene 2 | value 2.1
gene 4 | value 4.1
gene 8 | value 8.1

Tab 2:
ID column | column 1 | column 2
gene 1 | value 1.1 | value 1.2
gene 3 | value 3.1 | value 3.2
gene 4 | value 4.1 | value 4.2

Resulting Tab:
ID column | column 1 tab1 | column 1 tab2 | column 2 tab 2
gene 1 | value 1.1 | value 1.1 | value 1.2
gene 2 | value 2.1 | n.a. | n.a.
gene 3 | n.a. | value 3.1 | value 3.2
gene 4 | value 4.1 | value 4.1 | value 4.2
gene 8 | value 8.1 | n.a. | n.a.

Algorithm should work for random number of tables.

--------------------------------------------------
Algorithm I
--------------------------------------------------
I have several ideas, how to implement it:

Compare tables one by one:
- load ID columns for each table, load correponding tables.
- compare 2 tables; rearrange tabs, add additional string, corresponding to missing IDs to each table.
- load merged table and new joined ID column
- repeat with the next table.

I can imagine, this algorithm will take ages to run, a lot of memory, and it just does not look nice.
--------------------------------------------------
Algorithm II
--------------------------------------------------
- load all tables to the database. Use ID column as a key for every table.
- join together all IDs, sort, remove dublicates, create new tables with new ID column.
- query every table with each ID from the new table.

This algorithm for me looks better, but as well, it looks like I am using a microscope to hummer the nail.
--------------------------------------------------

So my quesiton are:
- Do you have any suggestions, how to organise such table alignment?
- Maybe there is a perl module available to perform such tas
k? - Any comments about my algorithms?

Best wishes,
Evgeniy

In reply to Merging/Rearranging Tables by homeveg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.