def create_new_project_and_upload_fastq(project_name, sample_data_list,
                                        experiment_name):
    '''
  A function for uploading afstq files to basespace after creating a new project
  
  :param project_name: A project name
  :param sample_data_list: Sample data list containing following information
  
                           sample_name (str)
                           read_count  (str)
                           read_length (str)
                           fastq_path (list)
                           
  :param experiment_name: Experiment name
  :retruns: None
  '''
    try:
        myAPI = BaseSpaceAPI()
        project = myAPI.createProject(project_name)  # create new project
        appResults = project.\
                     createAppResult(\
                        myAPI,
                        "FastqUpload",
                        "uploading project data",
                        appSessionId='')                                            # create new app results for project
        myAppSession = appResults.AppSession  # get app session
        __create_sample_and_upload_data(\
          api=myAPI,
          appSessionId=myAppSession.Id,
          appSession=myAppSession,
          project_id=project.Id,
          sample_data_list=sample_data_list,
          exp_name=experiment_name
        )                                                                           # upload fastq
        myAppSession.setStatus(
            myAPI, 'complete',
            "finished file upload")  # mark app session a complete
    except:
        if myAppSession and \
           len(project.getAppResults(myAPI,statuses=['Running']))>0:
            myAppSession.setStatus(
                myAPI, 'complete',
                "failed file upload")  # comment for failed jobs
        raise
Exemple #2
0
                        help="Target upload directory (default: %(default)s)")
    parser.add_argument("--sdir",
                        "-s",
                        type=str,
                        default="",
                        help="Target subdirectory (default: %(default)s)")
    parser.add_argument("--name", "-n", type=str, help="Target file name")
    args = parser.parse_args()

    print "Connecting to BaseSpace API server..."
    myAPI = BaseSpaceAPI()
    user = myAPI.getUserById('current')

    print "Connected to server, username: %s" % user

    p = myAPI.createProject(args.project)

    appResults = p.createAppResult(myAPI, args.dir, "", appSessionId="")

    myAppSession = appResults.AppSession
    myAppSession.setStatus(myAPI, "running", "uploading data")

    if not args.name or len(args.file):
        args.name = os.path.basename(args.file)
    print "Uploading file %(file)s to %(project)s:%(dir)s/%(sdir)s/%(name)s" % args.__dict__

    appResults.uploadFile(myAPI, args.file, args.name, args.sdir, "text/plain")

    myAppSession.setStatus(myAPI, "complete", "data uploaded")
    print "File successfully uploaded"
"""
import os
import sys

# Add relative path libraries
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.abspath(os.path.sep.join([SCRIPT_DIR, "..", "lib"])))
sys.path.append(os.path.abspath(os.path.sep.join([SCRIPT_DIR, "..", "..", "basespace-python-sdk", "src"])))

from BaseSpacePy.api.BaseSpaceAPI import BaseSpaceAPI
import Repository

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(description='Create a project')
    parser.add_argument('-n', '--name', type=str, required=True, dest="name", help='name of project')
    parser.add_argument('-p', '--path', type=str, required=True, dest="path", help='path where project should write')

    args = parser.parse_args()

    baseSpaceAPI = BaseSpaceAPI()

    if not os.path.exists(args.path):
        print "must specify an output directory that already exists!"
        sys.exit(1)

    print "attempting to create/retrieve BaseSpace project"
    project = baseSpaceAPI.createProject(args.name)
    print "got Id: %s" % project.Id
    Repository.AddProject(args.name, args.path, project.Id)