Off topic: How do I count a number of ("-") in a reference string and remove it in a second string?
1
0
Entering edit mode
11 months ago
USER • 0

When counting the number of characters at the beginning of a string or the end of a string, the result is 0. What do I do?

f = open('Denv4-X-gb_AY947539.txt', 'r') 
z = f.read()
e = sum(1 for _ in it.takewhile(lambda c: c == '-', z)) 
y = sum(1 for_ in it.takewhile(lambda c: c == '-', reversed(z)))
print(e,y)

Output:

> 0

The file is being read normally ....

What's in the file:

>lcl|NC_002640.1_cds_NP_073286.1_1 [gene=POLY] [locus_tag=DV4_gp1] [db_xref=GeneID:5075729] [protein=polyprotein] [protein_id=NP_073286.1] [location=102..10265] [gbkey=CDS]
------------------------------------------------------------
---------------------------------atgaaccaacgaaaaaaggtggttaga             
ccacctttcaatatgctgaaacgcgagagaaaccgcgtatcaacccctcaagggttggtg
aagagattctcaaccggacttttttctgggaaaggacccttacggatggtgctagcattc
atcacgtttttgcgagtcctttccatcccaccaacagcagggattctgaagagatgggga
cagttgaagaaaaataaggccatcaagatactgattggattcaggaaggagataggccgc
------------------------------------------------------------
>gb:AY947539|Organism:Dengue virus 4|Strain Name:H241|Segment:null|Subtype:4|Host:Human
ggtcgtgtggaccgacaaggacagttccaaatcggaagcttgcttaacacagttctaaca
gtttgtttagatagagagcagatctctggaaaaatgaaccaacgaaaaaaggtggttaga
ccacctttcaatatgctgaaacgcgagagaaaccgcgtatcaacccctcaagggttggtg
aagagattctcaaccggacttttttccgggaaaggacccttacggatggtgctagcattc
atcacgtttttgcgagtcctttccatcccaccaacagcagggattctgaaaagatgggga
cagttgaagaaaaacaaggccatcaaaatactgactggattcaggaaggagataggccgc
atgctgaacatcttgaatggaagaaaaaggtcaacaatgacattgctgtgcttgattccc

I would like to know how to print the "-" number at the beginning and end of the first text:

before starting

>lcl|NC_002640.1_cds_NP_073286.1_1 [gene=POLY] [locus_tag=DV4_gp1] [db_xref=GeneID:5075729][protein=polyprotein] [protein_id=NP_073286.1] [location=102..10265] [gbkey=CDS]

Blockquote

>gb:AY947539|Organism:Dengue virus 4|Strain Name:H241|Segment:null|Subtype:4|Host:Human.

.

f = open('Denv4-X-gb_AY947539.txt.txt', 'r')
con = f.readlines()
con = [i.strip() for i in con]
length = len(con[0].split(" ")[1])
result = f'{con[1].split(" ")[0]} {con[1].split(" ")[1][length:]}'
print(result)
f.close()

f = open('file.txt', 'a')
f.write(f'\n{result}')
genome alignment sequence • 335 views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 2211 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