Opening python file with readlines() method
The folder with this project contains a plain text file with a DNA sequence in fasta format ('MYH7.fasta').
Complete the cell below to open and read the file using the readlines() method and to save the sequence to a string named DNAsequence.
NB: The parts to be completed are indicated with "...". The other parts should not be changed.
inFile = ...
DNAsequence = ''
for ... in ...:
if not(">" in Line):
if (len(Line) > 0):
DNAsequence = DNAsequence + Line
print(DNAsequence)
print(len(DNAsequence))
python python-3.x python-requests jupyter-notebook
add a comment |
The folder with this project contains a plain text file with a DNA sequence in fasta format ('MYH7.fasta').
Complete the cell below to open and read the file using the readlines() method and to save the sequence to a string named DNAsequence.
NB: The parts to be completed are indicated with "...". The other parts should not be changed.
inFile = ...
DNAsequence = ''
for ... in ...:
if not(">" in Line):
if (len(Line) > 0):
DNAsequence = DNAsequence + Line
print(DNAsequence)
print(len(DNAsequence))
python python-3.x python-requests jupyter-notebook
Try to improve your questions with a code that can be executed by others. Minimal, Complete, and Verifiable example
– Daniel GL
Nov 22 '18 at 12:21
2
@DanielGL: but this is not a question. It is an assignment.
– usr2564301
Nov 22 '18 at 12:22
add a comment |
The folder with this project contains a plain text file with a DNA sequence in fasta format ('MYH7.fasta').
Complete the cell below to open and read the file using the readlines() method and to save the sequence to a string named DNAsequence.
NB: The parts to be completed are indicated with "...". The other parts should not be changed.
inFile = ...
DNAsequence = ''
for ... in ...:
if not(">" in Line):
if (len(Line) > 0):
DNAsequence = DNAsequence + Line
print(DNAsequence)
print(len(DNAsequence))
python python-3.x python-requests jupyter-notebook
The folder with this project contains a plain text file with a DNA sequence in fasta format ('MYH7.fasta').
Complete the cell below to open and read the file using the readlines() method and to save the sequence to a string named DNAsequence.
NB: The parts to be completed are indicated with "...". The other parts should not be changed.
inFile = ...
DNAsequence = ''
for ... in ...:
if not(">" in Line):
if (len(Line) > 0):
DNAsequence = DNAsequence + Line
print(DNAsequence)
print(len(DNAsequence))
python python-3.x python-requests jupyter-notebook
python python-3.x python-requests jupyter-notebook
edited Nov 22 '18 at 12:26
Rarblack
2,7163925
2,7163925
asked Nov 22 '18 at 12:13
C.Zennaro
11
11
Try to improve your questions with a code that can be executed by others. Minimal, Complete, and Verifiable example
– Daniel GL
Nov 22 '18 at 12:21
2
@DanielGL: but this is not a question. It is an assignment.
– usr2564301
Nov 22 '18 at 12:22
add a comment |
Try to improve your questions with a code that can be executed by others. Minimal, Complete, and Verifiable example
– Daniel GL
Nov 22 '18 at 12:21
2
@DanielGL: but this is not a question. It is an assignment.
– usr2564301
Nov 22 '18 at 12:22
Try to improve your questions with a code that can be executed by others. Minimal, Complete, and Verifiable example
– Daniel GL
Nov 22 '18 at 12:21
Try to improve your questions with a code that can be executed by others. Minimal, Complete, and Verifiable example
– Daniel GL
Nov 22 '18 at 12:21
2
2
@DanielGL: but this is not a question. It is an assignment.
– usr2564301
Nov 22 '18 at 12:22
@DanielGL: but this is not a question. It is an assignment.
– usr2564301
Nov 22 '18 at 12:22
add a comment |
1 Answer
1
active
oldest
votes
I suspect the answer they are looking for is
inFile = open("MYH7.fasta", "r").readlines()
In Perl concatenating code is standard (example below). I'm not sure here because inFile.readlines() should construct an array based on carriage returns and the invariable code in your question doen't allow its functionality to be used. The following code answers your question leaving the file handle open and omits readlines().
#!/usr/local/bin/python3
inFile = open("MYH7.fasta", "r")
DNAsequence = ''
for Line in inFile:
if not(">" in Line):
if (len(Line) > 0):
DNAsequence = DNAsequence + Line
print(DNAsequence)
print(len(DNAsequence))
The Perl version shows how several commands can be concatenated in a single line.
#!/usr/bin/perl
my $DNAsequence;
open (IN, "<MYH7.fasta");
while (my $line = <IN>){
chomp $line;
next if $line =~ m/>/;
$line =~ m/[ACGT]{10}/i ? $DNAsequence .= $line : next;
}
close IN;
print $DNAsequence, "n", length($DNAsequence) . " and Python s**ksn";
The MYH7.fasta input file will be of format,
>example_sequence
ACGCGTAGACGTATAG
I think there is a bug in your code because if carriage returns are present within the sequence they will carry through into the variable DNAsequence. In Perl these are removed using "chomp" or can by explicitly removed with $_ =~ s/n// (or in this eg $line =~ s/n//;). The presence of "n" could complicate subsequent analysis.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430781%2fopening-python-file-with-readlines-method%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I suspect the answer they are looking for is
inFile = open("MYH7.fasta", "r").readlines()
In Perl concatenating code is standard (example below). I'm not sure here because inFile.readlines() should construct an array based on carriage returns and the invariable code in your question doen't allow its functionality to be used. The following code answers your question leaving the file handle open and omits readlines().
#!/usr/local/bin/python3
inFile = open("MYH7.fasta", "r")
DNAsequence = ''
for Line in inFile:
if not(">" in Line):
if (len(Line) > 0):
DNAsequence = DNAsequence + Line
print(DNAsequence)
print(len(DNAsequence))
The Perl version shows how several commands can be concatenated in a single line.
#!/usr/bin/perl
my $DNAsequence;
open (IN, "<MYH7.fasta");
while (my $line = <IN>){
chomp $line;
next if $line =~ m/>/;
$line =~ m/[ACGT]{10}/i ? $DNAsequence .= $line : next;
}
close IN;
print $DNAsequence, "n", length($DNAsequence) . " and Python s**ksn";
The MYH7.fasta input file will be of format,
>example_sequence
ACGCGTAGACGTATAG
I think there is a bug in your code because if carriage returns are present within the sequence they will carry through into the variable DNAsequence. In Perl these are removed using "chomp" or can by explicitly removed with $_ =~ s/n// (or in this eg $line =~ s/n//;). The presence of "n" could complicate subsequent analysis.
add a comment |
I suspect the answer they are looking for is
inFile = open("MYH7.fasta", "r").readlines()
In Perl concatenating code is standard (example below). I'm not sure here because inFile.readlines() should construct an array based on carriage returns and the invariable code in your question doen't allow its functionality to be used. The following code answers your question leaving the file handle open and omits readlines().
#!/usr/local/bin/python3
inFile = open("MYH7.fasta", "r")
DNAsequence = ''
for Line in inFile:
if not(">" in Line):
if (len(Line) > 0):
DNAsequence = DNAsequence + Line
print(DNAsequence)
print(len(DNAsequence))
The Perl version shows how several commands can be concatenated in a single line.
#!/usr/bin/perl
my $DNAsequence;
open (IN, "<MYH7.fasta");
while (my $line = <IN>){
chomp $line;
next if $line =~ m/>/;
$line =~ m/[ACGT]{10}/i ? $DNAsequence .= $line : next;
}
close IN;
print $DNAsequence, "n", length($DNAsequence) . " and Python s**ksn";
The MYH7.fasta input file will be of format,
>example_sequence
ACGCGTAGACGTATAG
I think there is a bug in your code because if carriage returns are present within the sequence they will carry through into the variable DNAsequence. In Perl these are removed using "chomp" or can by explicitly removed with $_ =~ s/n// (or in this eg $line =~ s/n//;). The presence of "n" could complicate subsequent analysis.
add a comment |
I suspect the answer they are looking for is
inFile = open("MYH7.fasta", "r").readlines()
In Perl concatenating code is standard (example below). I'm not sure here because inFile.readlines() should construct an array based on carriage returns and the invariable code in your question doen't allow its functionality to be used. The following code answers your question leaving the file handle open and omits readlines().
#!/usr/local/bin/python3
inFile = open("MYH7.fasta", "r")
DNAsequence = ''
for Line in inFile:
if not(">" in Line):
if (len(Line) > 0):
DNAsequence = DNAsequence + Line
print(DNAsequence)
print(len(DNAsequence))
The Perl version shows how several commands can be concatenated in a single line.
#!/usr/bin/perl
my $DNAsequence;
open (IN, "<MYH7.fasta");
while (my $line = <IN>){
chomp $line;
next if $line =~ m/>/;
$line =~ m/[ACGT]{10}/i ? $DNAsequence .= $line : next;
}
close IN;
print $DNAsequence, "n", length($DNAsequence) . " and Python s**ksn";
The MYH7.fasta input file will be of format,
>example_sequence
ACGCGTAGACGTATAG
I think there is a bug in your code because if carriage returns are present within the sequence they will carry through into the variable DNAsequence. In Perl these are removed using "chomp" or can by explicitly removed with $_ =~ s/n// (or in this eg $line =~ s/n//;). The presence of "n" could complicate subsequent analysis.
I suspect the answer they are looking for is
inFile = open("MYH7.fasta", "r").readlines()
In Perl concatenating code is standard (example below). I'm not sure here because inFile.readlines() should construct an array based on carriage returns and the invariable code in your question doen't allow its functionality to be used. The following code answers your question leaving the file handle open and omits readlines().
#!/usr/local/bin/python3
inFile = open("MYH7.fasta", "r")
DNAsequence = ''
for Line in inFile:
if not(">" in Line):
if (len(Line) > 0):
DNAsequence = DNAsequence + Line
print(DNAsequence)
print(len(DNAsequence))
The Perl version shows how several commands can be concatenated in a single line.
#!/usr/bin/perl
my $DNAsequence;
open (IN, "<MYH7.fasta");
while (my $line = <IN>){
chomp $line;
next if $line =~ m/>/;
$line =~ m/[ACGT]{10}/i ? $DNAsequence .= $line : next;
}
close IN;
print $DNAsequence, "n", length($DNAsequence) . " and Python s**ksn";
The MYH7.fasta input file will be of format,
>example_sequence
ACGCGTAGACGTATAG
I think there is a bug in your code because if carriage returns are present within the sequence they will carry through into the variable DNAsequence. In Perl these are removed using "chomp" or can by explicitly removed with $_ =~ s/n// (or in this eg $line =~ s/n//;). The presence of "n" could complicate subsequent analysis.
edited Nov 23 '18 at 1:08
answered Nov 22 '18 at 22:50
Michael G.
2241116
2241116
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430781%2fopening-python-file-with-readlines-method%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try to improve your questions with a code that can be executed by others. Minimal, Complete, and Verifiable example
– Daniel GL
Nov 22 '18 at 12:21
2
@DanielGL: but this is not a question. It is an assignment.
– usr2564301
Nov 22 '18 at 12:22