Skip to content

Instantly share code, notes, and snippets.

@jasonsahl
Created March 29, 2021 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonsahl/b950e350fa67910bf5916dd2ecd460c3 to your computer and use it in GitHub Desktop.
Save jasonsahl/b950e350fa67910bf5916dd2ecd460c3 to your computer and use it in GitHub Desktop.
transpose a BSR matrix
#!/usr/bin/env python
import sys
from sys import argv
try:
out_matrix = open("transposed_matrix.matrix", "w")
reduced = []
with open(argv[1]) as my_file:
for line in my_file:
newline=line.strip("\n")
fields = newline.split("\t")
reduced.append(fields)
test=map(list, zip(*reduced))
for x in test:
out_matrix.write("\t".join(x)+"\n")
out_matrix.close()
except:
print("usage: script bsr_matrix.txt")
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment