This is a test version of Biostars. For the public version, visit https://www.biostars.org.
remove white space in fastq file

please help remove white space in fastq file

fastq

please help remove white space in fastq file in mac 12.6.9

Note: FASTQ headers might need those spaces, DO NOT REMOVE them unless you fully know what you're doing and why you're doing it.

I am running mapper. pl on mirDeep2-0.1.0 and some sequence files are kicked out with these messages line " Second line of FASTQ reads file contains whitespace in sequence". "Please make sure your file is in accordance with the FASTQ format specifications"

FASTQ should NOT have white spaces in the read sequence line. Do not just remove them, go back to the source and figure out why they have white spaces.

Do you mean empty lines between sequences? Or spaces within the sequences?

To remove empty lines between sequences I've used sed before:

sed -i '/^$/d' your_fastq_file.fastq

No it is spaces within sequences so this answer does not apply.

I am running mapper. pl on mirDeep2-0.1.0 and some sequence files are kicked out with these messages line " Second line of FASTQ reads file contains whitespace in sequence". "

I've moved your post to a comment as it does not answer the top level question.

Not been able to remove white spaces. I would appreciate any other suggestion

Try the following

awk 'NR%4==2 {gsub(" ", "");} {print;}' input.fastq > output.fastq

Replace the names of the files as appropriate.


ChatGPT also suggests this python script

def remove_spaces_from_fastq(input_file, output_file):
    with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
        for line_number, line in enumerate(infile, start=1):
            # Modify the second line (sequence line) by removing spaces
            if line_number % 4 == 2:
                line = line.replace(" ", "")

            # Write the modified or unmodified line to the output file
            outfile.write(line)

if __name__ == "__main__":
    input_fastq = "input.fastq"  # Replace with your input FASTQ file
    output_fastq = "output.fastq"  # Replace with the desired output file name

    remove_spaces_from_fastq(input_fastq, output_fastq)

Save as remove_spaces.py and run.

python remove_spaces.py

NOTE: Pay attention to point @Ram has made a couple of times. If the data is corrupt you are best off procuring a new copy.

ChatGPT hard-coding inputs - looks like it's gone from being a good programmer to being a beginner. Weird AI evolution?

Did you figure out why those white spaces were introduced? Your data is possibly corrupt and you're working to silence the evidence instead of preserving it.

0 answers

No answers yet.

Log in to answer this question.