Skip to content

Commit

Permalink
Version 0.28. Added private file support to file transfer classes. Im…
Browse files Browse the repository at this point in the history
…provements to auxiliary testing code. Added missing example and test scripts.
  • Loading branch information
victor73 committed Jan 26, 2017
2 parents 184ce51 + ea7b554 commit 0db9491
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 7 deletions.
13 changes: 10 additions & 3 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -8,14 +8,21 @@ cutlass 0.27

- Victor <[email protected]> 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 <[email protected]> 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
Expand Down
4 changes: 2 additions & 2 deletions cutlass/SixteenSTrimmedSeqSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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:
Expand Down
77 changes: 77 additions & 0 deletions examples/16s_trimmed_seq_set.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 4 additions & 2 deletions tests/test_16s_trimmed_seq_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import random
import string
import sys
import tempfile

from cutlass import iHMPSession
from cutlass import SixteenSTrimmedSeqSet
Expand Down Expand Up @@ -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

Expand All @@ -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"
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0db9491

Please sign in to comment.