Commit b430221b authored by Jeff Thiessen's avatar Jeff Thiessen

removed RC from files with dos2unix

parent 1bfef7ac
Pipeline #6957 passed with stage
in 8 minutes and 43 seconds
This diff is collapsed.
class ProjectError(Exception):
pass
class ProjectError(Exception):
pass
class SampleError(Exception):
"""An exception to be raised when issues with samples arise.
Examples include when IRIDA responds with an error during sample creation,
or when the parsing component can't parse the sample section of the sample
sheet.
"""
def __init__(self, message, errors):
"""Initialize a SampleError.
Args:
message: the summary message that's causing the error.
errors: a more detailed list of errors.
"""
self._message = message
self._errors = errors
@property
def message(self):
return self._message
@property
def errors(self):
return self._errors
def __str__(self):
return self.message
class SampleError(Exception):
"""An exception to be raised when issues with samples arise.
Examples include when IRIDA responds with an error during sample creation,
or when the parsing component can't parse the sample section of the sample
sheet.
"""
def __init__(self, message, errors):
"""Initialize a SampleError.
Args:
message: the summary message that's causing the error.
errors: a more detailed list of errors.
"""
self._message = message
self._errors = errors
@property
def message(self):
return self._message
@property
def errors(self):
return self._errors
def __str__(self):
return self.message
class SampleSheetError(Exception):
"""An exception raised when errors are encountered with a sample sheet.
Examples include when a sample sheet can't be parsed because it's garbled, or
if IRIDA rejects the creation of a run because fields are missing or invalid
from the sample sheet.
"""
def __init__(self, message, errors):
"""Initalize a SampleSheetError.
Args:
message: a summary message that's causing the error.
errors: a more detailed list of errors.
"""
self._message = message
self._errors = errors
@property
def message(self):
return self._message
@property
def errors(self):
return self._errors
def __str__(self):
return self.message
class SampleSheetError(Exception):
"""An exception raised when errors are encountered with a sample sheet.
Examples include when a sample sheet can't be parsed because it's garbled, or
if IRIDA rejects the creation of a run because fields are missing or invalid
from the sample sheet.
"""
def __init__(self, message, errors):
"""Initalize a SampleSheetError.
Args:
message: a summary message that's causing the error.
errors: a more detailed list of errors.
"""
self._message = message
self._errors = errors
@property
def message(self):
return self._message
@property
def errors(self):
return self._errors
def __str__(self):
return self.message
class SequenceFileError(Exception):
"""An exception that's raised when errors are encountered with a sequence file.
Examples include when files cannot be found for samples that are in the sample
sheet, or when the server rejects a file during upload.
"""
def __init__(self, message, errors):
"""Initialize a SequenceFileError.
Args:
message: a summary message of the error.
errors: a more detailed list of errors.
"""
self._message = message
self._errors = errors
@property
def message(self):
return self._message
@property
def errors(self):
return self._errors
def __str__(self):
return self.message
class SequenceFileError(Exception):
"""An exception that's raised when errors are encountered with a sequence file.
Examples include when files cannot be found for samples that are in the sample
sheet, or when the server rejects a file during upload.
"""
def __init__(self, message, errors):
"""Initialize a SequenceFileError.
Args:
message: a summary message of the error.
errors: a more detailed list of errors.
"""
self._message = message
self._errors = errors
@property
def message(self):
return self._message
@property
def errors(self):
return self._errors
def __str__(self):
return self.message
class Project:
# project_id is optional because it's not necessary when creating a Project
# object to send.
def __init__(self, proj_name, proj_description=None, proj_id=None):
# proj_id is the identifier key when getting projects from the API.
self.project_name = proj_name
self.project_description = str(proj_description)
self.project_id = str(proj_id)
def get_id(self):
return self.project_id
def get_name(self):
return self.project_name
def get_description(self):
return self.project_description
def get_dict(self): # for sending
return {"name": self.project_name,
"projectDescription": self.project_description}
def __str__(self):
return "ID:" + self.project_id + " Name:" + self.project_name + \
" Description: " + self.project_description
class Project:
# project_id is optional because it's not necessary when creating a Project
# object to send.
def __init__(self, proj_name, proj_description=None, proj_id=None):
# proj_id is the identifier key when getting projects from the API.
self.project_name = proj_name
self.project_description = str(proj_description)
self.project_id = str(proj_id)
def get_id(self):
return self.project_id
def get_name(self):
return self.project_name
def get_description(self):
return self.project_description
def get_dict(self): # for sending
return {"name": self.project_name,
"projectDescription": self.project_description}
def __str__(self):
return "ID:" + self.project_id + " Name:" + self.project_name + \
" Description: " + self.project_description
import json
import logging
"""
A Sample will store (key: value) pairs using a dictionary.
e.g {"sequencerSampleId": "01-1111"}
Keys: 'sampleName','description','sequencerSampleId','sampleProject'
"""
class Sample(object):
def __init__(self, new_samp_dict, run=None, sample_number=None):
self.sample_dict = dict(new_samp_dict)
self.seq_file = None
self._run = run
self._sample_number = sample_number
self._already_uploaded = False
def get_id(self):
# When pulling sample records from the server, the sample name *is* the
# identifier for the sample, so if it's not specified in the dictionary
# that we're using to build this sample, set it as the sample name that
# we got from the server.
try:
return self.sample_dict["sequencerSampleId"]
except KeyError:
return self.sample_dict["sampleName"]
@property
def already_uploaded(self):
return self._already_uploaded
@already_uploaded.setter
def already_uploaded(self, already_uploaded=False):
self._already_uploaded = already_uploaded
@property
def sample_name(self):
return self.get("sampleName")
@property
def sample_number(self):
return self._sample_number
def get_project_id(self):
return self.get("sampleProject")
def get_dict(self):
return self.sample_dict
def __getitem__(self, key):
ret_val = None
if key in self.sample_dict:
ret_val = self.sample_dict[key]
return ret_val
def get(self, key):
return self.__getitem__(key)
def get_sample_metadata(self):
return self.seq_file.get_properties()
def get_files(self):
return self.seq_file.get_files()
def get_files_size(self):
return self.seq_file.get_files_size()
def set_seq_file(self, seq_file):
self.seq_file = seq_file
def is_paired_end(self):
return len(self.seq_file.get_files()) == 2
def __str__(self):
return str(self.sample_dict) + str(self.seq_file)
@property
def upload_progress_topic(self):
return self._run.upload_progress_topic + "." + self.get_id()
@property
def upload_started_topic(self):
return self._run.upload_started_topic + "." + self.get_id()
@property
def upload_completed_topic(self):
return self._run.upload_completed_topic + "." + self.get_id()
@property
def upload_failed_topic(self):
return self._run.upload_failed_topic + "." + self.get_id()
@property
def online_validation_topic(self):
return self._run.online_validation_topic + "." + self.get_id()
@property
def run(self):
return self._run
@run.setter
def run(self, run):
logging.info("Setting run.")
self._run = run
class JsonEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Sample):
sample_dict = dict(obj.get_dict())
# get sample dict and make a copy of it
sample_dict.pop("sampleProject")
if "sequencerSampleId" in sample_dict:
# if the sample ID field is populated, then we've just Finished
# reading the run from disk and we're preparing to send data
# to the server. The server is using the sample ID field as the
# name of the sample, so overwrite whatever we *were* using to
# find files with the sample ID field.
sample_dict["sampleName"] = sample_dict["sequencerSampleId"]
return sample_dict
else:
return json.JSONEncoder.default(self, obj)
import json
import logging
"""
A Sample will store (key: value) pairs using a dictionary.
e.g {"sequencerSampleId": "01-1111"}
Keys: 'sampleName','description','sequencerSampleId','sampleProject'
"""
class Sample(object):
def __init__(self, new_samp_dict, run=None, sample_number=None):
self.sample_dict = dict(new_samp_dict)
self.seq_file = None
self._run = run
self._sample_number = sample_number
self._already_uploaded = False
def get_id(self):
# When pulling sample records from the server, the sample name *is* the
# identifier for the sample, so if it's not specified in the dictionary
# that we're using to build this sample, set it as the sample name that
# we got from the server.
try:
return self.sample_dict["sequencerSampleId"]
except KeyError:
return self.sample_dict["sampleName"]
@property
def already_uploaded(self):
return self._already_uploaded
@already_uploaded.setter
def already_uploaded(self, already_uploaded=False):
self._already_uploaded = already_uploaded
@property
def sample_name(self):
return self.get("sampleName")
@property
def sample_number(self):
return self._sample_number
def get_project_id(self):
return self.get("sampleProject")
def get_dict(self):
return self.sample_dict
def __getitem__(self, key):
ret_val = None
if key in self.sample_dict:
ret_val = self.sample_dict[key]
return ret_val
def get(self, key):
return self.__getitem__(key)
def get_sample_metadata(self):
return self.seq_file.get_properties()
def get_files(self):
return self.seq_file.get_files()
def get_files_size(self):
return self.seq_file.get_files_size()
def set_seq_file(self, seq_file):
self.seq_file = seq_file
def is_paired_end(self):
return len(self.seq_file.get_files()) == 2
def __str__(self):
return str(self.sample_dict) + str(self.seq_file)
@property
def upload_progress_topic(self):
return self._run.upload_progress_topic + "." + self.get_id()
@property
def upload_started_topic(self):
return self._run.upload_started_topic + "." + self.get_id()
@property
def upload_completed_topic(self):
return self._run.upload_completed_topic + "." + self.get_id()
@property
def upload_failed_topic(self):
return self._run.upload_failed_topic + "." + self.get_id()
@property
def online_validation_topic(self):
return self._run.online_validation_topic + "." + self.get_id()
@property
def run(self):
return self._run
@run.setter
def run(self, run):
logging.info("Setting run.")
self._run = run
class JsonEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Sample):
sample_dict = dict(obj.get_dict())
# get sample dict and make a copy of it
sample_dict.pop("sampleProject")
if "sequencerSampleId" in sample_dict:
# if the sample ID field is populated, then we've just Finished
# reading the run from disk and we're preparing to send data
# to the server. The server is using the sample ID field as the
# name of the sample, so overwrite whatever we *were* using to
# find files with the sample ID field.
sample_dict["sampleName"] = sample_dict["sequencerSampleId"]
return sample_dict
else:
return json.JSONEncoder.default(self, obj)
from os import path
"""
Holds files and Sample metadata:
samplePlate
sampleWell
i7IndexID
index
i5IndexID
index2
etc.
"""
class SequenceFile:
def __init__(self, properties_dict, file_list):
self.properties_dict = properties_dict # Sample metadata
self.file_list = file_list
self.file_list.sort()
def get_properties(self):
return self.properties_dict
def get(self, key):
retVal = None
if self.properties_dict in key:
retVal = self.properties_dict[key]
return retVal
def get_files_size(self):
return sum([path.getsize(file) for file in self.file_list])
def get_files(self):
return self.file_list
def __str__(self):
return str(self.properties_dict) + str(self.file_list)
from os import path
"""
Holds files and Sample metadata:
samplePlate
sampleWell
i7IndexID
index
i5IndexID
index2
etc.
"""
class SequenceFile:
def __init__(self, properties_dict, file_list):
self.properties_dict = properties_dict # Sample metadata
self.file_list = file_list
self.file_list.sort()
def get_properties(self):
return self.properties_dict
def get(self, key):
retVal = None
if self.properties_dict in key:
retVal = self.properties_dict[key]
return retVal
def get_files_size(self):
return sum([path.getsize(file) for file in self.file_list])
def get_files(self):
return self.file_list
def __str__(self):
return str(self.properties_dict) + str(self.file_list)
import os
import logging
class SequencingRun(object):
def __init__(self, metadata = None, sample_list = None, sample_sheet = None):
self._sample_list = sample_list
self._metadata = metadata
if sample_sheet is None:
raise ValueError("Sample sheet cannot be None!")
self._sample_sheet = sample_sheet
self._sample_sheet_dir = os.path.dirname(sample_sheet)
self._sample_sheet_name = os.path.basename(self._sample_sheet_dir)
for sample in self._sample_list:
logging.info("Setting run.")
sample.run = self
@property
def metadata(self):
return self._metadata
@metadata.setter
def metadata(self, metadata_dict):
self._metadata = metadata_dict
def get_workflow(self):
return self._metadata["workflow"]
@property
def sample_list(self):
return self._sample_list
@sample_list.setter
def sample_list(self, sample_list):
self._sample_list = sample_list
@property
def uploaded_samples(self):
return filter(lambda sample: sample.already_uploaded, self.sample_list)
@property
def samples_to_upload(self):
return filter(lambda sample: not sample.already_uploaded, self.sample_list)
def get_sample(self, sample_id):
for sample in self._sample_list:
if sample.get_id() == sample_id:
return sample
else:
raise ValueError("No sample with id {} found!.".format(sample_id))
def set_files(self, sample_id, file_list):
for sample in self._sample_list:
if sample.get_id() == sample_id:
sample.set_files(file_list)
break
def get_files(self, sample_id):
sample = self._get_sample(sample_id)
return sample.get_files()
@property
def sample_sheet(self):
return self._sample_sheet
@sample_sheet.setter
def sample_sheet(self, sample_sheet):
self._sample_sheet = sample_sheet
@property
def sample_sheet_dir(self):
return self._sample_sheet_dir
@property
def sample_sheet_name(self):
return self._sample_sheet_name
@property
def upload_started_topic(self):
return self._sample_sheet_name + ".upload_started"
@property
def upload_progress_topic(self):
return self._sample_sheet_name + ".upload_progress"
@property
def upload_completed_topic(self):
return self._sample_sheet_name + ".upload_completed"
@property
def upload_failed_topic(self):
return self._sample_sheet_name + ".upload_failed"
@property
def offline_validation_topic(self):
return self._sample_sheet_name + ".offline_validation"
@property
def online_validation_topic(self):
return self._sample_sheet_name + ".online_validation"
import os
import logging
class SequencingRun(object):
def __init__(self, metadata = None, sample_list = None, sample_sheet = None):
self._sample_list = sample_list
self._metadata = metadata
if sample_sheet is None:
raise ValueError("Sample sheet cannot be None!")
self._sample_sheet = sample_sheet
self._sample_sheet_dir = os.path.dirname(sample_sheet)
self._sample_sheet_name = os.path.basename(self._sample_sheet_dir)
for sample in self._sample_list:
logging.info("Setting run.")
sample.run = self
@property
def metadata(self):
return self._metadata
@metadata.setter
def metadata(self, metadata_dict):
self._metadata = metadata_dict
def get_workflow(self):
return self._metadata["workflow"]
@property
def sample_list(self):
return self._sample_list
@sample_list.setter
def sample_list(self, sample_list):
self._sample_list = sample_list
@property
def uploaded_samples(self):
return filter(lambda sample: sample.already_uploaded, self.sample_list)
@property
def samples_to_upload(self):
return filter(lambda sample: not sample.already_uploaded, self.sample_list)
def get_sample(self, sample_id):
for sample in self._sample_list:
if sample.get_id() == sample_id:
return sample
else:
raise ValueError("No sample with id {} found!.".format(sample_id))
def set_files(self, sample_id, file_list):
for sample in self._sample_list:
if sample.get_id() == sample_id:
sample.set_files(file_list)
break
def get_files(self, sample_id):
sample = self._get_sample(sample_id)
return sample.get_files()
@property
def sample_sheet(self):
return self._sample_sheet
@sample_sheet.setter
def sample_sheet(self, sample_sheet):
self._sample_sheet = sample_sheet