diff --git a/CHANGES b/CHANGES index 53e1cba..019299d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -cutlass 0.27 +cutlass 0.28 * Added support for private data in nodes associated with files and file transfer, such as WgsRawSeqSet. @@ -8,14 +8,21 @@ cutlass 0.27 - Victor Thu, 26 Jan 2016 15:30:00 -0400 +cutlass 0.27 + + * Bug fix to SixteenSTrimmedSeqSet save() functionality which + was losing the urls property. + * Improved test for SixteenSTrimmedSeqSet class. + * Added missing example script for SixteenSTrimmedSeqSet data. + + - Victor Tue, 17 Jan 2017 15:00:00 -0400 + cutlass 0.26 * Added missing SubjectAttribute node, example and test. * Modified Subject node to add attributes() method for retrieval of SubjectAttribute information. * Modified Annotation class to require file size. - * Bug fix to SixteenSTrimmedSeqSet save() functionality which - was losing the urls property. * Removed WgsRawSeqSetPrivate class, test and example in favor of more generic solution. * Improved flexibility of test scripts by using a configuration diff --git a/cutlass/SixteenSTrimmedSeqSet.py b/cutlass/SixteenSTrimmedSeqSet.py index e4e98bf..364cad3 100644 --- a/cutlass/SixteenSTrimmedSeqSet.py +++ b/cutlass/SixteenSTrimmedSeqSet.py @@ -618,6 +618,8 @@ def save(self): self.logger.error("Experienced an error uploading the sequence " + \ "set. Aborting save.") return success + else: + self._urls = [ "fasp://" + aspera_server + remote_path ] self.logger.info("Uploaded the %s to the iHMP Aspera server (%s) successfully." % (self._local_file, aspera_server)) @@ -638,11 +640,9 @@ def save(self): self.logger.info("Setting ID for " + __name__ + " %s." % node_id) self._set_id(node_id) self._version = 1 - self._urls = [ "fasp://" + aspera_server + remote_path ] success = True except Exception as e: - self.logger.exception(e) self.logger.error("An error occurred while saving " + __name__ + ". " + \ "Reason: %s" % e) else: diff --git a/examples/16s_trimmed_seq_set.py b/examples/16s_trimmed_seq_set.py new file mode 100755 index 0000000..8c412e8 --- /dev/null +++ b/examples/16s_trimmed_seq_set.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +import json +import logging +from cutlass import SixteenSTrimmedSeqSet +from cutlass import iHMPSession +from pprint import pprint +import tempfile +import sys + +root = logging.getLogger() +root.setLevel(logging.DEBUG) +ch = logging.StreamHandler(sys.stdout) +ch.setLevel(logging.DEBUG) +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +ch.setFormatter(formatter) +root.addHandler(ch) + +username = "test" +password = "test" + +session = iHMPSession(username, password) + +print("Required fields: ") +print(SixteenSTrimmedSeqSet.required_fields()) + +seq_set = SixteenSTrimmedSeqSet() + +seq_set.checksums = { "md5": "72bdc024d83226ccc90fbd2177e78d56" } +seq_set.comment = "test comment. Hello world!" +seq_set.exp_length = 2000 +seq_set.format = "fasta" +seq_set.format_doc = "url" +seq_set.seq_model = "a machine" +seq_set.sequence_type = "nucleotide" +seq_set.size = 3000 +seq_set.study = "prediabetes" + +print("Creating a temp file for example/testing purposes.") +temp_file = tempfile.NamedTemporaryFile(delete=False).name +print("Local file: %s" % temp_file) + +seq_set.local_file = temp_file + +seq_set.links = { "computed_from": [ "610a4911a5ca67de12cdc1e4b4014cd0" ] } + +seq_set.tags = [ "16s_trimmed_seq_set", "ihmp" ] +seq_set.add_tag("another") +seq_set.add_tag("and_another") + +print(seq_set.to_json(indent=2)) + +if seq_set.is_valid(): + print("Valid!") + + success = seq_set.save() + + if success: + seq_set_id = seq_set.id + print("Successfully saved sequence set with ID: %s" % seq_set_id) + + seq_set2 = SixteenSTrimmedSeqSet.load(seq_set_id) + + print(seq_set.to_json(indent=4)) + + deletion_success = seq_set.delete() + + if deletion_success: + print("Deleted 16s_trimmed_seq_set with ID %s" % seq_set_id) + else: + print("Deletion of 16s_trimmed_seq_set %s failed." % seq_set_id) + else: + print("Save failed") +else: + print("Invalid...") + validation_errors = seq_set.validate() + pprint(validation_errors) diff --git a/tests/test_16s_trimmed_seq_set.py b/tests/test_16s_trimmed_seq_set.py index 9d6e248..145d904 100644 --- a/tests/test_16s_trimmed_seq_set.py +++ b/tests/test_16s_trimmed_seq_set.py @@ -5,6 +5,7 @@ import random import string import sys +import tempfile from cutlass import iHMPSession from cutlass import SixteenSTrimmedSeqSet @@ -324,6 +325,8 @@ def testRequiredFields(self): "required_field() did not return empty value.") def testLoadSaveDeleteSixteenSTrimmedSeqSet(self): + temp_file = tempfile.NamedTemporaryFile(delete=False).name + # Attempt to save the sixteenSTrimmedSeqSet at all points before and # after adding the required fields @@ -334,7 +337,6 @@ def testLoadSaveDeleteSixteenSTrimmedSeqSet(self): exp_length = 100 test_format = "fasta" test_format_doc = "http://example.com" - local_fasta_file = "test.fasta" seq_model = "center for sequencing" size = 132 study = "ibd" @@ -366,7 +368,7 @@ def testLoadSaveDeleteSixteenSTrimmedSeqSet(self): sixteenSTrimmedSeqSet.format_doc = test_format_doc sixteenSTrimmedSeqSet.format = test_format sixteenSTrimmedSeqSet.seq_model = seq_model - sixteenSTrimmedSeqSet.local_file = local_fasta_file + sixteenSTrimmedSeqSet.local_file = temp_file sixteenSTrimmedSeqSet.size = size sixteenSTrimmedSeqSet.study = study