Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Include matrix conversion for R #2

Open
seanmcallister opened this issue Aug 9, 2017 · 2 comments
Open

Include matrix conversion for R #2

seanmcallister opened this issue Aug 9, 2017 · 2 comments

Comments

@seanmcallister
Copy link
Contributor

Please consider packaging the "seanie_matrix_convert.rb" with this repository so people can convert the output to a pairwise matrix for visualization in R.

@mooreryan
Copy link
Owner

@seanmcallister Do you have a copy of that script?

@seanmcallister
Copy link
Contributor Author

Here you go. If you include, I would change 2 things for use in R:

  1. Output the self comparisons as 100 instead of 0.
  2. For this aai, there are two matrices that would be useful. One for the one way hits (A->B on upper triangle, B->A on lower triangle), and one for the two way hits (output both upper and lower triangles of the matrix instead of leaving the lower triangle as 0's; the upper triangle in this case would be identical to the lower triangle).
# take 3 col dist matrix and spit out a dist matrix for R

dists = {}
all = []
File.open(ARGV.first).each_line.with_index do |line, lineno|
  unless lineno.zero?
    row, col, dist = line.chomp.split "\t"
    dist = dist.to_f

    all << row << col

    unless dists.has_key? row
      dists[row] = Hash.new 0
    end

    dists[row][col] = dist
  end
end

all = all.uniq.sort

puts ["", all].flatten.join "\t"

all.each_with_index do |row, ridx|
  row_name = all[ridx]
  print row_name

  all.each do |col|
    dist = 0
    dist = dists[row][col] if dists.has_key?(row)

    printf "\t%s", dist
  end

  puts
end

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants