bash loop to python loop for google colabs
1
0
Entering edit mode
11 months ago
svilla • 0

Hi there,

I have a bash loop to use kallisto on my sequencing samples, but I'm trying now to run kb on google colabs (all the fastq files are on Google drive), so I'd appreciate a hand in 'translating it to python'. Here's the original script:

#
#/bin/bash
FASTQ="/content/drive/My\ Drive/NovaSeq_raw_data/"
##############
cd $FASTQ
for FILE in $(ls *.fastq.gz | rev| cut -c 24- |rev| cut -c 14- |uniq)
do
echo "kallisto for" $FILE
kallisto quant -i $index.idx -o $FILE -b 100 "${FASTQ}WTCHG_702270_${FILE}_1.fastq.gz" "${FASTQ}WTCHG_702270_${FILE}_2.fastq.gz" "${FASTQ}WTCHG_705748_${FILE}_1.fastq.gz" "${FASTQ}WTCHG_705748_${FILE}_2.fastq.gz"
done
python loop kallisto colabs • 1.2k views
ADD COMMENT
0
Entering edit mode

Can you help me with using colab how u downloaded SRA data to google drive?

ADD REPLY
0
Entering edit mode
11 months ago

Untested, but perhaps it might be of use:

#!/usr/bin/env python3

import os
import subprocess

#
# redefine globals, as needed
#
index = "12345"
fastq_dir = "/content/drive/My\ Drive/NovaSeq_raw_data/"

#
# build a set of file keys, truncated per rev-cut-rev-cut-uniq pipeline
#
files = {}
for file in os.listdir(fastq_dir):
  if file.endswith(".fastq.gz"):
    file = file[13:-23]            # i.e., "rev | cut -c 24 - | rev | cut -c 14 -"
    files[file] = True             # i.e., "uniq"

#
# walk through set of file keys; call a kallisto subprocess on each 
#
for file_tuple in files.items():
  file = file_tuple[0]
  print("kallisto for {}".format(file))
  cmd = "kallisto quant -i {}.idx -o {} -b 100 {}WTCHG_702270_{}_1.fastq.gz {}WTCHG_702270_{}_2.fastq.gz {}WTCHG_705748_{}_1.fastq.gz {}WTCHG_705748_{}_2.fastq.gz".format(index, file, fastq_dir, file, fastq_dir, file, fastq_dir, file, fastq_dir, file)
  subprocess.call(cmd, shell=True)

Perhaps use print(variable_name) at various parts to see what variables look like, so that you can be sure that things are formatted properly before running the subprocess.call(...) statement.

ADD COMMENT

Login before adding your answer.

Traffic: 3045 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6