Ejemplo n.º 1
0
                    "data": bowtie2_out,
                    "name": output_name
                }]
            })
        except Exception, e:
            #logger.exception("Failed to save alignment to workspace")
            raise Exception("Failed to save alignment to workspace")
    except Exception, e:
        #logger.exception("Failed to create bowtie2 Alignment {0}".format(" ".join(traceback.print_exc())))
        raise Exception("Failed to create bowtie2 Alignment {0}".format(
            " ".join(traceback.print_exc())))
    finally:
        if os.path.exists(out_file_path): os.remove(out_file_path)
        if os.path.exists(output_dir): shutil.rmtree(output_dir)
        ret = script_util.if_obj_exists(None, ws_client, ws_id,
                                        "KBaseRNASeq.RNASeqAlignment",
                                        [output_name])
        if not ret is None:
            return (read_sample, output_name)
        else:
            return None


def _CallTophat(logger, services, ws_client, hs, ws_id, sample_type,
                num_threads, read_sample, gtf_file, condition, directory,
                bowtie2index_id, genome_id, sampleset_id, params, token):
    print "Downloading Read Sample{0}".format(read_sample)
    if not logger:
        logger = create_logger(directory, "run_Tophat_" + read_sample)
    try:
        r_sample = ws_client.get_objects([{
Ejemplo n.º 2
0
                           'mapped_rnaseq_alignment'  : { sample_id : s_alignment },
                           'tool_used'                : self.tool_used,
                           'tool_version'             : self.tool_version,
                           'tool_opts'                : tool_opts,
                           'file'                     : handle
                         }

                res= ws_client.save_objects(
                                   {"workspace":ws_id,
                                    "objects": [{
                                    "type":"KBaseRNASeq.RNASeqExpression",
                                    "data":es_obj,
                                    "name":output_name}
                                     ]})[0]
                expr_id = str(res[6]) + '/' + str(res[0]) + '/' + str(res[4])
           except Exception, e:
                logger.exception("".join(traceback.format_exc()))
                raise Exception("Failed to upload the ExpressionSample: {0}".format(output_name))
   	except Exception,e:
       		logger.exception("".join(traceback.format_exc()))
       		raise Exception("Error executing stringtie {0},{1}".format(cufflinks_command,directory))
   	finally:
                if os.path.exists(out_file_path): os.remove(out_file_path)
                if os.path.exists(output_dir): shutil.rmtree(output_dir)
                if os.path.exists(input_direc): shutil.rmtree(input_direc)
                ret = script_util.if_obj_exists(None,ws_client,ws_id,"KBaseRNASeq.RNASeqExpression",[output_name])
                if not ret is None:
                    return (alignment_name, output_name )
        return None

Ejemplo n.º 3
0
                    "name": output_name
                }]
            })
        except Exception, e:
            #logger.exception("Failed to save alignment to workspace")
            raise Exception("Failed to save alignment to workspace")
    except Exception, e:
        #logger.exception("Failed to create hisat2 Alignment {0}".format(" ".join(traceback.print_exc())))
        raise Exception("Failed to create hisat2 Alignment {0}".format(
            " ".join(traceback.print_exc())))
    finally:
        if os.path.exists(input_direc): shutil.rmtree(input_direc)
        if os.path.exists(out_file_path): os.remove(out_file_path)
        if os.path.exists(output_dir): shutil.rmtree(output_dir)
        ret = script_util.if_obj_exists(None, ws_client, ws_id,
                                        "KBaseRNASeq.RNASeqAlignment",
                                        [output_name])
        if not ret is None:
            return (read_sample, output_name)
        #else:
    return None


def runMethod(logger, token, ws_client, hs, services, hisat2_dir, params):
    try:
        sample, annotation_name = ws_client.get_objects([{
            'name':
            params['sampleset_id'],
            'workspace':
            params['ws_id']
        }, {
Ejemplo n.º 4
0
                except Exception, e:
                        raise Exception("Failed to upload zipped output file".format(out_file_path))
                #### Replace version with get_version command#####
		logger.info("Preparing output object")
                tophat_out = { "file" : tophat_handle ,"size" : os.path.getsize(out_file_path), "aligned_using" : "tophat" , "aligner_version" : "2.2.1" , 'library_type' : lib_type , 'condition' : condition ,'read_sample_id': read_sample, 'genome_id' : genome_id , 'bowtie2_index': self.bowtie2index_id, "alignment_stats" : stats_data }
                if not sampleset_id is None: tophat_out['sampleset_id'] = sampleset_id
                pprint(tophat_out)
		try:
                        res= ws_client.save_objects(
                                        {"workspace":ws_id,
                                         "objects": [{
                                         "type":"KBaseRNASeq.RNASeqAlignment",
                                         "data":tophat_out,
                                         "name":output_name}
                                        ]})
                except Exception, e:
			raise Exception(e)
                        #logger.exception("Failed to save alignment to workspace")
                        raise Exception("Failed to save alignment to workspace")
        except Exception, e:
                        #logger.exception("Failed to create tophat Alignment {0}".format(" ".join(traceback.print_exc())))
                        raise Exception("Failed to create tophat Alignment {0}".format(" ".join(traceback.print_exc())))
        finally:
                if os.path.exists(out_file_path): os.remove(out_file_path)
                if os.path.exists(output_dir): shutil.rmtree(output_dir)
                ret = script_util.if_obj_exists(None,ws_client,ws_id,"KBaseRNASeq.RNASeqAlignment",[output_name])
                if not ret is None:
                    return (read_sample,output_name)
		else :
		    return None
            ## Get the Input object type and info #
            e_sample_info = ws_client.get_object_info_new({"objects": [{'name': params['expressionset_id'], 'workspace': params['ws_id']}]})[0]
            e_sample_type = e_sample_info[2].split('-')[0]
            expressionset_id = str(e_sample_info[6]) + '/' + str(e_sample_info[0]) + '/' + str(e_sample_info[4])
	    alignmentset_id = e_sample['data']['alignmentSet_id'] 
	    sampleset_id = e_sample['data']['sampleset_id']
            expression_ids = e_sample['data']['sample_expression_ids']
            num_samples = len(expression_ids)
            if num_samples < 2:
               raise ValueError("Please ensure you have atleast 2 expressions to run diffExpCallforBallgown in Set mode")
            ### Check if the gtf file exists in the workspace. if exists download the file from that
            annotation_id = e_sample['data']['genome_id']
            logger.info("Check if the gtf file exists in the workspace".format(annotation_id))
            annotation_name = ws_client.get_object_info([{"ref" :annotation_id}],includeMetadata=None)[0][1]
            gtf_obj_name = annotation_name+"_GTF_Annotation"
            ret = script_util.if_obj_exists(None,ws_client,params['ws_id'],"KBaseRNASeq.GFFAnnotation",[gtf_obj_name])
            if not ret is None:
                logger.info("GFF Annotation Exist for Genome Annotation {0}.... Skipping step ".format(annotation_name))
                gtf_obj= ws_client.get_objects([{'name' : gtf_obj_name,'workspace' : params['ws_id']}])[0]
                gtf_info = ws_client.get_object_info_new({"objects": [{'name': gtf_obj_name, 'workspace': params['ws_id']}]})[0]
                gtf_annotation_id = str(gtf_info[6]) + '/' + str(gtf_info[0]) + '/' + str(gtf_info[4])
                gtf_id=gtf_obj['data']['handle']['id']
                gtf_name=gtf_obj['data']['handle']['file_name']
                try:
                     script_util.download_file_from_shock(logger, shock_service_url=services['shock_service_url'], shock_id=gtf_id,filename=gtf_name, directory=diffexp_dir,token=token)
                     gtf_file = os.path.join(diffexp_dir,gtf_name)
                except Exception,e:
                     raise Exception( "Unable to download shock file, {0}".format(gtf_name))
            else:
                fasta_file= script_util.generate_fasta(logger,services,token,annotation_id,diffexp_dir,annotation_name)
                logger.info("Sanitizing the fasta file to correct id names {}".format(datetime.datetime.utcnow()))
Ejemplo n.º 6
0
    num_samples = len(expression_ids)
    if num_samples < 2:
        raise ValueError(
            "Please ensure you have atleast 2 expressions to run diffExpCallforBallgown in Set mode"
        )
### Check if the gtf file exists in the workspace. if exists download the file from that
    annotation_id = e_sample['data']['genome_id']
    logger.info(
        "Check if the gtf file exists in the workspace".format(annotation_id))
    annotation_name = ws_client.get_object_info([{
        "ref": annotation_id
    }],
                                                includeMetadata=None)[0][1]
    gtf_obj_name = annotation_name + "_GTF_Annotation"
    ret = script_util.if_obj_exists(None, ws_client, params['ws_id'],
                                    "KBaseRNASeq.GFFAnnotation",
                                    [gtf_obj_name])
    if not ret is None:
        logger.info(
            "GFF Annotation Exist for Genome Annotation {0}.... Skipping step "
            .format(annotation_name))
        gtf_obj = ws_client.get_objects([{
            'name': gtf_obj_name,
            'workspace': params['ws_id']
        }])[0]
        gtf_info = ws_client.get_object_info_new({
            "objects": [{
                'name': gtf_obj_name,
                'workspace': params['ws_id']
            }]
        })[0]
Ejemplo n.º 7
0
                                         "objects": [{
                                         "type":"KBaseRNASeq.RNASeqAlignment",
                                         "data":hisat2_out,
                                         "name":output_name}
                                        ]})
                except Exception, e:
                        #logger.exception("Failed to save alignment to workspace")
                        raise Exception("Failed to save alignment to workspace")
        except Exception, e:
                        #logger.exception("Failed to create hisat2 Alignment {0}".format(" ".join(traceback.print_exc())))
                        raise Exception("Failed to create hisat2 Alignment {0}".format(" ".join(traceback.print_exc())))
        finally:
                if os.path.exists(input_direc): shutil.rmtree(input_direc)
                if os.path.exists(out_file_path): os.remove(out_file_path)
                if os.path.exists(output_dir): shutil.rmtree(output_dir)
                ret = script_util.if_obj_exists(None,ws_client,ws_id,"KBaseRNASeq.RNASeqAlignment",[output_name])
                if not ret is None:
                    return (read_sample,output_name)
                #else:
        return None
    	
def runMethod(logger,token,ws_client,hs,services,hisat2_dir,params):
	try:
               sample,annotation_name = ws_client.get_objects(
                                        [{ 'name' : params['sampleset_id'], 'workspace' : params['ws_id']},
                                        { 'name' : params['genome_id'], 'workspace' : params['ws_id']}])
        except Exception,e:
               logger.exception("".join(traceback.format_exc()))
               raise ValueError(" Error Downloading objects from the workspace ")
            ### Get obejct IDs
        sampleset_info,annotation_info = ws_client.get_object_info_new({"objects": [