77PREREQUISITES
88Must have python 3.6 or higher.
99"""
10+ import collections
11+ import ntpath
1012from collections import defaultdict
11- from typing import Dict , Generator , List , Tuple , Union # noqa: F401
1213from dataclasses import dataclass
13- from mypy_extensions import TypedDict
14+ from typing import Dict , Generator , List , Tuple , Union # noqa: F401
15+
1416from bson .objectid import ObjectId
15- import ntpath
16- import collections
17+ from mypy_extensions import TypedDict
1718
1819try :
1920 # Used when importing internally and in tests
@@ -35,7 +36,7 @@ def __init__(
3536 study_id : ObjectId ,
3637 study_file_id : ObjectId ,
3738 * args ,
38- ** kwargs
39+ ** kwargs ,
3940 ):
4041
4142 self .study_accession = kwargs .pop ("study_accession" )
@@ -60,6 +61,33 @@ class Model(TypedDict):
6061 # unique values from "group" type annotations
6162 values : List
6263
64+ # Will evolve to do cross file validation
65+ def validate (self ):
66+ """ Runs all validation checks
67+ """
68+ return all ([self .is_valid_format ()])
69+
70+ def is_valid_format (self ):
71+ """Validates format by calling all format validation methods"""
72+ return all (
73+ [self .validate_header_for_coordinate_values (), self .validate_format ()]
74+ )
75+
76+ def validate_header_for_coordinate_values (self ):
77+ """Cell metadata files should not have coordinates in header
78+ :return: boolean True if coordinates are not in header, otherwise False
79+ """
80+ lower_cased_headers = [header .lower () for header in self .headers ]
81+ valid = not any (
82+ [coordinate in ('x' , 'y' , 'z' ) for coordinate in lower_cased_headers ]
83+ )
84+ if valid :
85+ return True
86+ else :
87+ msg = 'Header names can not be coordinate values x, y, or z (case insensitive)'
88+ self .store_validation_issue ('error' , 'format' , msg )
89+ return False
90+
6391 def transform (self ):
6492 """ Builds cell metadata model"""
6593 AnnotationModel = collections .namedtuple (
0 commit comments