How to use read_rv method in fMBT

Best Python code snippet using fMBT_python

QC_1.smk

Source:QC_1.smk Github

copy

Full Screen

1#!/usr/bin/env python2'''3Pre-processing of metaG and metaT data step - quality reads filtering4Authors: Carmen Saenz, Mani Arumugam5'''6#7# configuration yaml file8# import sys9import os.path10from os import path11# args = sys.argv12# config_path = args[args.index("--configfile") + 1]13config_path = 'configuration yaml file' #args[args_idx+1]14print(" *******************************")15print(" Reading configuration yaml file: ")#, config_path)16print(" *******************************")17print(" ")18# Variables from configuration yaml file19if config['PROJECT'] is None:20 print('ERROR in ', config_path, ': PROJECT variable is empty. Please, complete ', config_path)21else:22 project_id = config['PROJECT']23if config['working_dir'] is None:24 print('ERROR in ', config_path, ': working_dir variable is empty. Please, complete ', config_path)25elif path.exists(config['working_dir']) is False:26 print('WARNING in ', config_path, ': working_dir path does not exit. The directory will be created by MIntO')27 working_dir = config['working_dir']28else:29 working_dir = config['working_dir']30if config['omics'] in ('metaG', 'metaT'):31 omics = config['omics']32else:33 print('ERROR in ', config_path, ': omics variable is not correct. "omics" variable should be metaG or metaT.')34if config['local_dir'] is None:35 print('ERROR in ', config_path, ': local_dir variable is empty. Please, complete ', config_path)36else:37 local_dir = config['local_dir']38if config['raw_reads_dir'] is None:39 print('ERROR in ', config_path, ': raw_reads_dir variable in configuration yaml file is empty. Please, complete ', config_path)40else:41 raw_dir = config['raw_reads_dir']42if config['minto_dir'] is None:43 print('ERROR in ', config_path, ': minto_dir variable in configuration yaml file is empty. Please, complete ', config_path)44elif path.exists(config['minto_dir']) is False:45 print('ERROR in ', config_path, ': minto_dir variable path does not exit. Please, complete ', config_path)46else:47 minto_dir=config["minto_dir"]48 script_dir=config["minto_dir"]+"/scripts"49if config['METADATA'] is None:50 print('WARNING in ', config_path, ': METADATA variable is empty. Samples will be analyzed excluding the metadata.')51 metadata=config["METADATA"]52 #metadata="None"53elif config['METADATA'] == "None":54 print('WARNING in ', config_path, ': METADATA variable is empty. Samples will be analyzed excluding the metadata.')55 metadata=config["METADATA"]56if config['METADATA'] is not None:57 if path.exists(config['METADATA']) is False:58 print('ERROR in ', config_path, ': METADATA variable path does not exit. Please, complete ', config_path)59 else:60 metadata=config["METADATA"]61# Make list of illumina samples, if ILLUMINA in config62if 'ILLUMINA' in config:63 if config['ILLUMINA'] is None:64 print('ERROR in ', config_path, ': ILLUMINA list of samples is empty. Please, complete ', config_path)65 else:66 try:67 # Make list of illumina samples, if ILLUMINA in config68 ilmn_samples = list()69 if 'ILLUMINA' in config:70 #print("Samples:")71 for ilmn in config["ILLUMINA"]:72 if path.exists(raw_dir+'/'+ilmn+'/'+ilmn+'.1.fq.gz') is True:73 #print(ilmn)74 ilmn_samples.append(ilmn)75 else:76 raise TypeError('ERROR in ', config_path, ': ILLUMINA list of samples does not exist. Please, complete ', config_path)77 except: 78 print('ERROR in ', config_path, ': ILLUMINA list of samples does not exist or has an incorrect format. Please, complete ', config_path)79else:80 print('ERROR in ', config_path, ': ILLUMINA list of samples is empty. Please, complete ', config_path)81if config['trimmomatic_adaptors'] in ('False', 'Skip'):82 pass83elif config['trimmomatic_adaptors'] is None:84 print('ERROR in ', config_path, ': trimmomatic_adaptors variable is empty. Please, complete ', config_path)85elif path.exists(config['trimmomatic_adaptors']) is False:86 print('ERROR in ', config_path, ': trimmomatic_adaptors variable path does not exit. Please, complete ', config_path)87if config['perc_remaining_reads'] is None:88 print('ERROR in ', config_path, ': perc_remaining_reads variable is empty. Please, complete ', config_path)89if config['TRIMMOMATIC_threads'] is None:90 print('ERROR in ', config_path, ': TRIMMOMATIC_threads variable is empty. Please, complete ', config_path)91elif type(config['TRIMMOMATIC_threads']) != int:92 print('ERROR in ', config_path, ': TRIMMOMATIC_threads variable is not an integer. Please, complete ', config_path)93if config['TRIMMOMATIC_memory'] is None:94 print('ERROR in ', config_path, ': TRIMMOMATIC_memory variable is empty. Please, complete ', config_path)95elif type(config['TRIMMOMATIC_memory']) != int:96 print('ERROR in ', config_path, ': TRIMMOMATIC_memory variable is not an integer. Please, complete ', config_path)97# Define all the outputs needed by target 'all'98def qc1_trim_quality_output():99 result = expand("{wd}/{omics}/1-trimmed/{sample}/{sample}.{group}.paired.fq.gz", 100 wd = working_dir,101 omics = omics,102 sample = config["ILLUMINA"] if "ILLUMINA" in config else [],103 group=['1', '2']),\104 expand("{wd}/{omics}/1-trimmed/{sample}/{sample}.{group}.single.fq.gz", 105 wd = working_dir,106 omics = omics,107 sample = config["ILLUMINA"] if "ILLUMINA" in config else [],108 group=['1', '2']),\109 expand("{wd}/{omics}/1-trimmed/{sample}/{sample}_trimlog_quality_adapter", 110 wd = working_dir,111 omics = omics,112 sample = config["ILLUMINA"] if "ILLUMINA" in config else [])113 return(result)114def qc1_check_read_length_output():115 result = expand("{wd}/{omics}/1-trimmed/{sample}/{sample}.{group}.read_length.txt", 116 wd = working_dir,117 omics = omics,118 sample = config["ILLUMINA"] if "ILLUMINA" in config else [],119 group = ['1', '2']),\120 expand("{wd}/{omics}/1-trimmed/samples_read_length.txt",121 wd = working_dir,122 omics = omics)123 return(result)124def qc1_read_length_cutoff_output():125 result = expand("{wd}/output/1-trimmed/{omics}_cumulative_read_lenght_cutoff.pdf", 126 wd = working_dir,127 omics = omics)128 return(result)129def qc1_config_yml_output():130 result = expand("{wd}/{omics}/QC_2.yaml", 131 wd = working_dir,132 omics = omics)133 return(result)134rule all:135 input:136 qc1_trim_quality_output(),137 qc1_check_read_length_output(),138 qc1_read_length_cutoff_output(),139 qc1_config_yml_output()140###############################################################################################141# Pre-processing of metaG and metaT data 142# Filter reads by quality143############################################################################################### 144rule qc1_trim_quality:145 input:146 read_fw=lambda wildcards: '{raw_dir}/{sample}/{sample}.1.fq.gz'.format(raw_dir=raw_dir, sample = wildcards.sample),147 read_rv=lambda wildcards: '{raw_dir}/{sample}/{sample}.2.fq.gz'.format(raw_dir=raw_dir, sample = wildcards.sample),148 output: 149 pairead1="{wd}/{omics}/1-trimmed/{sample}/{sample}.1.paired.fq.gz", 150 singleread1="{wd}/{omics}/1-trimmed/{sample}/{sample}.1.single.fq.gz", 151 pairead2="{wd}/{omics}/1-trimmed/{sample}/{sample}.2.paired.fq.gz", 152 singleread2="{wd}/{omics}/1-trimmed/{sample}/{sample}.2.single.fq.gz", 153 log_adapter="{wd}/{omics}/1-trimmed/{sample}/{sample}_trimlog_quality_adapter"154 params:155 tmp_quality=lambda wildcards: "{local_dir}/{omics}_{sample}_qc1_trim_quality/".format(local_dir=local_dir, omics = omics, sample = wildcards.sample),156 adapters=config['trimmomatic_adaptors'],157 log: 158 "{wd}/logs/{omics}/1-trimmed/{sample}_qc1_trim_quality.log"159 resources:160 mem=config['TRIMMOMATIC_memory']161 threads:162 config['TRIMMOMATIC_threads'] 163 conda: 164 config["minto_dir"]+"/envs/MIntO_base.yml"#trimmomatic165 shell: 166 """mkdir -p {params.tmp_quality}1-trimmed/167 remote_dir=$(dirname {output.pairead1})168 adapter_file="{params.adapters}"169time (if [ "{params.adapters}" == "Skip" ]170 then echo ${{adapter_file}}; \171cat {input.read_fw} > {output.pairead1}; \172> {output.singleread1}; \173cat {input.read_rv} > {output.pairead2}; \174> {output.singleread2}; \175> {output.log_adapter}176elif [ "{params.adapters}" == "False" ]177 then echo 'Generate adapter sequences file'; \178sh {script_dir}/index_adapter.sh {input.read_fw} {wildcards.sample} {params.tmp_quality}1-trimmed/ {wildcards.wd} {wildcards.omics}; \179trimmomatic PE -threads {threads} -trimlog {params.tmp_quality}1-trimmed/{wildcards.sample}_trimlog_quality_adapter -phred33 {input.read_fw} {input.read_rv} \180{params.tmp_quality}1-trimmed/{wildcards.sample}.1.paired.fq.gz {params.tmp_quality}1-trimmed/{wildcards.sample}.1.single.fq.gz \181{params.tmp_quality}1-trimmed/{wildcards.sample}.2.paired.fq.gz {params.tmp_quality}1-trimmed/{wildcards.sample}.2.single.fq.gz \182TRAILING:5 LEADING:5 SLIDINGWINDOW:4:20 ILLUMINACLIP:{params.tmp_quality}1-trimmed/adapters.fa:2:30:10:2:keepBothReads; \183rsync {params.tmp_quality}1-trimmed/* $remote_dir184else echo 'Filter by quality'185 trimmomatic PE -threads {threads} -trimlog {params.tmp_quality}1-trimmed/{wildcards.sample}_trimlog_quality_adapter -phred33 {input.read_fw} {input.read_rv} \186{params.tmp_quality}1-trimmed/{wildcards.sample}.1.paired.fq.gz {params.tmp_quality}1-trimmed/{wildcards.sample}.1.single.fq.gz \187{params.tmp_quality}1-trimmed/{wildcards.sample}.2.paired.fq.gz {params.tmp_quality}1-trimmed/{wildcards.sample}.2.single.fq.gz \188TRAILING:5 LEADING:5 SLIDINGWINDOW:4:20 ILLUMINACLIP:${{adapter_file}}:2:30:10:2:keepBothReads; \189rsync {params.tmp_quality}1-trimmed/* $remote_dir190 fi ) >& {log}191 rm -rf {params.tmp_quality}"""192 193rule qc1_check_read_length:194 input: 195 pairead="{wd}/{omics}/1-trimmed/{sample}/{sample}.{group}.paired.fq.gz"196 output: 197 length="{wd}/{omics}/1-trimmed/{sample}/{sample}.{group}.read_length.txt"198 params:199 tmp_read_length=lambda wildcards: "{local_dir}/{omics}_{sample}.{group}_qc1_check_read_length/".format(local_dir=local_dir, omics = omics, sample = wildcards.sample, group = wildcards.group),200 log: 201 "{wd}/logs/{omics}/1-trimmed/{sample}.{group}.check_read_length.log"202 resources:203 mem=config['TRIMMOMATIC_memory']204 threads:205 config['TRIMMOMATIC_threads'] 206 shell: 207 """ mkdir -p {params.tmp_read_length}208 time (sh {script_dir}/QC_trim_read_length.sh {input.pairead} {params.tmp_read_length}/{wildcards.sample}.{wildcards.group}.read_length.txt {wildcards.sample}_{wildcards.group}209 rsync {params.tmp_read_length}/{wildcards.sample}.{wildcards.group}.read_length.txt {output.length}) >& {log}210 rm -rf {params.tmp_read_length} """211rule qc1_check_read_length_merge:212 input: 213 length=expand("{{wd}}/{{omics}}/1-trimmed/{sample}/{sample}.{group}.read_length.txt", sample=ilmn_samples, group=['1', '2'])214 output: 215 list_samples="{wd}/{omics}/1-trimmed/samples_read_length.txt", 216 log: 217 "{wd}/logs/{omics}/1-trimmed/qc1_check_read_length_merge.log"218 resources:219 mem=config['TRIMMOMATIC_memory']220 threads:221 config['TRIMMOMATIC_threads'] 222 shell: 223 """time (cat {input.length} >> {output.list_samples}) >& {log}""" 224 225rule qc1_cumulative_read_len_plot:226 input:227 list_samples="{wd}/{omics}/1-trimmed/samples_read_length.txt", 228 output:229 plot="{wd}/output/1-trimmed/{omics}_cumulative_read_lenght_cutoff.pdf", 230 cutoff_file="{wd}/{omics}/1-trimmed/QC_1_min_len_read_cutoff.txt"231 params: 232 cutoff=config["perc_remaining_reads"], 233 log: 234 "{wd}/logs/{omics}/1-trimmed/plot_cumulative_read_len.log"235 resources:236 mem=config['TRIMMOMATIC_memory']237 threads:238 config['TRIMMOMATIC_threads'] 239 conda: 240 config["minto_dir"]+"/envs/taxa_env.yml"241 shell:242 """ time (Rscript {script_dir}/QC_cumulative_read_length_plot.R {input.list_samples} {params.cutoff} {output.plot} {output.cutoff_file}) >& {log}""" #; rm {input.list_length}243 244##########################################################################################################245# Generate configuration yml file for the next step in pre-processing of metaG and metaT data 246##########################################################################################################247rule qc1_config_yml_file:248 input: 249 cutoff_file="{wd}/{omics}/1-trimmed/QC_1_min_len_read_cutoff.txt",250 output: 251 config_file="{wd}/{omics}/QC_2.yaml"252 params: 253 tmp_qc1_yaml=lambda wildcards: "{local_dir}/{omics}_qc1_config_yml_file/".format(local_dir=local_dir, omics = omics),254 trim_threads=config['TRIMMOMATIC_memory'],255 trim_memory=config['TRIMMOMATIC_threads'] 256 resources:257 mem=2258 threads: 259 2260 log: 261 "{wd}/logs/{omics}/qc1_config_yml_file.log"262 shell: 263 """264 mkdir -p {params.tmp_qc1_yaml}265 time (files='{ilmn_samples}'; echo $files; echo $files| tr ' ' '\\n'| sed 's/^/- /' - > {params.tmp_qc1_yaml}/samples_illumina.txt266echo "######################267# General settings268######################269PROJECT: {project_id}270working_dir: {wildcards.wd}271omics: {wildcards.omics}272local_dir: {local_dir}273minto_dir: {minto_dir}274METADATA: {metadata}275######################276# Program settings277######################278# Pre-processing - length reads filtering279TRIMMOMATIC_threads: {params.trim_threads}280TRIMMOMATIC_memory: {params.trim_memory}" > {params.tmp_qc1_yaml}QC_2.yaml281cat {input.cutoff_file} >> {params.tmp_qc1_yaml}QC_2.yaml282echo "283# Pre-processing - host genome filtering284PATH_host_genome:285NAME_host_genome:286BWA_index_host_threads:287BWA_index_host_memory:288BWA_host_threads:289BWA_host_memory: " >> {params.tmp_qc1_yaml}QC_2.yaml290if [ "{omics}" == "metaG" ];\291 then echo "292# Assembly-free taxonomy profiling293TAXA_threads:294TAXA_memory:295taxa_profile: metaphlan">> {params.tmp_qc1_yaml}QC_2.yaml296elif [ "{omics}" == "metaT" ];\297 then echo "298# ribosomal RNA depletion299sortmeRNA_threads:300sortmeRNA_memory:301sortmeRNA_db:302sortmeRNA_db_idx: ">> {params.tmp_qc1_yaml}QC_2.yaml303fi304echo "305# Input data306# ILLUMINA section:307# -----------------308# List of illumina samples that will be filtered by read length.309#310# E.g.:311# - I1312# - I2313#314ILLUMINA:" >> {params.tmp_qc1_yaml}QC_2.yaml315cat {params.tmp_qc1_yaml}/samples_illumina.txt >> {params.tmp_qc1_yaml}QC_2.yaml316rsync {params.tmp_qc1_yaml}QC_2.yaml {output.config_file}) >& {log}317rm -rf {params.tmp_qc1_yaml}318 """ 319 ...

Full Screen

Full Screen

client.py

Source:client.py Github

copy

Full Screen

...156 Returns return value of the expr.157 Raises RemoteEvalError if expr caused an exception.158 """159 return self.exec_in(namespace, "", expr, async=async, lock=lock)160 def read_rv(self, async_rv, timeout=0):161 """Read return value of async call.162 Parameters:163 async_rv (string or Async_rv object)164 Handle to asynchronous return value, created by165 async exec_in or eval_in.166 timeout (float or integer, optional)167 -1: block until return value is ready and return it.168 0: returns pythonshare.Busy immediately if return169 value is not readable yet.170 > 0: wait until this timeout (NOT IMPLEMENTED).171 The defualt is 0.172 """173 if isinstance(async_rv, str):174 async_rv = eval(async_rv)175 rv = self.eval_in(async_rv.ns, "pythonshare_ns.read_rv(%s)" % (async_rv,))176 return rv177 def export_ns(self, namespace):178 """Export namespace to remote peer179 Parameters:180 namespace (string)181 Namespace to be exported, can be local or182 remote to current host.183 Returns True on success or raises an exception. If succeeded,184 this connection becomes a server for requests from remote185 peer. (The remote peer accesses registered namespace through186 this connection object.)187 """188 pythonshare._send(Register_ns(namespace), self._to_server)189 rv = pythonshare._recv(self._from_server)190 if isinstance(rv, Ns_rv) and rv.status:191 return True192 else:193 raise pythonshare.PythonShareError(rv.errormsg)194 def import_ns(self, namespace):195 """196 """197 pythonshare._send(Request_ns(namespace), self._to_server)198 rv = pythonshare._recv(self._from_server)199 if isinstance(rv, Ns_rv) and rv.status:200 return True201 else:202 raise pythonshare.PythonShareError(rv.errormsg)203 def drop_ns(self, namespace):204 """Delete namespace from the remote peer205 Parameters:206 namespace (string)207 Namespace to be dropped, can be local or208 remote to the server.209 Returns True on success or raises an exception.210 """211 pythonshare._send(Drop_ns(namespace), self._to_server)212 rv = pythonshare._recv(self._from_server)213 if isinstance(rv, Ns_rv) and rv.status:214 return True215 else:216 raise pythonshare.PythonShareError(rv.errormsg)217 def unlock_ns(self, namespace):218 """Unlock namespace on the remote peer219 Parameters:220 namespace (string)221 Namespace to be unlocked, can be local or222 remote to the server.223 Returns True on success or raises an exception.224 """225 pythonshare._send(Server_ctl("unlock", namespace), self._to_server)226 rv = pythonshare._recv(self._from_server)227 if isinstance(rv, Server_ctl_rv) and rv.status == 0:228 return True229 else:230 raise pythonshare.PythonShareError(rv.message)231 def poll_rvs(self, namespace=None):232 """Poll available async return values from namespace.233 Parameters:234 namespace (string, optional)235 namespace from which return values are queried.236 The default is returned by namespace().237 Example:238 rv = c.eval_("time.sleep(1)", async=True)239 print c.poll_rvs(rv.ns)240 time.sleep(1)241 print c.poll_rvs(rv.ns)242 print c.read_rv(rv)243 """244 return self.eval_in(namespace, "pythonshare_ns.poll_rvs()",245 async=False, lock=False)246 def close(self):247 pythonshare._check_hook("before:client.socket.close", {"socket": self._s})248 pythonshare._close(self._to_server, self._from_server, self._s)249 def kill_server(self, namespace=None):250 """Send server shutdown message"""251 if namespace == None:252 namespace = self.namespace()253 pythonshare._send(Server_ctl("die", namespace), self._to_server)254 return True255 def ls_local(self):256 """List local namespaces on the server"""...

Full Screen

Full Screen

RV.py

Source:RV.py Github

copy

Full Screen

...5import astropy.units as u6import astropy.constants as const7##This sctipt will compute the mass and radius of our planet8#Uses the results of our lightcurve analysis.9def read_rv():10 ##Reads in RV data11 ##returns arrays of times and radial velocities12 fname = "RV_data.txt"13 f = open(fname)14 time = []15 rv = []16 17 18 for i in f.readlines():19 if i[0] == "#":20 continue21 22 time.append(float(i.split()[0]))23 rv.append(float(i.split()[1]))24 25 26 27 return time , rv28 29def Prior(X):30 #I ultimately decided to use a uniform prior here31 return 132 33def lsq(X , D):34 ##A least-squares based fitting function.35 t = D[0]36 rv = D[1]37 38 ls = 039 for i in range(len(t)):40 ls += ( X[2] * np.sin(t[i] * 2 * np.pi / X[0] + X[1]) - rv[i]) ** 241 42 return -1 * ls * Prior(X)43 44def Q(X):45 ##This is our sampling distribution46 47 cov = [ [0.08 , 0 , 0] , [0, 1e-1 ,0 ] , [0 , 0 , 10 ] ]48 mean = [0 , 0 , 0]49 Y = X + np.random.multivariate_normal(mean , cov)50 51 52 while min(Y) < 0:53 Y = X + np.random.multivariate_normal(mean , cov)54 55 return Y56 57def plot_fit(t , rv , X):58 ##This code will plot our raadial velocity data set and our fit to the data59 60 fx = []61 fy = []62 63 for i in np.linspace(t[0] , t[-1] , 10000):64 fx.append(i)65 fy.append(X[2] * np.sin(i * 2 * np.pi / X[0] + X[1]))66 #print (fy)67 plt.plot(fx , fy)68 plt.scatter(t , rv)69 plt.show()70 71def measure():72 ##Measures and returns our R and M estimate73 tr = 2454955.78837374 75 phi = tr * 2 * np.pi / (3.55)76 77 t , rvel = read_rv()78 79 DI = 0.004380 Rstar = 1.7981 82 Rp = np.sqrt(Rstar ** 2 * DI)83 84 print (Rp)85 86 87 88 x0 = [3.55 , 4.34505429e+06 , 2.50998989e+02]89 opt = MCMC.MCMC(lsq , [t , rvel] )90 opt.M_H(Q , 5000 , x0 )91 print (opt.MAP , opt.MAPL)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful