Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
petitebete
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pacome Riobe
petitebete
Commits
a2905cc0
Commit
a2905cc0
authored
1 month ago
by
Pacome Riobe
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File : reads
parent
c37065e6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
reads.py
+83
-0
83 additions, 0 deletions
reads.py
with
83 additions
and
0 deletions
reads.py
0 → 100644
+
83
−
0
View file @
a2905cc0
import
gzip
from
Bio
import
SeqIO
class
Read_file
:
"""
Represente un fichier compressé fasta ou fastq, contenant un ou plusieurs reads
"""
def
__init__
(
self
,
file
:
str
):
"""
constructeur d
'
un objet Read
:param file: str, le chemin vers un fichier compressé fastq ou fasta
"""
self
.
it
=
None
self
.
file
=
file
self
.
extension
=
"
rt
"
if
'
fastq.gz
'
in
self
.
file
:
self
.
method
=
"
fastq
"
if
'
.fna.gz
'
in
self
.
file
or
'
.fasta
'
in
self
.
file
:
self
.
method
=
"
fasta
"
def
__len__
(
self
)
->
int
:
"""
permet de compter le nombre de reads dans un objet Read
:return: int
"""
count
=
0
with
gzip
.
open
(
self
.
file
,
self
.
extension
)
as
fichier
:
for
_
in
SeqIO
.
parse
(
fichier
,
self
.
method
):
count
+=
1
return
count
def
next
(
self
):
"""
appelle l
'
itérateur
:return: it
"""
with
gzip
.
open
(
self
.
file
,
self
.
extension
):
return
next
(
self
.
it
)
def
get_read
(
self
,
nb
:
int
)
->
str
:
"""
renvoie la sequence du read voulue selon sa position dans le fichier
:param nb: int, une position
:return:
"""
with
gzip
.
open
(
self
.
file
,
self
.
extension
)
as
fichier
:
record
=
SeqIO
.
parse
(
fichier
,
self
.
method
)
for
_
in
range
(
0
,
(
nb
-
1
)):
record
.
__next__
()
return
str
(
record
.
__next__
().
seq
)
def
fin
(
self
):
count
=
0
while
count
<
len
(
self
.
file
):
seq
=
self
.
next
()
kmer
=
seq
.
kmers
()
def
concat_fasta
(
self
,
output
):
"""
:param output:
:return:
"""
with
open
(
output
,
"
w
"
)
as
out_fasta
:
with
gzip
.
open
(
self
.
file
,
self
.
extension
)
as
fichier
:
record
=
SeqIO
.
parse
(
fichier
,
self
.
method
)
for
n
in
range
(
0
,
self
.
__len__
()):
out_fasta
.
write
(
str
(
record
.
__next__
().
seq
))
print
(
f
"
fin, resultat dans
{
output
}
"
)
if
__name__
==
"
__main__
"
:
G
=
"
/home/m1miso/pacome.riobe.etu/PycharmProjects/pythonProject_petitebete/petitgenome.fna.gz
"
Q
=
"
/home/m1miso/pacome.riobe.etu/PycharmProjects/pythonProject_petitebete/petitquery.fastq.gz
"
genome
=
Read_file
(
G
)
query
=
Read_file
(
Q
)
print
(
"
___
"
)
print
(
"
len
"
)
print
(
"
___
"
)
print
(
query
.
__len__
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment