Sunday, August 26, 2018

Matching alphanumeric string in PERL

 
if($_ =~ /[a-zA-Z]+/ && $_ =~ /[0-9]+/)


$_ : the string in default variable
=~ : should match
a-zA-Z: lower case and uppercase
+ : more than once
&&: as well as
0-9: numbers

Connection timed out; no servers could be reached - CentOS - Solved

For some reason, could not connect access internet in CentOS, although my network shows connected. 
$ nslookup google.com
;; connection timed out; no servers could be reached
 
$ ping www.google.com
ping: www.google.com: Name or service not known

$ ping 8.8.8.8

From XX.XX.X.X icmp_seq=1 Destination Net Unreachable
From XX.XX.X.X icmp_seq=2 Destination Net Unreachable
From XX.XX.X.X icmp_seq=3 Destination Net Unreachable
From XX.XX.X.X icmp_seq=4 Destination Net Unreachable
 
then, from an online post, I understand that /etc/sysconfig/network should have following:  
$ cat /etc/sysconfig/network
NETWORKING=yes
 
When I checked my /etc/sysconfig/network, it was empty. Soon, I updated it with   
NETWORKING=yes 
GATEWAY=XX.XX.X.X (filled with my IP address)
and restarted my system again, which works now without problem!! 
$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=27.6 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=39.6 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=117 time=29.8 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=117 time=62.9 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=117 time=35.4 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=117 time=18.7 ms
^C
--- 8.8.8.8 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5009ms

Wednesday, August 22, 2018

Sunday, August 19, 2018

Gene Ontology information from Uniport IDs


1) Go to https://www.uniprot.org/uploadlists/, paste your identifiers and submit



2) Once you get results, click Gene Ontology on the left side to gene ontology annotations.




 3) Check the results by clicking the "+" button. Once it expands you can see more details




 4) Once it expands you can see more details like below:



Thursday, August 9, 2018

Generate combinations from a item list in BASH + Ignore same pairs

View the contents of the file using cat command

$ cat list
Pair1
Pair2
Pair3
Pair4

A bash "for" loop in another "for" helps + AWK resolves the issue

$ for d in $(cat list); do for i in $(cat list); do echo "$d $i"; done done | awk '$1 != $2'

Pair1 Pair2
Pair1 Pair3
Pair1 Pair4
Pair2 Pair1
Pair2 Pair3
Pair2 Pair4
Pair3 Pair1
Pair3 Pair2
Pair3 Pair4
Pair4 Pair1
Pair4 Pair2
Pair4 Pair3

Sequence lengths from AWK one-liner


$ awk '/^>/ {if (sqlen){print sqlen}; print ;sqlen=0;next; } { sqlen = sqlen +length($0)}END{print sqlen}' db4_cdc_NDM_only.fasta | sed 's/>//g' | paste - - 

ref|NZ_CP029245.1| Escherichia_coli_strain_ECCRA-119_plasmid_pTB203,_complete_sequence 46161
ref|NZ_CP029386.1| Klebsiella_pneumoniae_subsp._pneumoniae_strain_SCKP040074_plasmid_pNDM6_040074,_complete_sequence 52989
ref|NZ_CP029731.1| Citrobacter_sp._CRE-46_strain_AR_0157_plasmid_unnamed3,_complete_sequence 108148
ref|NZ_CP029737.1| Providencia_rettgeri_strain_AR_0082_plasmid_unnamed,_complete_sequence 144970
ref|NZ_CP029978.1| Escherichia_coli_strain_51008369SK1_plasmid_p51008369SK1_E,_complete_sequence 99465
ref|NZ_KM923969.1| Acinetobacter_dijkshoorniae_strain_JVAP01_plasmid_pNDM-JVAP01,_complete_sequence 47268

Friday, August 3, 2018

Setting up AWS CLI and Downloading S3 Files using command line interface

1. Install the AWS Command Line Interface (CLI) using:

$ pip install awscli 


For more details such as upgrade, check the amazon webpage here.

Note: if installation was not successful, reinstall forcefully. Check here

The next step is to configure. AWS requires the following items for this:
(how to find these?)
  1. Access key ID
  2. Secret Access key
  3. Region name
  4. Valid output format
2. Configuration

Now, run the following command and answer the prompts:

$ aws configure
 
AWS Access Key ID [None]: <enter the access key>
AWS Secret Access Key [None]: <enter the secret access key>
Default region name [None]: <enter region>
Default output format [None]: <text>


3. Copying files from AWS S3 folder to Local Desktop 

once this is done, we can start using AWS CLI for the file operations. For example, if it want to copy WBB3097.gz file in my AWS account to my local desktop, which is under "qgen" username and in the folder MIX7341, I do the following

$ aws s3 cp s3:URI  <Local Desktop Location>

$ aws s3 cp s3://qgen/MIX7341/WBB3097.gz ~/Desktop/AWS

4. List all files in AWS S3 folder 

Similarly to list all the files in the MIX7341, we can use the following command


$ aws s3 ls s3://qgen/MIX7341/

2018-08-02 11:03:58  459407360 WBB3066.gz
2018-08-02 11:03:01  337848320 WBB3067.gz
2018-08-02 11:02:57  327219200 WBB3068.gz
2018-08-02 11:02:57  298680320 WBB3069.gz
2018-08-02 11:02:57  280514560 WBB3070.gz

5. Copy multiple files using BASH for loop

Off hand, I had to download multiple files from AWS account. To click each file and download was taking time. So, I just listed the files (step1 below) and used "for loop" in bash to download the files (step2 below).


$ aws s3 ls s3://qgen/MIX7341/ | awk '{print $NF}' >files_in_AWS.list ##step 1

$ for d in $(cat files_in_AWS.list); do echo $d; aws s3 cp s3://qgen/MIX7341/$d . ; done ##step 2




border:solid green;border-width:.1em .1em .1em .8em;padding:.2em .6em;
Python ; Pastie ; www. hilitie.me

Thursday, August 2, 2018

ImportError: No module named botocore.session - Solved

My aws cli had some installation problems and ended up using the following error


$ aws

Traceback (most recent call last):

  File "/usr/bin/aws", line 19, in <module>

    import awscli.clidriver

  File "/usr/lib/python2.7/site-packages/awscli/clidriver.py", line 17, in <module>

    import botocore.session

ImportError: No module named botocore.session

Running the following command fixed the problem:


$ sudo pip install awscli --force-reinstall --upgrade

Collecting awscli

  Using cached https://files.pythonhosted.org/packages/18/99/a1a1ea5a91161d5be5f434550ac1de800d79da7d4f68a5b5c8f265fcbd58/awscli-1.15.70-py2.py3-none-any.whl

Collecting s3transfer<0.2.0,>=0.1.12 (from awscli)

  Using cached https://files.pythonhosted.org/packages/d7/14/2a0004d487464d120c9fb85313a75cd3d71a7506955be458eebfe19a6b1d/s3transfer-0.1.13-py2.py3-none-any.whl

Collecting colorama<=0.3.9,>=0.2.5 (from awscli)

  Using cached https://files.pythonhosted.org/packages/db/c8/7dcf9dbcb22429512708fe3a547f8b6101c0d02137acbd892505aee57adf/colorama-0.3.9-py2.py3-none-any.whl

Collecting rsa<=3.5.0,>=3.1.2 (from awscli)

  Using cached https://files.pythonhosted.org/packages/e1/ae/baedc9cb175552e95f3395c43055a6a5e125ae4d48a1d7a924baca83e92e/rsa-3.4.2-py2.py3-none-any.whl

Collecting docutils>=0.10 (from awscli)

  Using cached https://files.pythonhosted.org/packages/50/09/c53398e0005b11f7ffb27b7aa720c617aba53be4fb4f4f3f06b9b5c60f28/docutils-0.14-py2-none-any.whl

Collecting PyYAML<=3.13,>=3.10 (from awscli)

  Downloading https://files.pythonhosted.org/packages/9e/a3/1d13970c3f36777c583f136c136f804d70f500168edc1edea6daa7200769/PyYAML-3.13.tar.gz (270kB)

    100% |████████████████████████████████| 276kB 2.8MB/s

Collecting botocore==1.10.69 (from awscli)

  Using cached https://files.pythonhosted.org/packages/45/f3/0e5006bc6198213b853ca3975c537335a91716ffa1ed768e2b2ffe12d7ed/botocore-1.10.69-py2.py3-none-any.whl

Collecting futures<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" (from s3transfer<0.2.0,>=0.1.12->awscli)

  Using cached https://files.pythonhosted.org/packages/2d/99/b2c4e9d5a30f6471e410a146232b4118e697fa3ffc06d6a65efde84debd0/futures-3.2.0-py2-none-any.whl

Collecting pyasn1>=0.1.3 (from rsa<=3.5.0,>=3.1.2->awscli)

  Downloading https://files.pythonhosted.org/packages/d1/a1/7790cc85db38daa874f6a2e6308131b9953feb1367f2ae2d1123bb93a9f5/pyasn1-0.4.4-py2.py3-none-any.whl (72kB)

    100% |████████████████████████████████| 81kB 3.5MB/s

Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.10.69->awscli)

  Using cached https://files.pythonhosted.org/packages/b7/31/05c8d001f7f87f0f07289a5fc0fc3832e9a57f2dbd4d3b0fee70e0d51365/jmespath-0.9.3-py2.py3-none-any.whl

Collecting python-dateutil<3.0.0,>=2.1; python_version >= "2.7" (from botocore==1.10.69->awscli)

  Using cached https://files.pythonhosted.org/packages/cf/f5/af2b09c957ace60dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825/python_dateutil-2.7.3-py2.py3-none-any.whl

Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1; python_version >= "2.7"->botocore==1.10.69->awscli)

  Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl

Building wheels for collected packages: PyYAML

  Running setup.py bdist_wheel for PyYAML ... done

  Stored in directory: /root/.cache/pip/wheels/ad/da/0c/74eb680767247273e2cf2723482cb9c924fe70af57c334513f

Successfully built PyYAML

ipaclient 4.5.4 requires jinja2, which is not installed.

rtslib-fb 2.1.63 has requirement pyudev>=0.16.1, but you'll have pyudev 0.15 which is incompatible.

ipapython 4.5.4 has requirement dnspython>=1.15, but you'll have dnspython 1.12.0 which is incompatible.

Installing collected packages: futures, jmespath, docutils, six, python-dateutil, botocore, s3transfer, colorama, pyasn1, rsa, PyYAML, awscli

  Found existing installation: futures 3.2.0

    Uninstalling futures-3.2.0:

      Successfully uninstalled futures-3.2.0

  Found existing installation: jmespath 0.9.3

    Uninstalling jmespath-0.9.3:

      Successfully uninstalled jmespath-0.9.3

  Found existing installation: docutils 0.14

    Uninstalling docutils-0.14:

      Successfully uninstalled docutils-0.14

  Found existing installation: six 1.9.0

    Uninstalling six-1.9.0:

      Successfully uninstalled six-1.9.0

  Found existing installation: python-dateutil 2.7.3

    Uninstalling python-dateutil-2.7.3:

      Successfully uninstalled python-dateutil-2.7.3

  Found existing installation: botocore 1.10.69

    Uninstalling botocore-1.10.69:

      Successfully uninstalled botocore-1.10.69

  Found existing installation: s3transfer 0.1.13

    Uninstalling s3transfer-0.1.13:

      Successfully uninstalled s3transfer-0.1.13

  Found existing installation: colorama 0.3.9

    Uninstalling colorama-0.3.9:

      Successfully uninstalled colorama-0.3.9

  Found existing installation: pyasn1 0.1.9

    Uninstalling pyasn1-0.1.9:

      Successfully uninstalled pyasn1-0.1.9

  Found existing installation: rsa 3.4.2

    Uninstalling rsa-3.4.2:

      Successfully uninstalled rsa-3.4.2

  Found existing installation: PyYAML 3.10

Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

You are using pip version 10.0.1, however version 18.0 is available.

You should consider upgrading via the 'pip install --upgrade pip' command.

 

$ aws
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]

To see help text, you can run:


  aws help

  aws <command> help

  aws <command> <subcommand> help

aws: error: too few arguments

 

We can check  aws version as following:


$ aws --version

aws-cli/1.15.70 Python/2.7.5 Linux/3.10.0-693.17.1.el7.x86_64 botocore/1.10.69
 

Thats it ! We can now use AWS CLI to access the buckets in our AWS console account. :)