Monday, March 21, 2022

Nextflow: Missing 'bind' declaration in input parameter - resolved

$ time nextflow test4_20200322.nf

N E X T F L O W  ~  version 21.04.3

Launching `test4_20200322.nf` [happy_leakey] - revision: d7d5d88709

reads: /data01/nextflow_test/2022_test/sample_data/*_{1,2}.fastq

Missing 'bind' declaration in input parameter

 -- Check script 'test4_20200322.nf' at line: 9 or see '.nextflow.log' file for more details


Paste this line at the 2nd line : nextflow.enable.dsl=2




Tuesday, February 15, 2022

Tips for uploading data to NCBI SRA

 ### Case: 

So, If have 20 bacterial samples, then I will have 20 x 2 = 40 fastq files for Illumina paired data and 20 x 1 = 20 fastq files for Nanopore data that I need to upload.

1) Create a Bioproject (Get the Bioproject accession)

2) Create a Biosample (Use Bioproject accession to fill the Microbe template (template depends on the organism bacterial in this case;can be downloaded from NCBI only as going through the steps)

3) For Illumina data 

   - Create a SRA submission 1

   - Need to fill the metadata template using the SAMN numbers generated from Biosample submission.

   - Upload the data either using aspera or FTP.

4) For Nanopore data 

   - Create a SRA submission 2

   - Need to fill the metadata template using the SAMN numbers generated from Biosample submission.

   - Upload the data either using aspera or FTP.



# Pointers:

1. Always best to create a bioproject first and get PRJNA number

2. Then create a BioSample project - in the Microbe1.0 excel provide the Bioproject (PRJNA) number

3. Then do the SRA submission.

4. For the SRA submission, if you have two types of data such as Ilumina and Nanopore sequences for the same sample, then in the SRA_meta_acc file have the Illumina information and followed by nanopore details. 

5. The SAM number (Biosample number) will be same for both Illumina and Nanopore data

6. If your data samples are more than 1000, then single submission is not possible in NCBI. So you have to split the data accordingly.

7. aspera command line seems a bit confusing to use, ftp seems to be straightforward. Just need to get username password from SRA submission

8. Advantage with ftp is: Even if sometimes the internet connection drops, we can resume from where transfer stopped

9. We cannot upload half of our data with FTP and half of our data aspera. It is either aspera or FTP. 

Wednesday, January 12, 2022

Extract accessory genes as fasta files from the roary output for downstream functional characterization


1. First generate the locus_tag of the accessory genes (output file: pan_genome_results)
query_pan_genome -a complement -g clustered_proteins *.gff
mv pan_genome_results accessory_genome_locus_tags.list
2. Use the locus_tags of the accessory genes to extract the sequences from prokka folder
fgrep 'locus_tag=' *.gff >Combined_local_gffs.txt # search 'locus_tag' in all gff file and combine - for speeding purpose

time for locus_tag in $(awk '{print $2}' accessory_genome_locus_tags.list); do 
file=`fgrep -m1 "$locus_tag" Combined_local_gffs.txt | awk -F':' '{print $1}' | sed 's/.gff//g'`; # extract the samplename (foldername) where the gene is present
awk -v var="$locus_tag" 'BEGIN {RS=">"} $0~var {print ">"$0}' Prokka/MySampleFolders/"$file"_prokka_out/"$file".ffn >accessory_gene_representatives/"$locus_tag".fasta;  
done 

These genes can be combined and can be functionally characterised for downstream analysis

Extracting 5477 genes took me around ~19 mins by this way

Sunday, December 19, 2021

Add file name after ">" in a multi fasta file

More solutions here: https://www.biostars.org/p/435813/


awk '/>/{sub(">","&"FILENAME"_");sub(/\.fasta/,x)}1'  assembly.fasta | sed 's/ /_/g' | grep '>'

Wednesday, December 15, 2021

Dowloading raw fastq data from European Nucleotide Archive (ENA) using ERR IDs

 Step1: Paste the comma separated ERR IDs in the address bar like this:

https://www.ebi.ac.uk/ena/browser/view/ERR3417384,ERR3418576,ERR3418577,ERR3307235?show=reads


Step 2: This will list the ID in the webpage like this:



Step 3: Click Download XML file - this downloaded ena_data_20211215-0958.xml file on to my desktop

Step 4: In the linux terminal:

$ fgrep 'filename="run' ena_data_20211215-0958.xml | 
sed -e 's/.*run/ftp.sra.ebi.ac.uk\/vol1\/run/g' -e 's/\".*//g' >downloadlinks.list


Step 5 : Looping through the links and using wget command from linux, we can download like this:

$ time for d in $(cat downloadlinks.list); do echo $d; wget $d; done

Step 6 : But, wget command was very slow and reconnecting many times like this:

--2021-12-16 09:50:41--  (try:13)  http://ftp.sra.ebi.ac.uk/vol1/run/ERR329/ERR3297045/1_P_PA_1.fastq.gz
Connecting to ftp.sra.ebi.ac.uk (ftp.sra.ebi.ac.uk)|193.62.197.74|:80... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 1842088178 (1.7G), 606664946 (579M) remaining [application/octet-stream]
Saving to: ‘1_P_PA_1.fastq.gz’

1_P_PA_1.fastq.gz                                     67%[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                                       ]   1.15G  --.-KB/s    in 15m 0s  

2021-12-16 10:05:43 (0.00 B/s) - Read error at byte 1235423232/1842088178 (Connection timed out). Retrying.

--2021-12-16 10:05:53--  (try:14)  http://ftp.sra.ebi.ac.uk/vol1/run/ERR329/ERR3297045/1_P_PA_1.fastq.gz
Connecting to ftp.sra.ebi.ac.uk (ftp.sra.ebi.ac.uk)|193.62.197.74|:80... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 1842088178 (1.7G), 606664946 (579M) remaining [application/octet-stream]
Saving to: ‘1_P_PA_1.fastq.gz’

1_P_PA_1.fastq.gz                                     67%[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                                       ]   1.15G  --.-KB/s    in 15m 0s  

2021-12-16 10:20:54 (0.00 B/s) - Read error at byte 1235423232/1842088178 (Connection timed out). Retrying.

--2021-12-16 10:21:04--  (try:15)  http://ftp.sra.ebi.ac.uk/vol1/run/ERR329/ERR3297045/1_P_PA_1.fastq.gz
Connecting to ftp.sra.ebi.ac.uk (ftp.sra.ebi.ac.uk)|193.62.197.74|:80... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 1842088178 (1.7G), 606664946 (579M) remaining [application/octet-stream]
Saving to: ‘1_P_PA_1.fastq.gz’

1_P_PA_1.fastq.gz                                     81%[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++================>                      ]   1.40G  --.-KB/s    in 26m 54s 

So, used aspera pluggin to download at better speed.

Step 7:  Locate asperaweb_id_dsa.openssh in ubuntu. The absolute path is required for the next step

$ locate asperaweb_id_dsa.openssh
/home/user/.aspera/connect/etc/asperaweb_id_dsa.openssh

Step 8: parsing the downloadlinks.list and creating a new file for aspera download.


$ cat downloadlinks.list | sed 's/ftp.sra.ebi.ac.uk\/vol1\/run\///g' >downloadlinks_ascp.list

$ time for d in $(cat downloadlinks_ascp.list); do echo $d; ascp -v -l 300m -P33001 -i /home/prakki/.aspera/connect/etc/asperaweb_id_dsa.openssh era-fasp@fasp.sra.ebi.ac.uk:vol1/run/$d /ena/download/folder/ ; done





Wednesday, November 24, 2021

Downloading raw fastq data from NCBI SRA

  • Go to PRJNA (for example: https://www.ncbi.nlm.nih.gov/bioproject/PRJNA656645)
  • Click  "299" under Number of links for row SRA Experiments

  • Click "RunInfo" under, file and "Create File"


  • We need SRR numbers, something like this:
  • Assuming the above SRR accessions are in a file (SRR.list), we can run the following command:

time for d in $(cat SRR.list); do time prefetch -v $d; done &


  • Now, we convert the sra file to fastq:
time for d in $(ls */*.sra);do fastq-dump --outdir fastq --split-files $d; done

Sunday, September 26, 2021

Running multiple parallel scripts from a bash script using GNU parallel

 Supposedly, if we want to run any perl/any language program in bash on mutiple input files (say 1000 inputs files) and if the number of threads in my computer is either 48 or 64 only, sometimes there might be overload which can lead to Resource temporarily unavailable error.

So, to circumvent this problem, we want to run a batch of 48 scripts/commands parallely without overloading the resources. This can be done using GNU parallel. The advantage of GNU parallel is, By default, parallel runs as many jobs in parallel as there are CPU cores.

In order to do this, we will create a file with commands and pass it to GNU parallel.

time for d in $(ls */*fq); 

do 

echo "perl /storage/apps/SNP_Validation_Scripts/tools/Q20_Q30_Stats_wo_functions.pl $d";

 done >parallel_script_Q20_Q30_stats.sh


parallel < parallel_script_Q20_Q30_stats.sh

And thats it! 

Tuesday, September 21, 2021

Upgrade R version 3.5 to 4.1 in CentOS 7

$ sudo yum update R
 

$ yum list installed | grep R
$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
 

$ sudo yum install yum-utils
$ sudo yum-config-manager --enable "rhel-*-optional-rpms"
 

$ export R_VERSION=4.1.1
$ curl -O https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
$ sudo yum install R-${R_VERSION}-1-1.x86_64.rpm

$ /opt/R/${R_VERSION}/bin/R --version
R version 4.1.1 (2021-08-10) -- "Kick Things"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

$ sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R

$ sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript


# Let's check the R version is changed

$ R

R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-conda_cos6-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

# Looks like the we have to create a softlink of R 4.1 instead of R 3.5 which is at:


$ which R

/storage/apps/anaconda3/bin/R

# change the R3.5 version softlinkname
$ sudo mv /storage/apps/anaconda3/bin/R /storage/apps/anaconda3/bin/R3.5

# softlink
$ sudo ln -s /opt/R/${R_VERSION}/bin/R /storage/apps/anaconda3/bin/R

# Now we have latest R version
$ R --version
R version 4.1.1 (2021-08-10) -- "Kick Things"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.


Wednesday, September 8, 2021

BEAST - ESS of combined logs vs ESS of individual run logs

Sometimes, when running BEAST, it is seen that ESS values of the individual runs is not > 200 but the combined ESS of all the independent runs is > 200 and traces of three independent runs converge in the combined trace. Is it acceptable then to use combined estimate of parameters such as mutation rate?


Here is an answer from BEAST author:

https://groups.google.com/g/beast-users/c/b11vV19nqkI

User:

Is it acceptable to use an estimate of say, TMRCA, from the combined analysis of three identical runs (from different random seeds) if the ESS is >200 for all parameters in the combined file (but not in each individual file) in Tracer?

Or do I need to do that three times (for a total of 9 runs) and use log combiner to combine the nine files?

alexei....@gmail.com

3 runs combined to give an ESS of >200 is probably safe but you need to be a little bit careful. 10 runs to get an ESS of >200 is probably not safe because if individual runs are given ESS estimates of about 20 then there is a question of whether those ESS estimates are valid at all. You should use Tracer to visually inspect that your 3 runs are giving essentially the same answers for all the parameters and the likelihood and prior. The traces should substantially overlap and given basically the same mean and variance. If your three runs give traces that don't overlap then you can't combine them no matter what the combined ESS says! 

Cheers

Alexei

  



Wednesday, June 9, 2021

Mob_suite ERROR: Downloading databases failed, please check your internet connection and retry - Resolved

 2021-06-09 14:18:11,612 mob_suite.utils ERROR: Downloading databases failed, please check your internet connection and retry [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:226]

2021-06-09 14:18:11,612 mob_suite.utils ERROR: Process failed with error [Errno 2] No such file or directory: 'mash': 'mash'. Removing lock file [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:227]


Some solutions to try at:

https://githubmemory.com/repo/phac-nml/mob-suite/issues/86


Mine specifically looks like mash is not installed so msh file is not generated causing the error.


$ conda install -c bioconda mash

$ mob_init 

2021-06-09 14:51:02,838 mob_suite.utils INFO: Database directory folder already exists at /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/databases [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:133]

2021-06-09 14:51:02,838 mob_suite.utils INFO: Placed lock file at /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/databases/.lock [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:144]

2021-06-09 14:51:02,838 mob_suite.utils INFO: Initializing databases...this will take some time [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:167]

2021-06-09 14:51:02,838 mob_suite.utils INFO: Downloading databases...this will take some time [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:180]

2021-06-09 14:51:02,838 mob_suite.utils INFO: Trying mirror https://share.corefacility.ca/index.php/s/oeufkw5HyKz0X5I/download [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:184]

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100  214M  100  214M    0     0  3638k      0  0:01:00  0:01:00 --:--:-- 3942k

2021-06-09 14:52:04,226 mob_suite.utils INFO: Download data.zip sha256 checksum is 92a9008caa2bbc273bdb9cb76c5df001f25d71be819fa85a19f7e6d13e56073c [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:68]

2021-06-09 14:52:04,227 mob_suite.utils INFO: Download data.zip size in bytes is 225377917 [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:69]

2021-06-09 14:52:04,241 mob_suite.utils INFO: Downloading databases successful, now building databases [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:198]

2021-06-09 14:52:04,241 mob_suite.utils INFO: Decompressing /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/databases/data.zip [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:106]

2021-06-09 14:52:04,932 mob_suite.utils INFO: Decompressing /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/databases/ncbi_plasmid_full_seqs.fas.gz [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:106]

2021-06-09 14:52:12,348 mob_suite.utils INFO: Decompressing /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/databases/orit.fas.gz [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:106]

2021-06-09 14:52:12,350 mob_suite.utils INFO: Decompressing /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/databases/rep.dna.fas.gz [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:106]

2021-06-09 14:52:12,372 mob_suite.utils INFO: Decompressing /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/databases/mob.proteins.faa.gz [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:106]

2021-06-09 14:52:12,381 mob_suite.utils INFO: Decompressing /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/databases/repetitive.dna.fas.gz [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:106]

2021-06-09 14:52:12,460 mob_suite.utils INFO: Decompressing /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/databases/mpf.proteins.faa.gz [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:106]

2021-06-09 14:52:12,477 mob_suite.utils INFO: Building repetitive mask database [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:212]

2021-06-09 14:52:12,696 mob_suite.utils INFO: Building complete plasmid database [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:216]

2021-06-09 14:52:17,531 mob_suite.utils INFO: Sketching complete plasmid database [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:220]

2021-06-09 14:52:23,037 mob_suite.utils INFO: Init ete3 library ... [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:232]

NCBI database not present yet (first time used?)

Downloading taxdump.tar.gz from NCBI FTP site (via HTTP)...

Done. Parsing...

Loading node names...

2334637 names loaded.

247459 synonyms loaded.

Loading nodes...

2334637 nodes loaded.

Linking nodes...

Tree is loaded.

Updating database: /home/prakki/.etetoolkit/taxa.sqlite ...

 2334000 generating entries... 

Uploading to /home/prakki/.etetoolkit/taxa.sqlite


Inserting synonyms:      50000 2021-06-09 14:53:57,919 mob_suite.utils ERROR: Init of ete3 library failed with error UNIQUE constraint failed: synonym.spname, synonym.taxid. Removing lock file [in /home/prakki/sw/pyenv/versions/3.6.4/lib/python3.6/site-packages/mob_suite/mob_init.py:238]

 conda install -c etetoolkit ete3
Collecting package metadata (repodata.json): done
Solving environment: done

Still had this error. So I followed authors instructions to manually install.

You should see taxa.sqlite and taxa.sqlite.traverse.pkl files; d) if all these steps went well then you can generate empty status.txt file in the databases directory by running touch status.txt which would signal successful database init.

Now the mob_typer worked without error!