Created
October 25, 2017 14:47
-
-
Save mwatts15/bed123ca92e22db479a7fec401a65acb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
class WormbaseIonChannelCSVTranslator(DataTranslator): | |
input_type = WormbaseIonChannelCSVDataSource | |
output_type = DataObjectContextDataSource | |
def translate(self, data_source): | |
res = set([]) | |
try: | |
with open(data_source.csv_file_name, 'r') as csvfile: | |
next(csvfile, None) | |
csvreader = csv.reader(csvfile, skipinitialspace=True) | |
for line in csvreader: | |
channel_name = normalize_cell_name(line[0]).upper() | |
gene_name = line[1].upper() | |
gene_WB_ID = line[2].upper() | |
expression_pattern = line[3] | |
description = line[4] | |
c = Channel(name=str(channel_name)) | |
c.gene_name(gene_name) | |
c.gene_WB_ID(gene_WB_ID) | |
c.description(description) | |
patterns = expression_pattern.split(r' | ') | |
regex = re.compile(r' *\[([^\]]+)\] *(.*) *') | |
matches = [regex.match(pat) for pat in patterns] | |
patterns = [ExpressionPattern(wormbaseID=m.group(1), | |
description=m.group(2)) | |
for m in matches if m is not None] | |
for pat in patterns: | |
c.expression_pattern(pat) | |
res.add(c) | |
except Exception: | |
traceback.print_exc() | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment