annotate modify_loom.py @ 8:e98619de2776 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit 656ce7ff596a8870b77848469e85b406c7bd9344
author iuc
date Sun, 12 Nov 2023 16:44:29 +0000
parents c8e4d0b9ae8c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
1 #!/usr/bin/env python
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
2 """This program adds layers, row attributes or column attributes for loom files"""
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
3
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
4 import argparse
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
5
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
6 import loompy
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
7 import numpy as np
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
8
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
9 parser = argparse.ArgumentParser(description="Loompy file converter flags")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
10 parser.add_argument('--VERSION', action='version', version='%(prog)s 0.1.0',
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
11 help="Displays tool version")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
12 parser.add_argument('--file', '-f',
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
13 help="Loom file to which data will be added")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
14 parser.add_argument('--rowfile', '-r', help="File of row attributes & values")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
15 parser.add_argument('--colfile', '-c',
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
16 help="File of column attributes and values")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
17 parser.add_argument('--layers', '-l', nargs='*',
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
18 help="Input tsv files. First file becomes main layer.")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
19 parser.add_argument('--add', '-a', choices=["rows", "cols", "layers"],
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
20 help="Selects rows, columns or layers to be added to file")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
21 args = parser.parse_args()
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
22
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
23 lfile = args.file
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
24 if args.rowfile:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
25 rowfile = args.rowfile
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
26 if args.colfile:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
27 colfile = args.colfile
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
28 if args.layers:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
29 alllayers = args.layers
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
30 addselect = args.add
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
31 # Check proper flags for chosen attributes are being added
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
32 if addselect == "cols" and not args.colfile:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
33 raise Exception("To add column attributes, column flag and file must be provided")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
34 if addselect == "rows" and not args.rowfile:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
35 raise Exception("To add row attributes, row flag and file must be provided")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
36 if addselect == "layers" and not args.layers:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
37 raise Exception("To add layers, a layer flag and file(s) must be provided")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
38
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
39 layernames = []
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
40 rowdict = {}
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
41 coldict = {}
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
42
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
43 with loompy.connect(lfile) as loomfile:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
44 # Loom file dimensions
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
45 nrow = loomfile.shape[0]
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
46 ncol = loomfile.shape[1]
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
47 if addselect == "layers":
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
48 layernames = []
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
49 # Generate layer names based on file names
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
50 for x in range(0, len(alllayers)):
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
51 layer = alllayers[x]
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
52 layer = layer.split("/")[-1].split(".")[-2] # Takes away path, takes off extension
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
53 layernames.append(layer)
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
54 # Add in the layers themselves
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
55 for layer in range(0, len(alllayers)):
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
56 matrix = ""
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
57 with open(alllayers[layer], "r") as infile:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
58 rows = 0
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
59 count = 0
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
60 for line in infile:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
61 if count == 0:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
62 cols = len(line.split("\t"))
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
63 if cols != ncol:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
64 raise Exception("Dimensions of new matrix incorrect for this loom file. New matrices must be %d by %d" % (nrow, ncol))
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
65 matrix = matrix + line + "\t"
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
66 rows += 1
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
67 if rows != nrow:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
68 raise Exception("Dimensions of new matrix incorrect for this loom file. New matrices must be %d by %d")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
69 matrix = matrix.split("\t")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
70 matrix = [float(n) for n in matrix[:-1]]
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
71 matrix = np.asarray(matrix).reshape(nrow, ncol)
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
72 loomfile[layernames[layer]] = matrix
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
73 elif addselect == "rows":
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
74 with open(rowfile, "r") as rows:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
75 count = 0
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
76 for line in rows:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
77 line = line.strip().split("\t")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
78 if count == 0: # First time through
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
79 row_attributes = line
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
80 for x in row_attributes:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
81 rowdict[x] = []
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
82 count += 1
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
83 else:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
84 for x in range(0, len(line)):
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
85 rowdict[row_attributes[x]].append(line[x])
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
86 for x in row_attributes:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
87 if len(rowdict[x]) != nrow:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
88 raise Exception("Incorrect length of row. Row length must be: %d" % nrow)
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
89 loomfile.ra[x] = rowdict[x]
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
90 elif addselect == "cols":
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
91 with open(colfile, "r") as cols:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
92 count = 0
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
93 for line in cols:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
94 line = line.replace('\"', "")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
95 line = line.replace(' ', "")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
96 line = line.strip().split("\t")
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
97 if count == 0: # First time through
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
98 col_attributes = line
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
99 for x in col_attributes:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
100 coldict[x] = []
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
101 count += 1
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
102 else:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
103 for x in range(0, len(line)):
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
104 coldict[col_attributes[x]].append(line[x])
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
105 for y in col_attributes:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
106 if len(coldict[y]) != ncol:
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
107 raise Exception("Incorrect length of column. Column length must be: %d" % ncol)
c8e4d0b9ae8c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit dc9d19d1f902f3ed54009cd0e68c8518c284b856"
iuc
parents:
diff changeset
108 loomfile.ca[y] = coldict[y]