-1

Structure of fasta file is like this:

>gi|568815364|ref|NT_077402.3| Homo sapiens chromosome 1 genomic scaffold, GRCh38 Primary Assembly HSCHR1_CTG1
TAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAAC
CCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCAACCCTAACCCTAACCCTAACCCTAACCCTAA
CCCTAACCCCTAACCCTAACCCTAACCCTAACCCTAACCTAACCCTAACCCTAACCCTAACCCTAACCCT
AACCCTAACCCTAACCCTAACCCCTAACCCTAACCCTAAACCCTAAACCCTAACCCTAACCCTAACCCTA
ACCCTAACCCCAACCCCAACCCCAACCCCAACCCCAACCCCAACCCTAACCCCTAACCCTAACCCTAACC

The first line is some information about the content of file and rest lines are strand of DNA, RNA or amino acid. To do some work with this kind of file I need to remove first line of file. How can I do this using python? I tried this code, but its not suitable:

My_string=open("SimpleFastaFile.fa", "r").read()
def line_remove(str):
    if str.isalnum()==False:
        str=str[1:]
        line_remove(str)

line_remove(My_string)

2 Answers2

0

you can use next to advanced pointer to nextline:

my_string = open("SimpleFsastaFile.fa", "r")
next(my_string)                  # advanced file pointer to next line
my_string.read()
Hackaholic
  • 19,069
  • 5
  • 54
  • 72
-1

If you need the whole file's content, why not read all lines at once and immediately slice away the first line?

with open('path','r') as f:
    content = f.readlines()[1:]
output="".join(content)
Malhelo
  • 399
  • 6
  • 16
  • It converts the file to a list of lines, I want it as a string finally –  Dec 20 '14 at 11:29
  • Simply drop the first line using `next(f)`. – Ashwini Chaudhary Dec 20 '14 at 11:42
  • I'd love to know why I got a downvote when the answer is clearly correct and works (and add the value of getting the file content minus the first line as string). The answer is thus not an exact duplicate of the linked question's answers. – Malhelo Dec 22 '14 at 02:30