0

I'm working with DNA sequence data in a program called ObiTools. I would like to find a way to repeat a command for every set of files within the same folder.

For example, if I have the files

Sequence_A1_R1.fastq,
Sequence_A1_R2.fastq,
Sequence_A2_R1.fastq,
Sequence_A2_R2.fastq,
etc.

I would like to run the following command for every value of X, such that X is always the same value (no combination of different values).

illuminapairedend Sequence_X_R1.fastq Sequence_X_R2.fastq > Sequence_X_pairedend.fastq

Is there a python script that could easily do this?

Thanks

Prune
  • 72,213
  • 14
  • 48
  • 72
  • Please use code blocks instead of quotation blocks. Also, provide a concrete example of what commands would be run for your set of concrete example files. – Alyssa Haroldsen Mar 02 '16 at 23:07
  • Is this a command line thing? You might try tagging your question with [shell] or [bash] or [batch] if it's windows. "Running a command" on files like that would be much easier at that level. – aghast Mar 02 '16 at 23:27

1 Answers1

0

Assuming your files are in file_list and already captive in earlier Python code, you could do something like this:

for file_pos in range(0, len(file_list), 2): command = "illuminapairedend " + file_list[file_pos] + file_list[file_pos + 1] + "> Sequence_X_pairedend.fastq" os.system(command)

This last command is covered thoroughly here


This is best only if you acquire the file list in Python. If the file list comes from elsewhere, it's almost certainly better to write the script in your command shell: bash, for example.

Community
  • 1
  • 1
Prune
  • 72,213
  • 14
  • 48
  • 72