Skip to content

Commit

Permalink
Merge pull request #28 from IHEC/add_nome_seq
Browse files Browse the repository at this point in the history
catch key error in validate semantics
  • Loading branch information
sitag authored May 6, 2019
2 parents 7d23d31 + 33808fa commit 99f7af0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
28 changes: 26 additions & 2 deletions version_metadata/json_spec/ihec_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@
"CHIP_PROTOCOL_CROSSLINK_TIME",
"LIBRARY_GENERATION_FRAGMENT_SIZE_RANGE"
],


"chip-seq_input": [
"EXPERIMENT_TYPE",
"EXPERIMENT_ONTOLOGY_URI",
"LIBRARY_STRATEGY",
"MOLECULE_ONTOLOGY_URI",
"MOLECULE",
"EXTRACTION_PROTOCOL",
"EXTRACTION_PROTOCOL_TYPE_OF_SONICATOR",
"EXTRACTION_PROTOCOL_SONICATION_CYCLES",
"CHIP_PROTOCOL",
"CHIP_PROTOCOL_CHROMATIN_AMOUNT"
],


"chromatin_accessibility": [
"EXPERIMENT_TYPE",
"EXPERIMENT_ONTOLOGY_URI",
Expand Down Expand Up @@ -265,5 +281,13 @@
"LIBRARY_GENERATION_PCR_R_PRIMER_SEQUENCE",
"LIBRARY_GENERATION_PCR_PRIMER_CONC",
"LIBRARY_GENERATION_PCR_PRODUCT_ISOLATION_PROTOCOL"
]
}
],

"patches" : {
"RNA_PREPARATION_3'_RNA_ADAPTER_LIGATION_PROTOCOL" : "RNA_PREPARATION_3'_RNA ADAPTER_LIGATION_PROTOCOL",
"EXTRACTION_PROTOCOL_RNA_ENRICHMENT": "EXTRACTION_PROTOCOL_MRNA_ENRICHMENT",
"RNA_PREPARATION_FRAGMENT_SIZE_RANGE": "MRNA_PREPARATION_FRAGMENT_SIZE_RANGE",
"PREPARATION_INITIAL_RNA_QNTY": "PREPARATION_INITIAL_MRNA_QNTY"
}

}
15 changes: 12 additions & 3 deletions version_metadata/review.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
from utils import json2, cmn
import config
import sraparse
import os

def objtype(e):
if 'BIOMATERIAL_TYPE' in e['attributes']:
return cmn.demanduniq(e['attributes']['BIOMATERIAL_TYPE']).lower().replace(' ', '_')
elif 'EXPERIMENT_TYPE' in e['attributes']:
return cmn.demanduniq(e['attributes']['EXPERIMENT_TYPE']).lower().replace(' ', '_')
et = cmn.demanduniq(e['attributes']['EXPERIMENT_TYPE']).lower().replace(' ', '_')
if et.startswith('histone'):
et = 'chip-seq'
elif et.find('input') != -1:
et = 'chip-seq_input'
return et
else:
return None
def main(args):
#assert args.has('-sample')
xmls = args.args()
ihec = json2.loadf('./json_spec/ihec_spec.json')
schome = os.path.dirname(os.path.realpath(__file__))
ihec = json2.loadf('{0}/json_spec/ihec_spec.json'.format(schome))
if args.has('-isxml'):
loader = lambda x: sraparse.SRAParseObjSet.from_file(x).attributes()
else:
loader = lambda x: json2.loadf(x)

patches = ihec["patches"]
for arg in xmls:
db = loader(arg)
for e in db:
Expand All @@ -26,7 +34,8 @@ def main(args):
required = ihec.get(ot, None)
if required:
missing = [x for x in required if not x in e['attributes']]
print alias, missing, ot
missing2 = [x for x in missing if not patches.get(x, '-') in e['attributes']]
print alias, ot, missing2, 'XXXX', missing
else:
print alias, '__unknown_object_type__', ot

Expand Down
19 changes: 11 additions & 8 deletions version_metadata/validate_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ def validate_semantics_stub(self, attrs):
return True

def validate_semantics(self, attrs):
attributes = attrs['attributes']
miRNA_experiment_type = attributes['experiment_type'] in ['smRNA-Seq'] # abstract all this using a Rule interface... another day
miRNA_strategy = attributes['library_strategy'] in ['miRNA-Seq']
validation_status = miRNA_strategy if miRNA_experiment_type else not miRNA_strategy
if not validation_status:
logger.warn('#warn: __semantic_validation_failed__: smRNA-Seq library strategy if and only if miRNA-Seq experiment type\n')
return validation_status

try:
attributes = attrs['attributes']
miRNA_experiment_type = attributes['experiment_type'] in ['smRNA-Seq'] # abstract all this using a Rule interface... another day
miRNA_strategy = attributes['library_strategy'] in ['miRNA-Seq']
validation_status = miRNA_strategy if miRNA_experiment_type else not miRNA_strategy
if not validation_status:
logger.warn('#warn: __semantic_validation_failed__: smRNA-Seq library strategy if and only if miRNA-Seq experiment type\n')
return validation_status
except KeyError as e:
logger.warn('#warn keyerror in validate_semantics, probably is not even syntactically valid\n')
return False

# to do: refactor this code along with validate_sample into one module
def main(args):
Expand Down

0 comments on commit 99f7af0

Please sign in to comment.